From e1f6bc951f5effcb67826b34c4e1e126294ede9d Mon Sep 17 00:00:00 2001 From: emmett1 Date: Mon, 13 Aug 2018 22:05:23 +0800 Subject: [PATCH] updated --- INSTALL.sh | 5 +- pkgadd | 155 +++++++++++++++++++++--------------------------- pkgbuild | 30 ++++------ pkgdel | 17 +++++- pkgdeplist | 58 ++++++++++++------ scratch | 17 +++++- scratchpkg.conf | 5 -- 7 files changed, 152 insertions(+), 135 deletions(-) diff --git a/INSTALL.sh b/INSTALL.sh index 3bfcbc3..b9feb7a 100755 --- a/INSTALL.sh +++ b/INSTALL.sh @@ -3,13 +3,12 @@ BINDIR=/usr/bin 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},${CONFDIR},${HOOK_DIR},${SYSUSERS_DIR},${PORT_DIR}} -install -m755 revdep pkgadd pkgdel pkgbuild pkgcreate pkgdeplist scratch ${DESTDIR}${BINDIR} +mkdir -pv ${DESTDIR}{${BINDIR},${CONFDIR},${HOOK_DIR},${PORT_DIR}} +install -m755 revdep pkgadd pkgdel pkgbuild pkgdeplist scratch ${DESTDIR}${BINDIR} install -m644 scratchpkg.conf scratchpkg.repo ${DESTDIR}${CONFDIR} install -m755 extra/* ${DESTDIR}${BINDIR} mkdir -pv ${DESTDIR}${INDEX_DIR}/index diff --git a/pkgadd b/pkgadd index 123aeba..85ae935 100755 --- a/pkgadd +++ b/pkgadd @@ -6,11 +6,12 @@ YELLOW='\e[0;33m' #Yellow CYAN='\e[0;36m' #Cyan CRESET='\e[0m' #Reset color -INDEX_DIR=$ROOT/var/lib/scratchpkg/index -LOCK_FILE=$ROOT/var/lib/scratchpkg/spkg.lock -TMP_PKGINSTALL=$ROOT/var/lib/scratchpkg/spkg.install -HOOK_DIR=/etc/hooks -SYSUSERS_DIR=/etc/sysusers +trap "interrupted" SIGHUP SIGINT SIGQUIT SIGTERM + +interrupted() { + echo + ret 1 +} nocolor() { RED= @@ -65,75 +66,37 @@ runhooks() { } -sysusers() { +#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 + #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 -Usage: - $(basename $0) package.spkg.txz - -Options: - -u, --upgrade upgrade package - -r, --reinstall reinstall package - -d, --no-dep skip dependency check - -c, --ignore-conflict ignore conflict when installing package - -v, --verbose print files installed - -h, --help show this help message - --no-preinstall skip preinstall script before build/install package - --no-postinstall skip postinstall script after install package - --no-preupgrade skip preupgrade script before upgrade package - --no-postupgrade skip postupgrade script after upgrade package - --no-backup skip backup when upgrading package - --no-color disable colour for output - -Example: - installpkg foobar-1.0-1.spkg.txz -uc --no-backup upgrade package foobar-1.0-1 without backup its - old configuration files and skip conflict check -EOF - -} - -extract_opt() { - for opt in $@; do - case $opt in - --*) OPTS+=($opt) ;; - -*) for (( i=1; i<${#opt}; i++ )); do OPTS+=(-${opt:$i:1}); done ;; - *) OPTS+=($opt) ;; - esac - done - echo ${OPTS[@]} -} +#} help() { cat << EOF @@ -145,6 +108,7 @@ Options: -r, --reinstall reinstall package -c, --ignore-conflict ignore conflict when installing package -v, --verbose print files installed + -s, --silent print install message in simple format -h, --help show this help message --no-preinstall skip preinstall script before build/install package --no-postinstall skip postinstall script after install package @@ -181,6 +145,7 @@ parse_opts() { -r | --reinstall) REINSTALL_PKG=yes ;; -c | --ignore-conflict) IGNORE_CONFLICT=yes ;; -v | --verbose) VERBOSE_INSTALL=yes ;; + -s | --silent) QUIET_INSTALL=yes ;; -h | --help) SHOWHELP=yes ;; --no-preinstall) NO_PREINSTALL=yes ;; --no-postinstall) NO_POSTINSTALL=yes ;; @@ -205,6 +170,11 @@ ret() { parse_opts $(extract_opt $@) +INDEX_DIR=$ROOT/var/lib/scratchpkg/index +LOCK_FILE=$ROOT/tmp/spkg.lock +TMP_PKGINSTALL=$ROOT/var/lib/scratchpkg/spkg.install +HOOK_DIR=/etc/hooks + # show help page if [ "$SHOWHELP" ] || [ -z "$PKGNAME" ]; then help @@ -225,6 +195,10 @@ if [ -f $LOCK_FILE ]; then exit 1 else touch $LOCK_FILE + if [ "$?" != 0 ]; then + msgerr "Cant create lock file in '$LOCK_FILE'" + exit 1 + fi fi if [ -n "$PKGNAME" ]; then @@ -287,11 +261,15 @@ fi opr=Installing; oprdone=installed [ "$UPGRADE_PKG" ] && { opr=Upgrading; oprdone=upgraded; } [ "$REINSTALL_PKG" ] && { opr=Reinstalling; oprdone=reinstalled; } -msg "$opr '$name-$version-$release'..." +if [ "$SILENT_INSTALL" ]; then + echo -ne "$opr '$name-$version-$release'... " +else + msg "$opr '$name-$version-$release'..." +fi #ignore conflict if [ ! "$IGNORE_CONFLICT" ]; then - msg2 "Checking file conflict..." + [ "$SILENT_INSTALL" ] || msg2 "Checking file conflict..." while IFS=' ' read -r line; do if [ "$line" = "${line%.*}.spkgnew" ]; then line=${line%.*} @@ -308,6 +286,7 @@ if [ ! "$IGNORE_CONFLICT" ]; then done < <(tar -tf "$PKGNAME" --exclude=.pkginfo --exclude=.pkginstall --exclude=.pkgreadme ${excludefile[@]} | grep -v '/$') if [ "${#fileconflict[@]}" -gt 0 ]; then + [ "$SILENT_INSTALL" ] && echo msgerr "File conflict found:" for fc in ${fileconflict[@]}; do msg2 "$fc" @@ -327,21 +306,21 @@ fi # run preinstall script if no --no-preinstall flag and not upgrade package if [ ! "$NO_PREINSTALL" ] && [ ! "$UPGRADE_PKG" ]; then if [ "`type -t pre_install`" = "function" ]; then - msg2 "Running preinstall script..." - pre_install "$version" + [ "$SILENT_INSTALL" ] || msg2 "Running preinstall script..." + pre_install "$version" &>/dev/null fi fi # run preupgrade script if package upgrade if [ "$UPGRADE_PKG" ] && [ ! "$NO_PREUPGRADE" ]; then if [ "`type -t pre_upgrade`" = "function" ]; then - msg2 "Running preupgrade script..." - pre_upgrade "$version" "$iversion" + [ "$SILENT_INSTALL" ] || msg2 "Running preupgrade script..." + pre_upgrade "$version" "$iversion" &>/dev/null fi fi #installing package into system -msg2 "Extracting package..." +[ "$SILENT_INSTALL" ] || msg2 "Extracting package..." installcmd="tar --keep-directory-symlink -p -x -v -f $PKGNAME -C ${ROOT:-/} --exclude=.pkginfo --exclude=.pkginstall --exclude=.pkgreadme" rm -f $TMP_PKGINSTALL @@ -361,7 +340,7 @@ done # remove old files from old package that not exist in new package if [ "$UPGRADE_PKG" ] || [ "$REINSTALL_PKG" ]; then - msg2 "Removing old files..." + [ "$SILENT_INSTALL" ] || msg2 "Removing old files..." grep -v '/$' $INDEX_DIR/$name/.files | while IFS=' ' read line; do if [ ! "$(grep -Fx "$line" $TMP_PKGINSTALL)" ]; then rm "$ROOT/$line" &>/dev/null @@ -386,24 +365,28 @@ tar -x -f $PKGNAME -C $INDEX_DIR/$name .pkginstall .pkgreadme >/dev/null 2>&1 if [ ! "$NO_POSTINSTALL" ] && [ ! "$UPGRADE_PKG" ]; then if [ "`type -t post_install`" = "function" ]; then - msg2 "Running postinstall script..." - post_install "$version" + [ "$SILENT_INSTALL" ] || msg2 "Running postinstall script..." + post_install "$version" &>/dev/null fi fi if [ "$UPGRADE_PKG" ] && [ ! "$NO_POSTUPGRADE" ]; then if [ "`type -t post_upgrade`" = "function" ]; then - msg2 "Running postupgrade script..." - post_upgrade "$version" "$iversion" + [ "$SILENT_INSTALL" ] || msg2 "Running postupgrade script..." + post_upgrade "$version" "$iversion" &>/dev/null fi fi if [ "$ROOT" = "" ]; then runhooks - sysusers + [ $(type -p sysusers) ] && sysusers fi -msg "Package '$name-$version-$release' $oprdone." +if [ "$SILENT_INSTALL" ]; then + echo -e "done" +else + msg "Package '$name-$version-$release' $oprdone." +fi # running ldconfig if [ "$ROOT" = "" ] && [ -x /sbin/ldconfig ]; then diff --git a/pkgbuild b/pkgbuild index b6391c2..b27c675 100755 --- a/pkgbuild +++ b/pkgbuild @@ -468,6 +468,7 @@ Options: -o, --download download only source file -x, --extract extract only source file -w, --keep-work keep working directory + -s, --silent print install message in simple format -h, --help show this help message --srcdir= override directory path for sources --pkgdir= override directory path for compiled package @@ -531,7 +532,7 @@ parse_opts() { -o | --download) DOWNLOAD_ONLY=yes ;; -x | --extract) EXTRACT_ONLY=yes ;; -w | --keep-work) KEEP_WORK=yes ;; - -s | --silent-install) SILENT_INSTALL=yes ;; + -s | --silent) INST_OPT=$1 ;; -h | --help) SHOWHELP=yes ;; --no-preinstall) NO_PREINSTALL=yes; OPTS+=($1) ;; --no-postinstall) OPTS+=($1) ;; @@ -552,10 +553,6 @@ parse_opts() { main() { - parse_opts $(extract_opt $@) - - local FILE - if [ -f $PKGBUILD_CONF ]; then source $PKGBUILD_CONF else @@ -563,6 +560,8 @@ main() { exit 1 fi + parse_opts $(extract_opt $@) + # show usage if [ "$SHOWHELP" ]; then help @@ -575,6 +574,7 @@ main() { msgerr "'$PKGBUILD_BSCRIPT' file not found." exit 1 fi + description=$(grep "^# description[[:blank:]]*:" $PKGBUILD_BSCRIPT | sed 's/^# description[[:blank:]]*:[[:blank:]]*//') backup=$(grep "^# backup[[:blank:]]*:" $PKGBUILD_BSCRIPT | sed 's/^# backup[[:blank:]]*:[[:blank:]]*//') depends=$(grep "^# depends[[:blank:]]*:" $PKGBUILD_BSCRIPT | sed 's/^# depends[[:blank:]]*:[[:blank:]]*//') @@ -589,6 +589,10 @@ main() { exit 1 else touch "$LOCK_FILE" + if [ "$?" != 0 ]; then + msgerr "Cant create lock file in '$LOCK_FILE'" + exit 1 + fi fi if [ -z "$SOURCE_DIR" ]; then @@ -641,21 +645,7 @@ main() { # install package if [ "$INSTALL_PKG" ] || [ "$REINSTALL_PKG" ] || [ "$UPGRADE_PKG" ]; then - [ "$INSTALL_PKG" ] && opr=Installing - [ "$REINSTALL_PKG" ] && opr=Reinstalling - [ "$UPGRADE_PKG" ] && opr=Upgrading - if [ "$SILENT_INSTALL" ]; then - echo -ne "$opr '$PKGNAME'... " - pkgadd $PACKAGE_DIR/$PKGNAME ${OPTS[@]} >/dev/null 2>&1 - if [ $? = 0 ]; then - echo -e "${GREEN}done${CRESET}." - else - echo -e "${RED}failed${CRESET}." - abort 1 - fi - else - pkgadd $PACKAGE_DIR/$PKGNAME ${OPTS[@]} || abort 1 - fi + pkgadd $PACKAGE_DIR/$PKGNAME $INST_OPT ${OPTS[@]} || abort 1 fi abort 0 diff --git a/pkgdel b/pkgdel index 4700589..2897628 100755 --- a/pkgdel +++ b/pkgdel @@ -6,6 +6,13 @@ YELLOW='\e[0;33m' #Yellow CYAN='\e[0;36m' #Cyan CRESET='\e[0m' #Reset color +trap "interrupted" SIGHUP SIGINT SIGQUIT SIGTERM + +interrupted() { + echo + ret 1 +} + nocolor() { RED= GREEN= @@ -128,7 +135,7 @@ ret() { parse_opts $(extract_opt $@) INDEX_DIR=$ROOT/var/lib/scratchpkg/index -LOCK_FILE=$ROOT/var/lib/scratchpkg/spkg.lock +LOCK_FILE=$ROOT/tmp/spkg.lock HOOK_DIR=/etc/hook # show help page @@ -149,6 +156,10 @@ if [ -f $LOCK_FILE ]; then exit 1 else touch $LOCK_FILE + if [ "$?" != 0 ]; then + msgerr "Cant create lock file in '$LOCK_FILE'" + exit 1 + fi fi if [ ! -d $INDEX_DIR/$RMNAME ]; then @@ -178,7 +189,7 @@ fi if [ ! "$NO_PREREMOVE" ]; then if [ "`type -t pre_remove`" = "function" ]; then msg2 "Running preremove script..." - pre_remove "$version" + pre_remove "$version" &>/dev/null fi fi @@ -200,7 +211,7 @@ done < <(tac $INDEX_DIR/$name/.files | grep '/$') if [ ! "$NO_POSTREMOVE" ]; then if [ "`type -t post_remove`" = "function" ]; then msg2 "Running postremove script..." - post_remove "$version" + post_remove "$version" &>/dev/null fi fi diff --git a/pkgdeplist b/pkgdeplist index 44176f7..627f8b3 100755 --- a/pkgdeplist +++ b/pkgdeplist @@ -6,6 +6,9 @@ YELLOW='\e[0;33m' #Yellow CYAN='\e[0;36m' #Cyan CRESET='\e[0m' #Reset color +INDEX_DIR="/var/lib/scratchpkg/index" +REPO_FILE="/etc/scratchpkg.repo" + msgerr() { echo -e "${RED}==> ERROR:${CRESET} $1" } @@ -60,6 +63,7 @@ deplist() { # check dependencies for i in $(checkdep $1); do + [ -e $INDEX_DIR/$i/.pkginfo -a "$QUICK" ] && continue if [[ $(echo ${DEP[@]} | tr " " "\n" | grep -x $i) = "" ]]; then deplist $i fi @@ -78,12 +82,38 @@ deplist() { done } -INDEX_DIR="/var/lib/scratchpkg/index" -REPO_FILE="/etc/scratchpkg.repo" +usage() { + cat << EOF +Usage: + $(basename $0) [ ] -if [ ! "$1" ]; then - msgerr "Please specify package name to list its dependencies order." - exit 1 +Options: + -q, --quick calculate only not-installed package/dependency + -i, --installed print only installed package/dependency + -n, --not-installed print only not-installed package/dependency + -m, --missing print only missing package/dependency + -l, --loop ignore loop dependencies + -h, --help print this help message + +EOF +} + +while [ "$1" ]; do + case $1 in + -q|--quick) QUICK=1 ;; + -i|--installed) INSTALLED=1 ;; + -n|--not-installed) NOT_INSTALLED=1 ;; + -m|--missing) MISSING=1 ;; + -l|--loop) IGNORE_LOOP=1 ;; + -h|--help) USAGE=1 ;; + *) PKG+=($1) ;; + esac + shift +done + +if [ "$USAGE" = 1 ]; then + usage + exit 0 fi if [ ! -f "$REPO_FILE" ]; then @@ -91,6 +121,11 @@ if [ ! -f "$REPO_FILE" ]; then exit 1 fi +if [ "${#PKG[@]}" = 0 ]; then + msgerr "Please specify package name to list its dependencies order." + exit 1 +fi + while read repodir repourl junk; do case $repodir in ""|"#"*) continue ;; @@ -98,17 +133,6 @@ while read repodir repourl junk; do PORT_REPO+=($repodir) done < "$REPO_FILE" -while [ "$1" ]; do - case $1 in - -i|--installed) INSTALLED=1 ;; - -n|--not-installed) NOT_INSTALLED=1 ;; - -m|--missing) MISSING=1 ;; - -l|--loop) IGNORE_LOOP=1 ;; - *) PKG+=($1) ;; - esac - shift -done - # set all to 1 (all) if not use any of it if [ ! "$INSTALLED" ] && [ ! "$NOT_INSTALLED" ] && [ ! "$MISSING" ]; then INSTALLED=1 @@ -132,7 +156,7 @@ done for deps in ${DEP[@]}; do if [ -e $INDEX_DIR/$deps/.pkginfo ]; then [ "$INSTALLED" ] && msginst "$deps" # print installed - elif ! getportpath "$deps" >/dev/null; then + elif [ ! $(getportpath "$deps") ]; then [ "$MISSING" ] && msgmiss "$deps" # print missing port else [ "$NOT_INSTALLED" ] && msgnoinst "$deps" # print not installed diff --git a/scratch b/scratch index 11ea3d6..93a4bb3 100755 --- a/scratch +++ b/scratch @@ -156,6 +156,16 @@ checkintegrity() { [ ! "$MISSING_FILE" ] && msg "$p files is consistent with package tree." } +listinstalled() { + local pkg + for pkg in $(allinstalled); do + iname=$(installed_pkg_info name $pkg) + iversion=$(installed_pkg_info version $pkg) + irelease=$(installed_pkg_info release $pkg) + echo -e "$iname ${GREEN}$iversion${CRESET}-${BLUE}$irelease${CRESET}" + done +} + listorphan() { local pkg all depends deps @@ -472,7 +482,7 @@ installpkg() { return 0 fi echo "Resolving dependencies..." - INST="$(pkgdeplist -l -n ${IPKG[@]} | awk '{print $2}')" + INST="$(pkgdeplist -l -q ${IPKG[@]} | awk '{print $2}')" if [ "$INST" ]; then echo @@ -921,6 +931,11 @@ main() { exit 0 fi + if [ "$mode" = "listinst" ]; then + listinstalled + exit 0 + fi + if [ "$mode" = "help" ]; then printhelp $1 exit 0 diff --git a/scratchpkg.conf b/scratchpkg.conf index 45dd1a1..39038c6 100644 --- a/scratchpkg.conf +++ b/scratchpkg.conf @@ -19,7 +19,6 @@ MAKEFLAGS="-j$(nproc)" # PACKAGE_DIR="/var/cache/scratchpkg/packages" # WORK_DIR="/var/cache/scratchpkg/work" # HOOK_DIR="/etc/hooks" -# SYSUSERS_DIR="/etc/sysusers" ## ## GLOBAL PACKAGE OPTIONS @@ -46,7 +45,3 @@ MAKEFLAGS="-j$(nproc)" # -- Manual (man and info) directories to compress (if zipman is specified) # MAN_DIRS=({usr{,/local}{,/share},opt/*}/man) - -# -- Uncomment and specified file/path you dont want to -# -- extract from package into system -# NO_EXTRACT=(usr/share/locale)