Hello,

I've finally got it to work on FreeBSD after some changes. I've attached some patches and the startup script (it contains some substitution variables) so you can look at them.

It's not yet in the official ports tree only because I'm testing if it mentions all required dependencies, doesn't leave files after uninstall, etc. But it'll be there by tomorrow probably.

BTW this is for a SoC project about classifying ports by their license (we have more than 20000 currently), avoiding some problems with GPLv3, and restricted redistribution of some ports. The FOSSology part would be to assist in identifying licenses the most automated way possible. I'll ask about this in another e-mail, this was just to mention it.

Here is a list of the changes I made:

1. stat64, fopen64, etc

Changed all of the "(stat|fopen|mmap|lseek|off)64" to "\1" (remove the "64" suffix). In FreeBSD they aren't needed, and off_t is always defined as a 64-bit integer.

I've seen some configure scripts that check for off_t but as you don't use one, an #ifdef __FreeBSD__ can be added to some .h file, that defines aliases in that case (like #define fstat64 fstat).

2. PostgreSQL

In FreeBSD (don't know why) the user is not "postgres", but "pgsql". The problem is that the database is still called "postgres", so I had to do the following:

* Add "export PGDATABASE=postgres" to db/dbcreate.in.
* Change all of the "su postgres" occurrences to "su pgsql" in db/dbcreate.in.

3. GNU userland / standards / paths

In cli/fo_notify.php "hostname --fqdn" is called, but that option isn't supported in FreeBSD (it defaults to include domain information anyways).

In scheduler/selftest.c 'sed' is called with the pattern 's/.*agent=\(\w\).*/\1/', but "\w" (IIRC it's a Perl regex) isn't supported by our 'sed' so I used the following instead: 's/.*agent=\([^[:blank:]]*\).*/\1/'. This one was particularly difficult to track.

I had to manually create /usr/local/lib/fossology/agents and /usr/local/share/fossology/php or otherwise the installation failed.

Added "echo $REPODIR > RepPath.conf" as it contains "/srv/fossology/repository" by default, even after configuring REPODIR in Makefile.conf.

In fo-postinstall.in, getopt is used with "--long" but FreeBSD doesn't support this so I delegated options parsing fully to the while-case block (checking for $# > 0 and using shift).

In FreeBSD, user/group management is done through the 'pw' command. The syntax is different as you can see in the patch. Our WWW user is just "www" (not "www-data" or others), and generally use /usr/sbin/nologin instead of /bin/false.

4. Scheduler

In scheduler/mkschedconf.c, a single "%" is used instead of a "%%" in printf() format strings. It seems Linux just ignores the nonexistent placeholder "%{" and prints just that, but it's not standard and Linux manual pages also say to use "%%" to output a literal "%" character. In FreeBSD (and probably other OSes), it's required to use "%%". Please note that it's only required in the 2 relevant snprintf() calls (in other normal strings it's fine).

Both the scheduler (scheduler.c) and the watchdog (fo_watchdog.c) try to create a file with shm_open in the current directory, and they haven't permission. Specially after calling daemon() with 0 as the first argument (I changed it to 1 so it doesn't chdir() to "/", and ran it from "/var/tmp" where it can write). I didn't look much into this, so maybe (probably) I'm missing something, please clarify in that case.

5. Some requests (not so important)

For the startup script it would be better if both the scheduler and watchdog create files with their PID as most daemons do (like /var/run/fossology-scheduler.pid and /var/run/fossology-watchdog.pid). This would be convenient in any OS, because before starting/stopping the service the script could check its state. Other daemons include their own script (independent of the rc.d/init.d system) which starts/stops/gives status about the programs (like apachectl).

