Opened 2 years ago

Closed 2 years ago

#64142 closed submission (fixed)

New Port - ntpstat

Reported by: RobK88 Owned by: RobK88
Priority: Normal Milestone:
Component: ports Version: 2.7.1
Keywords: Cc:
Port: ntpstat

Description

Attached please find a port for ntpstat (along with a source code patch file to make it run properly on a Mac and a Makefile patch file to make Macports happy).

ntpstat shows the network time protocol (ntp) status.

ntpstat will report the synchronisation state of the NTP daemon running on the local machine. If the local system is found to be synchronised to a reference time source, ntpstat will report the approximate time accuracy.

Attachments (3)

ntpstat.zip (10.3 KB) - added by RobK88 2 years ago.
Zip file containing portfile and patch files
Portfile (1.8 KB) - added by RobK88 2 years ago.
Updated portfile -- Added "depends_run port:ntp"
ntpstat-Githib.zip (3.1 KB) - added by RobK88 2 years ago.
ZIP containg Portfile and Patch Files. Portfile uses GitHub PortGroup.

Download all attachments as: .zip

Change History (17)

Changed 2 years ago by RobK88

Attachment: ntpstat.zip added

Zip file containing portfile and patch files

Changed 2 years ago by RobK88

Attachment: Portfile added

Updated portfile -- Added "depends_run port:ntp"

comment:1 Changed 2 years ago by ryandesign (Ryan Carsten Schmidt)

The version you've selected in the file... "20010622"... are you basing that on the date at the top of the manpage and the comment at the top of the source file?

The project was committed to GitHub in 2013, by someone other than the author listed in the source file, and the repository has only one commit of the source and one commit of a binary that we don't want, which makes me think this is not the original or official source of this software.

It looks like this is the last archived copy of the official homepage: https://web.archive.org/web/20121207230716/http://people.redhat.com/rkeech/#ntpstat

That page links to a source code archive called ntpstat-0.2-1.src.rpm so I think that means we should set version to "0.2".

We may want to try to contact the developer at the listed email address or do additional internet searches to try to discover if there is a new home for this software from which we could get it.

If we were to download the source code from GitHub, then we'd want to use the github 1.0 portgroup to simplify the Portfile. However, since that's not the original source, I'd be inclined to use a more official source if available. If no new home is available we could try to use the above source rpm but I'm not sure if MacPorts knows how to decompress an rpm file.

And if we were to download from GitHub, then it's not permitted to download the head of "master" or another branch of a repository in a Portfile. Instead, you must select a specific tag or commit, so that builds are reproducible. For example, we might select the initial commit, since that will be a smaller archive since it won't contain the binary we don't need.

In your patchfile which comments out the line #include <error.h>, it would be simpler and more efficient for the patchfile to remove that line.

I wouldn't bother including the entire GPL license file in the files directory. It is several times the size of the Portfile and patches. If every port did that, it would be an incredible waste of space. The software already includes a COPYING file which, while it doesn't have the entire license text, does say what license it is, and installing that should be sufficient.

I am assuming in all of this that there is some value in adding this 20+-year-old program to MacPorts at this point that is not already met by one of our other ports.

comment:2 Changed 2 years ago by RobK88

Ryan, thanks for digging up the original site for ntpstat on the Internet Archive. The homepage I provided in the portfile for Macports is the same as Debian uses in its packaging file.

And yes, since I could not find a version anywhere, I used the date at the top of the source code file. Based on the original source code filename, I agree that version 0.2 would be more appropriate.

It looks like there has been one commit for the source and another for a Linux binary. I suspect that the source on githib is identical to the source on the Internet Archive. I will verify tomorrow.

As you suggest, I will remove the #include <error.h>. It really will not affect the compile at all since the source code being compiled will be identical after the preprocessor does its magic.

I will also remove the LICENSE file. I was not sure what the policy was for license files in Macports. Normally, when one distributes GPL-2 source, one also provides a copy of the GPL-2 license with the distribution or a link to the GPL-2 license on the web to be fully compliant with the GPL-2 license. I may patch COPYING and add a link to the GPL-2 license. That will not add much to the size of the file.

I will also update the port using github portGroup since I need to learn how to do that. (I doubt it will make a practical difference in the end since the source has not been updated since 2006 and from my personal experience over many years of use is still bug free).

