From 4418d408ab034c317c8cb66205d5fbf2606f0b03 Mon Sep 17 00:00:00 2001 From: emmett1 Date: Tue, 26 Jun 2018 17:56:26 +0800 Subject: [PATCH] add sysusers option and fix some bugs --- INSTALL.sh | 3 ++- buildpkg | 2 +- functions/functions | 1 + installpkg | 36 +++++++++++++++++++++++++++++++++++- scratchpkg.conf | 1 + 5 files changed, 40 insertions(+), 3 deletions(-) diff --git a/INSTALL.sh b/INSTALL.sh index c4f0508..748c8db 100755 --- a/INSTALL.sh +++ b/INSTALL.sh @@ -4,11 +4,12 @@ BINDIR=/usr/bin FUNCDIR=/usr/share/scratchpkg CONFDIR=/etc HOOK_DIR=/etc/hooks +SYSUSERS_DIR=/etc/sysusers CACHE_DIR=/var/cache/scratchpkg INDEX_DIR=/var/lib/scratchpkg PORT_DIR=/usr/ports -mkdir -pv ${DESTDIR}{${BINDIR},${FUNCDIR},${CONFDIR},${HOOK_DIR},${PORT_DIR}} +mkdir -pv ${DESTDIR}{${BINDIR},${FUNCDIR},${CONFDIR},${HOOK_DIR},${SYSUSERS_DIR},${PORT_DIR}} install -m755 revdep buildpkg installpkg removepkg scratch ${DESTDIR}${BINDIR} install -m644 functions/* ${DESTDIR}${FUNCDIR} install -m644 scratchpkg.conf scratchpkg.repo ${DESTDIR}${CONFDIR} diff --git a/buildpkg b/buildpkg index f870c5d..c754f4e 100755 --- a/buildpkg +++ b/buildpkg @@ -8,7 +8,7 @@ backupconf() { for bkp in ${backup[@]}; do if [ ! -f $bkp ]; then msgerr "File '$bkp' not exist!" - exit 1 + exitscript1 else mv $bkp $bkp.spkgnew fi diff --git a/functions/functions b/functions/functions index 53d0a8e..2ccf5f5 100644 --- a/functions/functions +++ b/functions/functions @@ -18,6 +18,7 @@ SOURCE_DIR="/var/cache/scratchpkg/sources" WORK_DIR="/tmp" LOG_DIR="/var/cache/scratchpkg/log" HOOK_DIR="/etc/hooks" +SYSUSERS_DIR="/etc/sysusers" OPTIONS=(!libtool emptydirs strip docs purge zipman buildflags makeflags) PURGE_FILES=(usr/{,share/}info/dir) diff --git a/installpkg b/installpkg index 1f71c4e..9b96a65 100755 --- a/installpkg +++ b/installpkg @@ -66,7 +66,7 @@ installpkg() { #installing package into system msg2 "Extracting package..." installcmd() { - tar --keep-directory-symlink --no-overwrite-dir -p -x -v -f $1 -C $ROOT_DIR --exclude=.pkginfo --exclude=.pkginstall --exclude=.pkgreadme ${excludefile[@]} + tar --keep-directory-symlink -p -x -v -f $1 -C $ROOT_DIR --exclude=.pkginfo --exclude=.pkginstall --exclude=.pkgreadme ${excludefile[@]} } rm -f /tmp/spkginstall.$name @@ -134,6 +134,8 @@ installpkg() { msg2 "This package has ${GREEN}readme${CRESET}" fi + sysusers + runhooks msg "Successfully $oprmsg ${GREEN}$name-$version-$release${CRESET}." @@ -305,6 +307,38 @@ runhooks() { } +sysusers() { + + if [ "$(ls $SYSUSERS_DIR/*.conf 2>/dev/null)" ]; then + for file in $(ls $SYSUSERS_DIR/*.conf); do + while read uid gid mode dir junk; do + # Ignore comments and blank lines + case "${uid}" in + ""|\#*) continue ;; + esac + if [ -e "$dir" ]; then + if [ "$uid" != '-' ]; then + getent passwd $uid >/dev/null + if [[ "$?" = 0 ]]; then + chown "$uid" "$dir" + fi + fi + if [ "$gid" != '-' ]; then + getent group $gid >/dev/null + if [[ "$?" = 0 ]]; then + chgrp "$gid" "$dir" + fi + fi + if [ "$mode" != '-' ]; then + chmod "$mode" "$dir" + fi + fi + done < "$file" + done + fi + +} + help() { cat << EOF diff --git a/scratchpkg.conf b/scratchpkg.conf index 526986f..6fe97b0 100644 --- a/scratchpkg.conf +++ b/scratchpkg.conf @@ -20,6 +20,7 @@ MAKEFLAGS="-j2" # WORK_DIR="/tmp" # LOG_DIR="/var/cache/scratchpkg/log" # HOOK_DIR="/etc/hooks" +# SYSUSERS_DIR="/etc/sysusers" ## ## GLOBAL PACKAGE OPTIONS