tech-pkg archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: pkgsrc RC scripts



On Mon, 5 Oct 2009, Steven Drake wrote:

> On Sat, 3 Oct 2009, Joerg Sonnenberger wrote:
> 
> > (1) Install pkgsrc RC scripts by default into /etc/rc.pkg.d, not
> > /etc/rc.d and adjust the default value for rc_directories accordingly.
> > This keeps the logical separation between base and pkgsrc RC scripts
> > and still allows /usr (or /usr/pkg) to be on a separate filesystem.
> 
> Sounds like your talking about changeing the default value 
> of RCD_SCRIPTS_DIR. 
> 
> Personaly I would like config variables that are used by the 
> +INSTALL +DEINSTALL script set in pkg_install.conf and passed to the scripts 
> when thay get run. I know this would mean writing extra code in pkg_install 
> but it would mean that the +INSTALL +DEINSTALL behaviour is defined when 
> a binary package is installed not built.  
> 

So heres the code. The first patch to pkg_install passes anything that 
looks like a variable in pkg_install.conf to the environment of any 
sub processes.  

I've noted that some of the script templates in pkgsrc/mk/pkginstall are 
already setup to use varialbles passed to them, i.e.:
PKG_CREATE_USERGROUP, PKG_CONFIG, PKG_CONFIG_PERMS, PKG_RCD_SCRIPTS,
PKG_UPDATE_FONTS_DB, FONTS_VERBOSE, INFO_FILES_VERBOSE, PKG_REGISTER_SHELLS.

The second patch to files in pkgsrc/mk/ adds RCD_SCRIPTS_DIR and RC_SUBR_DIR to
the variables the +FILES script uses as well as code to modify the rcd scripts
when they are installed to RCD_SCRIPTS_DIR.

The RC_SUBR_DIR variable is brand new and gives the location of the 
rc.subr and rc.conf files.

-- 
Steven
I'm such a prick!  --- The Bastard Operator from Hell
--- mk/pkginstall/bsd.pkginstall.mk     2008/03/04 06:51:41     1.1.1.1
+++ mk/pkginstall/bsd.pkginstall.mk     2009/10/13 10:15:21
@@ -952,10 +952,13 @@ PKG_CONFIG_PERMS?=        NO
 PKG_RCD_SCRIPTS?=      NO
 PKG_REGISTER_SHELLS?=  YES
 PKG_UPDATE_FONTS_DB?=  YES
+RC_SUBR_DIR?=          /etc
 FILES_SUBST+=          PKG_CREATE_USERGROUP=${PKG_CREATE_USERGROUP:Q}
 FILES_SUBST+=          PKG_CONFIG=${PKG_CONFIG:Q}
 FILES_SUBST+=          PKG_CONFIG_PERMS=${PKG_CONFIG_PERMS:Q}
 FILES_SUBST+=          PKG_RCD_SCRIPTS=${PKG_RCD_SCRIPTS:Q}
+FILES_SUBST+=          RCD_SCRIPTS_DIR=${RCD_SCRIPTS_DIR:Q}
+FILES_SUBST+=          RC_SUBR_DIR=${RC_SUBR_DIR:Q}
 FILES_SUBST+=          PKG_REGISTER_SHELLS=${PKG_REGISTER_SHELLS:Q}
 FILES_SUBST+=          PKG_UPDATE_FONTS_DB=${PKG_UPDATE_FONTS_DB:Q}
 
@@ -1024,6 +1027,9 @@ FILES_SUBST+=             USERADD=${USERADD:Q}
 FILES_SUBST+=          XARGS=${XARGS:Q}
 
 FILES_SUBST_SED=       ${FILES_SUBST:S/=/@!/:S/$/!g/:S/^/ -e s!@/}
+FILES_SUBST_SED+=     -e s!/etc/rc\.d!${RCD_SCRIPTS_DIR:Q}!
+FILES_SUBST_SED+=     -e s!/etc/rc\.subr!${RC_SUBR_DIR:Q}/rc.subr!
+FILES_SUBST_SED+=     -e s!/etc/rc\.conf!${RC_SUBR_DIR:Q}/rc.conf!
 
 PKG_REFCOUNT_DBDIR?=   ${PKG_DBDIR}.refcount
 
--- mk/pkginstall/files 2008/09/25 14:01:46     1.1.1.1
+++ mk/pkginstall/files 2009/10/13 10:14:53
@@ -98,6 +98,11 @@ case "${PKG_RCD_SCRIPTS:-@PKG_RCD_SCRIPT
        ;;
 esac
 
+: ${RCD_SCRIPTS_DIR:=@RCD_SCRIPTS_DIR@}
+: ${RC_SUBR_DIR:=@RC_SUBR_DIR@}
+RC_SCRIPT_SUBST=" s!@RCD_SCRIPTS_DIR@!${RCD_SCRIPTS_DIR}!g; 
s!@RC_SUBR_DIR@/rc\.subr!${RC_SUBR_DIR}/rc\.subr!g; 
s!@RC_SUBR_DIR@/rc\.conf!${RC_SUBR_DIR}/rc\.conf!g;"
+
+
 case $ACTION in
 VIEW-REMOVE)
        DEPOTDIR="$2"
@@ -123,6 +128,11 @@ ADD)
                "")     continue ;;
                [!/]*)  file="${PKG_PREFIX}/$file" ;;
                esac
+               case "$f_flags" in
+               *r*)
+                       file="${RCD_SCRIPTS_DIR}/${file##*/}"
+                       ;;
+               esac
                case $f_flags in
                *c*)    ;;
                *)      continue ;;