Our ports/package practice (and maybe others are similar) is to install initial configuration files as .conf.sample or under a defaults subdirectory, and then copy them over to their correct places (if don't already exist) at post-install time. That helps because when the port is removed the configuration files are compared to the defaults, and if there are no changes they are removed.

Thanks,
Ale
#!/bin/sh
#
# $FreeBSD$
#
# REQUIRE: DAEMON postgresql
# PROVIDE: fossology
#

. %%RC_SUBR%%

name="fossology"
rcvar=`set_rcvar`
load_rc_config "$name"
: ${fossology_enable="NO"}

SCHEDULER="%%PREFIX%%/lib/fossology/fossology-scheduler"
WATCHDOG="%%PREFIX%%/lib/fossology/fo_watchdog"

start_cmd="fossology_start"
stop_cmd="fossology_stop"

# FIXME: status command not implemented, but only one instance
#        is allowed so there aren't problems for now.

fossology_start()
{
        echo "Starting fossology."
# XXX: Enter /var/tmp because uses shm_open in current directory,
#      otherwise patch scheduler.c
        cd /var/tmp && ${SCHEDULER} -d -R
        cd /var/tmp && ${WATCHDOG}
}

fossology_stop()
{
        echo "Stopping fossology."
        ${WATCHDOG} -k
        ${SCHEDULER} -k
}

run_rc_command "$1"
--- common/fo-postinstall.in.orig       2009-07-13 21:51:17.000000000 +0000
+++ common/fo-postinstall.in    2009-07-15 00:37:37.000000000 +0000
@@ -8,22 +8,15 @@
 # right thing, regardless of the success of previous runs.
 
 ## Options parsing and setup
-# parse options
-OPTS=`getopt -o adwseoh --long 
agent,database,web,web-only,scheduler,scheduler-only,everything,overwrite,help 
-n 'fo-postinstall' -- "$@"`
 
-if [ $? != 0 ]; then
-   echo "ERROR: Bad option specified."
-   OPTS="--help"
-fi
-
-eval set -- "$OPTS"
+# FIXME: joint options do not work (i.e. "-as" instead of "-a -s")
 
 # if no options or just -o then do everything
-if [ "$OPTS" = " --" -o "$OPTS" = " -o --" ]; then
+if [ $# -eq 0 -o "$1" = "-o" ]; then
    EVERYTHING=1
 fi
 
-while true; do
+while [ $# -gt 0 ]; do
    case "$1" in
       -a|--agent) AGENT=1; shift;;
       -d|--database) DATABASE=1; shift;;
@@ -105,15 +98,10 @@
    echo "*** Creating user and group ***"
 
    # check for group
-   if grep -q "^{$PROJECTGROUP}:" /etc/group; then
+   if pw groupshow {$PROJECTGROUP} 2>/dev/null 1>&2; then
       echo "NOTE: group '{$PROJECTGROUP}' already exists, good."
    else
-      # use addgroup if it exists since it supports --system
-      if [ -f /usr/sbin/addgroup -a ! -L /usr/sbin/addgroup ]; then
-         addgroup --system {$PROJECTGROUP}
-      else
-         groupadd {$PROJECTGROUP}
-      fi
+      pw groupadd {$PROJECTGROUP} -g 901
       if [ "$?" != "0" ] ; then
          echo "ERROR: Unable to create group '{$PROJECTGROUP}'"
          exit 1
@@ -123,25 +111,18 @@
    fi
 
    # check for user
-   if grep -q "^{$PROJECTUSER}:" /etc/passwd; then
+   if pw usershow {$PROJECTUSER} 2>/dev/null 1>&2; then
       echo "NOTE: user '{$PROJECTUSER}' already exists, good."
       USERSHELL=`grep "^{$PROJECTUSER}:" /etc/passwd |cut -d: -f 7`
-      if [ "$USERSHELL" = "/bin/false" ]; then
+      if [ "$USERSHELL" = "/usr/sbin/nologin" ]; then
          echo "ERROR: {$PROJECTUSER} shell must be a real shell"
          exit 1
       fi
    else
       # ensure that the full parent path of the HOME exists first
       mkdir -p $\{REPO%/*/*\}
-      # use adduser if it exists since it supports --system, but
-      # not if it's a symlink (probably to /usr/sbin/useradd)
-      if [ -f /usr/sbin/adduser -a ! -L /usr/sbin/adduser ]; then
-         adduser --gecos "{$PROJECT}" --ingroup {$PROJECTGROUP} --system \
-           --shell /bin/bash --home "$\{REPO%/*\}" {$PROJECTUSER}
-      else
-         useradd -c "{$PROJECT}" -g {$PROJECTGROUP} -m \
-           -s /bin/bash -d "$\{REPO%/*\}" {$PROJECTUSER}
-      fi
+      pw useradd {$PROJECTUSER} -u 901 -g {$PROJECTGROUP} -h - \
+          -s "/bin/bash" -d "$\{REPO%/*\}" -c "FOSSology user"
       if [ "$?" != "0" ] ; then
          echo "ERROR: Unable to create user '{$PROJECTUSER}'"
          exit 1
@@ -284,19 +265,12 @@
    echo "*** Setting up the web interface ***"
 
    # See if web server user exists, if so add to the group.
-   # check for www-data (Debian, etc)
-   grep -q "^www-data:" /etc/passwd
-   if [ $? == 0 ] ; then
-     echo "NOTE: Adding user www-data to group {$PROJECTGROUP}"
-     # this is smart enough to not add multiple times so it's ok to repeat
-     usermod -G {$PROJECTGROUP} -a www-data
-   fi
-   # check for apache (RHEL/CentOS, etc)
-   grep -q "^apache:" /etc/passwd
+   # check for www (FreeBSD)
+   grep -q "^www:" /etc/passwd
    if [ $? == 0 ] ; then
-     echo "NOTE: Adding user apache to group {$PROJECTGROUP}"
+     echo "NOTE: Adding user www to group {$PROJECTGROUP}"
      # this is smart enough to not add multiple times so it's ok to repeat
-     usermod -G {$PROJECTGROUP} -a apache
+     pw groupmod {$PROJECTGROUP} -m www
    fi
 
 fi # end of WEBONLY
--- scheduler/mkschedconf.c.orig        2009-07-09 23:04:45.000000000 +0000
+++ scheduler/mkschedconf.c     2009-07-14 01:45:35.000000000 +0000
@@ -180,14 +180,14 @@
   /** fosscp **/
   fprintf(Fout,"agent=fosscp_agent %s| ",CmdHost);
   memset(Cmd,'\0',sizeof(Cmd));
-  snprintf(Cmd,sizeof(Cmd)-1,Rcmd,"%s/engine-shell fosscp_agent '%s/cp2foss 
%{*}'");
+  snprintf(Cmd,sizeof(Cmd)-1,Rcmd,"%s/engine-shell fosscp_agent '%s/cp2foss 
%%{*}'");
   fprintf(Fout,Cmd,AGENTDIR,BINDIR);
   fprintf(Fout,"\n");
 
  /** notify **/
   fprintf(Fout,"agent=fo_notify %s| ",CmdHost);
   memset(Cmd,'\0',sizeof(Cmd));
-  snprintf(Cmd,sizeof(Cmd)-1,Rcmd,"%s/engine-shell fo_notify '%s/fo_notify 
%{*}'");
+  snprintf(Cmd,sizeof(Cmd)-1,Rcmd,"%s/engine-shell fo_notify '%s/fo_notify 
%%{*}'");
   fprintf(Fout,Cmd,AGENTDIR,BINDIR);
   fprintf(Fout,"\n");
 
--- ./scheduler/selftest.c.orig 2008-11-24 18:15:44.000000000 +0000
+++ ./scheduler/selftest.c      2009-07-10 01:47:07.000000000 +0000
@@ -42,7 +42,7 @@
 {
   FILE *Fin, *FData, *FTest;
   char SelfTest[] = "echo 'test' | " AGENTDIR "/selftest -g -s"; /* -g for 
generate test data */
-  char MkConfig[] = LIBEXECDIR "/mkschedconf -L 2>&1 | grep agent | sed 
's/.*agent=\\(\\w*\\).*/\\1/' | sort -u"; /* get list of agents */
+  char MkConfig[] = LIBEXECDIR "/mkschedconf -L 2>&1 | grep agent | sed 
's/.*agent=\\([^[:blank:]]*\\).*/\\1/' | sort -u"; /* get list of agents */
   int c,i;
   int Thread;
   int rc=0;
_______________________________________________
fossology mailing list
[email protected]
http://fossology.org/mailman/listinfo/fossology

Reply via email to