For many years, I have always installed ntpstat on all my Linux PC's. I provides a simple summary of ntp. You could get the same info by running two commands ntpq -p and sntp apple.time.com and parsing the output. But ntpstat is simpler. (There are very few software programs for ntp). If you do not think there is any value in adding ntpstat to Macports at this time, that is fine. I have a working port for ntpstat on my local Macports repo that I can use. I was sharing the port in case others wanted to install ntpstat via Macports.

Last edited 2 years ago by RobK88 (previous) (diff)

comment:3 Changed 2 years ago by RobK88

P.S. I just discovered another program with the same name ntpstat. Unlike the original ntpstat which was written in C and did not rely on ntpq, the newer ntpstat is a shell script which prints the ntpd or chronyd synchronisation status, using the ntpq or chronyc program. See See https://github.com/mlichvar/ntpstat

It emulates the original ntpstat program written in C by G. Richard Keech, which implemented a subset of the mode 6 ntp control message protocol supported by ntpd. But please note that it has an additional dependency that the original ntpstat did not have. It requires gawk (at least on older Macs where awk is pretty limited. I had to patch the original script replacing awk with gawk everywhere to make the newer ntpstat work on my older Macs).

Another downside to the newer ntpstat program -- it is NOT fully POSIX shell (sh) compatible. It would have been better if the newer ntpstat was NOT scripted and used the NTP mode 6 control message protocol to communicate directly to ntpd, like the original ntpstat program did, instead of using bash and ntpq in "raw" mode . (see https://github.com/mlichvar/ntpstat/pull/4). But that is a lot more work and the ntp control message protocol is pretty obscure.

On the bright side, unlike the original ntpstat program, the newer ntpstat supports not only ntp but also chronyc. It is also still being developed.

Last edited 2 years ago by RobK88 (previous) (diff)

comment:4 in reply to:  3 Changed 2 years ago by ryandesign (Ryan Carsten Schmidt)

Replying to RobK88:

For many years, I have always installed ntpstat on all my Linux PC's. I provides a simple summary of ntp. You could get the same info by running two commands ntpq -p and sntp apple.time.com and parsing the output. But ntpstat is simpler. (There are very few software programs for ntp). If you do not think there is any value in adding ntpstat to Macports at this time,

No no, it's good, let's add it. Just making sure that the fact that it wasn't already in MacPorts wasn't the only reason you were contributing it. The fact that you actually use it and it serves a useful function for you makes it worth adding.

Replying to RobK88:

P.S. I just discovered another program with the same name ntpstat.

That presents a slight difficulty in deciding which of the two should be added to MacPorts as "ntpstat" and what the other one should be called in MacPorts. But, since you already propose a portfile for the original ntpstat here, and it claimed the name first, it seems reasonable to proceed with your original portfile and to tackle what the shell-based ntpstat might be called in MacPorts at a later time, should someone want to add it later.

comment:5 Changed 2 years ago by RobK88

@Ryan -- Sorry for the delay. I prefer the original ntpstat written in C since it runs as expected in all shells (unlike the newer ntpstat which is not fully POSIX shell (sh) compatible).

It looks the original author's site is now more (but can still be seen via the internet archive as you discovered). One can either obtain the source from Internet Archive, Debian or the Darkhelmet github site. (The Debian packaging file shows the Darkhelmet Github site as the homepage. See http://deb.debian.org/debian/pool/main/n/ntpstat/ntpstat_0.0.0.1-2.dsc).

As a result, I believe it is best that Macports download the source from the Darkhelmet Github site. The initial commit is identical to the the source found on the Internet Archive. So I propose we use the initial commit.

Attached please find an updated ZIP file containing the portfile and needed patch files.

The portfile has been updated to download the source from github. I also deleted the LICENSE.txt file. I also used version 0.2 as the version number which appears to be the right version number as you pointed out earlier.

Last edited 2 years ago by RobK88 (previous) (diff)

Changed 2 years ago by RobK88

Attachment: ntpstat-Githib.zip added

ZIP containg Portfile and Patch Files. Portfile uses GitHub PortGroup.

comment:6 Changed 2 years ago by reneeotten (Renee Otten)

if possible please just open a PR - that will automatically test building the port and will facilitate getting this port added

comment:8 Changed 2 years ago by RobK88

I did not realize that the committers to the Macports repo want any contributors to first install their new port or modified port using trace mode. (This requirement is not in the Macports Guide).

When I do that with my ntpstat port, I get:

bash-3.2$ sudo port uninstall ntpstat
Password:
--->  Deactivating ntpstat @0.2_0
--->  Cleaning ntpstat
--->  Uninstalling ntpstat @0.2_0
--->  Cleaning ntpstat
bash-3.2$ sudo port clean ntpstat
--->  Cleaning ntpstat
bash-3.2$ sudo port install -vst ntpstat
--->  Computing dependencies for ntpstat
--->  Fetching distfiles for ntpstat
--->  Verifying checksums for ntpstat
--->  Extracting ntpstat
--->  Applying patches to ntpstat
--->  Configuring ntpstat
--->  Building ntpstat
Warning: The following existing files were hidden from the build system by trace mode:
  /opt/local/bin/i686-apple-darwin11-llvm-gcc-4.2
  /usr/llvm-gcc-4.2/bin/i686-apple-darwin11-llvm-gcc-4.2
  /usr/llvm-gcc-4.2/bin/llvm-gcc-4.2
Error: Failed to build ntpstat: command execution failed
Error: See /opt/local/var/macports/logs/_Users_grinch_Macports_ports_sysutils_ntpstat/ntpstat/main.log for details.
Error: Follow https://guide.macports.org/#project.tickets if you believe there is a bug.
Error: Processing of port ntpstat failed

How do you fix this? Is this really an issue?

Last edited 2 years ago by RobK88 (previous) (diff)

comment:9 Changed 2 years ago by RobK88

I understand now that I need to setup the compiler and the compiler flags. The easiest solution is to add PortGroup Makefile 1.0 and remove use_configure no from the portfile.

Last edited 2 years ago by RobK88 (previous) (diff)

comment:10 Changed 2 years ago by RobK88

@Renee and Ryan -- I apologize for messing up my first Pull Request (PR). I am new to a DISTRIBUTED CVS like GitHib. In fact when I started to program in the 70s on mainframes using punch cards, CVS type systems did not even exist.

What confused me in the Macports Guide were the terms git and Github. In my view, the documentation should make it clear that the term git DOES NOT include a repo on github.com. (I am sure that experienced developers who use git and Github would not confuse the two. But that is not the case for git newbies). And unfortunately, the capabilities of GitHub.com is more limited than a local git repo (as I just discovered). e.g One cannot amend a commit on GitHub.com without amending the commit on a local git repo and pushing (or force pushing) the changes to GitHub.com.

For Macports Pull Requests, it looks like the following is the best workflow:

  1. If this has not been done before, fork the Macports GitHub repo (which will create an identical repo on one's personal GitHub website).
  1. Clone the Macports repo (or your personal forked GitHub repo) to a local git repo located on their own Mac.
  1. Using the local git repo, make a branch, makes changes to files in the branch (or add files to the branch), test the port, commit the changes to the local git repo, rebase if needed to reduce the number of commits etc.
  1. Push one's changes from the local git repo to one's personal GitHub.com repo.
  1. Make sure that your personal Githib.com repo is up to date by doing a "fetch upstream" if necessary.
  1. Make a Pull Request (PR) from the branch of one's personal GitHub repo to the Macports Github site.

(The Macports Guide states "Make a pull request from your branch in your own git repository to the appropriate MacPorts repository." I am sure that will work but doesn't it make more sense to make the Pull Request from the branch of one's personal GitHub repo to the Macports Github site?)

The Macports Guide does not mention using git commit --amend on the local git repo and a force push for future small changes but I agree that is a wise approach to minimize the number of commits that you need to deal with. I will get the hang of it for future contributions to Macports.

Last edited 2 years ago by RobK88 (previous) (diff)

comment:11 Changed 2 years ago by reneeotten (Renee Otten)

see: https://trac.macports.org/wiki/WorkingWithGit#commit

I've left a few more comments in the PR, if you agree with them and want to make the changes feel free to do so. I will take a look later tomorrow and fetch the PR and locally squash the commits and check whether it indeed builds/works as intended. If so, I'll push to your branch which will update the PR and if that all looks good we'll merge it.

Last edited 2 years ago by reneeotten (Renee Otten) (previous) (diff)

comment:12 Changed 2 years ago by RobK88

@Renee -- Many thanks for all your help. I see from the buildbot, that the C code for ntpstat is not building in 10.15 and macOS 11. The error shown is not very helpful. And I do not have a Mac running either 10.15 or 11 to debug on my end. If you have any insight that would be very helpful.

Many many thanks for the link to the wiki on using git. It was extremely helpful!

P.S. In my view, the wiki on git could be clearer in some sections.

  1. Under the section "Using a branch for development", I would add the following note:
Note:  If your upstream macports-ports repo is your personal fork of the official macports-port repo, you should first make sure
 your fork is up to date by clicking "Fetch Upstream" on the webpage for the fork on GitHib.com before running the commands above.
  1. Under the section "Checking out a working copy of the ports tree". I would change the note as follows (changes in BOLD):

Note: If you intend to submit a pull request on GitHub to get your changes included in MacPorts, you may want to create a fork of the repository first. To do that, first log into GitHub.com with your personal GitHub username and password, if you are not already logged in. Then, go to ​https://github.com/macports/macports-ports/ and click the fork button at the top right. (Now you will have a fork or clone of the macports-ports repo on your personal GitHib.com website). Then, run the command above, but use <yourGitHubusername>/macports-ports.git instead of macports/macports-ports.git. (Now you will have a local git repo of the forked macports-ports repo).

I may go ahead and edit the wiki accordingly with my suggested changes.

WorkFlow for Pull Requests (PR's)

The wiki has confirmed that the following is the best workflow for Pull Requests:

  1. If this has not been done before, fork the Macports GitHub repo (which will create an identical repo on one's personal GitHub website).
  1. Clone your personal forked GitHub repo to a local git repo located on their own Mac. (i.e. git clone https://github.com/<YourGitHubUsername>/macports-ports.git or git clone git@github.com:<YourGitHubUsername>/macports-ports.git where <YourGitHubUsername> is your personal GitHub username).
  1. Using the local git repo, make a branch, makes changes to files in the branch (or add files to the branch), test the port, add changes (and new files) to the git staging area or index, commit the changes to the local git repo.
  1. If additional commits are needed locally, please use "git commit --amend" which will amend the initial commit with the changes. The goal here is to submit ONLY one commit with each Pull Request (PR), if at all possible, to make life easier for the Macports' committers.
  1. Push one's changes from the local git repo to one's personal GitHub.com repo. (i.e. git push origin).
  1. Make sure that your personal Githib.com repo is up to date by doing a "fetch upstream" on the website, if necessary.
  1. Make a Pull Request (PR) from the branch of one's personal GitHub repo (that contains the new port or proposed changes) to the Macports Github site.
  1. If Step 5 fetched any new files or changed files, you will likely want these changes to be reflected in your local git repo as well. To do this, run git fetch origin or simply git fetch.

Alternatively, you can update your local repo directly from the official Macports repo. (see "Updating your Fork" on the wiki https://trac.macports.org/wiki/WorkingWithGit#upstream-fetch ).

  1. If the committers suggest changes and you agree to them, you will likely be asked to rebase your changes on top of the official Macports current master branch. The easiest way to do this is adding the official repository as a second remote to your working copy and pulling from it. Then rebase the changes. (see https://trac.macports.org/wiki/WorkingWithGit#upstream-fetch for details). Once all of that is done, do not forget to push the changes to your fork on your personal GitHub website. (i.e. git push origin). Once the push is complete, the associated Pull Request (PR) request will automatically be updated!
Last edited 2 years ago by RobK88 (previous) (diff)

comment:13 Changed 2 years ago by RobK88

Thanks Renee for all your help. I see you got the port to run in 10.15 and macOS 11. fantastic.

And thank you for cleaning up the commit history. I know I made a mess of that. It sure looks like it is ready for submission to the official macports tree.

P.S. As for the line CC = gcc in the Makefile. I was told on my first port submission (codegroup) that it does not make a difference if one uses CC = gcc or CC ?= gcc in the Makefile as far as Macports is concerned. Apparently, Macports can override the CC variable even when the CC variable is assigned using = or :=. This is not difficult. One just needs to pass the the new value for CC with the make command. e.g. make CC=gcc. See https://stackoverflow.com/questions/18007326/how-to-change-default-values-of-variables-like-cc-in-makefile

Last edited 2 years ago by RobK88 (previous) (diff)

comment:14 Changed 2 years ago by RobK88

Owner: set to RobK88
Resolution: fixed
Status: newclosed

In 10d23caebaa570f86399552732fa386dd69d6d8f/macports-ports (master):

ntpstat: new port, version 0.2

Closes: #64142

Note: See TracTickets for help on using tickets.