@@ -160,8 +170,16 @@ ADD)
                                if ${TEST} -f "$file"; then
                                        ${ECHO} "${PKGNAME}: $file already 
exists"
                                elif ${TEST} -f "$f_eg" -o -c "$f_eg"; then
-                                       ${ECHO} "${PKGNAME}: copying $f_eg to 
$file"
-                                       ${CP} $f_eg $file
+                                       case "$f_flags" in
+                                       *r*)
+                                               ${ECHO} "${PKGNAME}: Modifing 
$f_eg and copying to $file"
+                                               ${SED} -e "${RC_SCRIPT_SUBST}" 
$f_eg >$file
+                                               ;;
+                                       *)
+                                               ${ECHO} "${PKGNAME}: copying 
$f_eg to $file"
+                                               ${CP} $f_eg $file
+                                               ;;
+                                       esac
                                        case $f_user in
                                        "")     ;;
                                        *)      ${CHOWN} $f_user $file ;;
@@ -188,6 +206,11 @@ REMOVE)
                "")     continue ;;
                [!/]*)  file="${PKG_PREFIX}/$file" ;;
                esac
+               case "$f_flags" in
+               *r*)
+                       file="${RCD_SCRIPTS_DIR}/${file##*/}"
+                       ;;
+               esac
                case $f_flags in
                *c*)    ;;
                *)      continue ;;
@@ -209,13 +232,24 @@ REMOVE)
                        "")
                                if ${TEST} -f "$preexist"; then
                                        :
-                               elif ${TEST} -f "$file" -a \( -f "$f_eg" -o -c 
"$f_eg" \) && \
-                                    ${CMP} -s "$file" "$f_eg"; then
-                                       case 
"$f_flags:$_PKG_CONFIG:$_PKG_RCD_SCRIPTS" in
-                                       
*f*:*:*|[!r]:yes:*|[!r][!r]:yes:*|[!r][!r][!r]:yes:*|*r*:yes:yes)
-                                               ${RM} -f "$file"
+                               elif ${TEST} -f "$file" -a \( -f "$f_eg" -o -c 
"$f_eg" \); then
+                                       case "$f_flags" in
+                                       *r*)
+                                               ${SED} -e ${RC_SCRIPT_SUBST} 
"$f_eg" | ${CMP} -s "-" "$f_eg"
+                                               ret=$?
+                                               ;;
+                                       *)
+                                               ${CMP} -s "$file" "$f_eg" 
+                                               ret=$?
                                                ;;
                                        esac
+                                       if ${TEST} "$ret" = "0" ;then
+                                               case 
"$f_flags:$_PKG_CONFIG:$_PKG_RCD_SCRIPTS" in
+                                               
*f*:*:*|[!r]:yes:*|[!r][!r]:yes:*|[!r][!r][!r]:yes:*|*r*:yes:yes)
+                                                       ${RM} -f "$file"
+                                                       ;;
+                                               esac
+                                       fi
                                fi
                                ${RM} -f $perms $preexist $token $token.tmp.*
                                ${RMDIR} -p $shadow_dir 2>/dev/null || ${TRUE}
--- pkgtools/pkg_install/files/lib/parse-config.c.orig  2009-10-14 
00:45:23.000000000 +1300
+++ pkgtools/pkg_install/files/lib/parse-config.c
@@ -107,7 +107,7 @@ parse_pkg_install_conf(void)
 {
        struct config_variable *var;
        FILE *fp;
-       char *line, *value;
+       char *line, *value, *buf;
        size_t len, var_len, i;
 
        fp = fopen(config_file, "r");
@@ -119,24 +119,49 @@ parse_pkg_install_conf(void)
 
        while ((line = fgetln(fp, &len)) != (char *) NULL) {
                if (line[len - 1] == '\n')
-                       --len;
+                       line[--len] = '\0';
+               else {
+                       if ((buf = (char *)malloc(len + 1)) == NULL)
+                               err(1, NULL);
+                       memcpy(buf, line, len);
+                       buf[len] = '\0';
+                       line = buf;
+               }
+
+               value=strchr(line, '=');
+               if (value == NULL || *value != '=')
+                       goto freebuf;
+
+               *value='\0';
+               value++;
+
+#define ENV_ACCEPT "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
+               if (strspn(line, ENV_ACCEPT) != strlen(line))
+                       goto freebuf;
+
+               /* handle "VAR= value" lines! */
+               if (*value == ' ')
+                       value++;
+
+               setenv(line, value, 1);
+
                for (i = 0; (var = &config_variables[i])->name != NULL; ++i) {
-                       var_len = strlen(var->name);
-                       if (strncmp(var->name, line, var_len) != 0)
-                               continue;
-                       if (line[var_len] != '=')
+                       if (strcmp(var->name, line) != 0)
                                continue;
-                       line += var_len + 1;
-                       len -= var_len + 1;
                        if (config_tmp_variables[i])
-                               value = xasprintf("%s\n%.*s",
-                                   config_tmp_variables[i], (int)len, line);
+                               value = xasprintf("%s\n%s",
+                                   config_tmp_variables[i], value);
                        else
-                               value = xasprintf("%.*s", (int)len, line);
+                               value = xasprintf("%s", value);
                        free(config_tmp_variables[i]);
                        config_tmp_variables[i] = value;
                        break;
                }
+freebuf:
+               if (buf != NULL) {
+                       free(buf);
+                       buf = NULL;
+               }
        }
 
        for (i = 0; (var = &config_variables[i])->name != NULL; ++i) {


Home | Main Index | Thread Index | Old Index