From 359c72151b8eb7cc9e53f985e4b2daf46cb9ce02 Mon Sep 17 00:00:00 2001 From: emmett1 Date: Wed, 15 May 2019 17:26:00 +0800 Subject: [PATCH] change install script style and fix some stuff --- pkgadd | 54 ++++++++++++++++++++++-------------------------------- pkgbuild | 14 -------------- pkgdel | 51 +++++++++++++++++++++++---------------------------- scratch | 6 +++--- 4 files changed, 48 insertions(+), 77 deletions(-) diff --git a/pkgadd b/pkgadd index 8762a35..db362f1 100755 --- a/pkgadd +++ b/pkgadd @@ -119,8 +119,15 @@ parse_opts $(extract_opt $@) ROOT_DIR=${ROOT:-/} INDEX_DIR="$ROOT_DIR/var/lib/scratchpkg/index" -PKGADD_DIR="$ROOT_DIR/var/lib/scratchpkg" -LOCK_FILE="$PKGADD_DIR/spkg.lock" +LOCK_FILE="$ROOT_DIR/var/lib/scratchpkg/spkg.lock" + +# disable pre/post install script when install to custom root location +if [ "$ROOT_DIR" != "/" ]; then + NO_PREINSTALL=yes + NO_POSTINSTALL=yes + NO_PREUPGRADE=yes + NO_POSTUPGRADE=yes +fi # show help page if [ "$SHOWHELP" ] || [ -z "$PKGNAME" ]; then @@ -181,13 +188,13 @@ if [ "$ALREADYINSTALLED" = "yes" ] && [ ! "$UPGRADE_PKG" ] && [ ! "$REINSTALL_PK ret 0 fi -echo -ne "Loading $BASEPKGNAME...\033[0K\r" - TMP_PKGADD="$(mktemp)" || exit 1 TMP_PKGINSTALL="$(mktemp)" || exit 1 TMP_PKGINSTALL_BKP="$(mktemp)" || exit 1 TMP_PKGADD_RMLIST="$(mktemp)" || exit 1 +echo -ne "Loading $BASEPKGNAME...\033[0K\r" + # check integrity of package tar -tf $PKGNAME > $TMP_PKGADD 2>/dev/null if [ $? != 0 ]; then @@ -218,7 +225,7 @@ echo "$opr: $name-$version-$release..." #ignore conflict if [ ! "$IGNORE_CONFLICT" ]; then - while IFS=' ' read -r line; do + while read -r line; do if [ "$line" = "${line%.*}.spkgnew" ]; then line=${line%.*} fi @@ -243,22 +250,10 @@ fi if [ $(grep -x .pkginstall $TMP_PKGADD) ]; then if [ ! "$NO_PREINSTALL" ] && [ ! "$UPGRADE_PKG" ]; then - if [ "$ROOT_DIR" = "/" ]; then - source <(tar -xf "$PKGNAME" .pkginstall -O) pre-install "$version" - else - tar -xf "$PKGNAME" -C "$ROOT_DIR"/tmp .pkginstall - chroot "$ROOT_DIR" bash /tmp/.pkginstall pre-install "$version" - rm -f "$ROOT_DIR"/tmp/.pkginstall - fi + (cd "$ROOT_DIR" && sh <(tar -xf "$PKGNAME" .pkginstall -O) pre-install "$version") fi if [ "$UPGRADE_PKG" ] && [ ! "$NO_PREUPGRADE" ]; then - if [ "$ROOT_DIR" = "/" ]; then - source <(tar -xf "$PKGNAME" .pkginstall -O) pre-upgrade "$version" - else - tar -xf "$PKGNAME" -C "$ROOT_DIR"/tmp .pkginstall - chroot "$ROOT_DIR" bash /tmp/.pkginstall pre-upgrade "$version" - rm -f "$ROOT_DIR"/tmp/.pkginstall - fi + (cd "$ROOT_DIR" && sh <(tar -xf "$PKGNAME" .pkginstall -O) pre-upgrade "$version" "$iversion") fi fi @@ -266,10 +261,8 @@ for i in $(grep ^.pkg* $TMP_PKGADD); do excludefile="$excludefile --exclude=$i" done -installcmd="tar --keep-directory-symlink -p -x -v -f $PKGNAME -C $ROOT_DIR $excludefile" - rm -f $TMP_PKGINSTALL $TMP_PKGINSTALL_BKP -$installcmd | while IFS=' ' read line; do +tar --keep-directory-symlink -p -x -v -f $PKGNAME -C $ROOT_DIR $excludefile | while read line; do if [ "$line" = "${line%.*}.spkgnew" ]; then echo "$line" >> $TMP_PKGINSTALL_BKP line=${line%.*} @@ -288,10 +281,10 @@ done # remove old files from old package that not exist in new package if [ "$UPGRADE_PKG" ] || [ "$REINSTALL_PKG" ]; then grep -Fxv -f $TMP_PKGINSTALL $INDEX_DIR/$name/.files > $TMP_PKGADD_RMLIST - grep -v '/$' $TMP_PKGADD_RMLIST | while IFS=' ' read line; do + grep -v '/$' $TMP_PKGADD_RMLIST | while read line; do rm "$ROOT_DIR/$line" &>/dev/null done - grep '/$' $TMP_PKGADD_RMLIST | tac | while IFS=' ' read line; do + grep '/$' $TMP_PKGADD_RMLIST | tac | while read line; do if [ ! "$(grep -R --exclude-dir="$name" -w "$line" "$INDEX_DIR")" ]; then rmdir "$ROOT_DIR/$line" &>/dev/null fi @@ -313,15 +306,12 @@ done tar -x -f $PKGNAME -C $INDEX_DIR/$name $pkgfiles >/dev/null 2>&1 -if [ ! "$NO_POSTINSTALL" ] && [ ! "$UPGRADE_PKG" ]; then - if [ -f $INDEX_DIR/$name/.pkginstall ]; then - bash $INDEX_DIR/$name/.pkginstall post-install "$version" +if [ -f $INDEX_DIR/$name/.pkginstall ]; then + if [ ! "$NO_POSTINSTALL" ] && [ ! "$UPGRADE_PKG" ]; then + (cd "$ROOT_DIR" && sh $INDEX_DIR/$name/.pkginstall post-install "$version") fi -fi - -if [ "$UPGRADE_PKG" ] && [ ! "$NO_POSTUPGRADE" ]; then - if [ -f $INDEX_DIR/$name/.pkginstall ]; then - bash $INDEX_DIR/$name/.pkginstall post-upgrade "$version" + if [ "$UPGRADE_PKG" ] && [ ! "$NO_POSTUPGRADE" ]; then + (cd "$ROOT_DIR" && sh $INDEX_DIR/$name/.pkginstall post-upgrade "$version" "$iversion") fi fi diff --git a/pkgbuild b/pkgbuild index abfede3..8d8f3ed 100755 --- a/pkgbuild +++ b/pkgbuild @@ -213,12 +213,6 @@ prepare_src() { fi } -runprebuildscript() { - if [ "`type -t pre_build`" = "function" ]; then - pre_build - fi -} - run_build() { if [ "$UID" != 0 ]; then msgerr "You must build package as root, or use fakeroot." @@ -230,14 +224,8 @@ run_build() { [ "$MAKE_FLAGS" = 1 ] && export MAKEFLAGS || unset MAKEFLAGS [ "$BUILD_FLAGS" = 1 ] && export CFLAGS CXXFLAGS || unset CFLAGS CXXFLAGS - [ -f $PWD/install ] && source $PWD/install - pushd $SRC >/dev/null - if [ "$NO_PREBUILD" != yes ]; then - runprebuildscript - fi - if [ "$LOGGING" = yes ]; then ( set -e -x; build 2>&1 | tee $LOG_DIR/$name-$version-$release.log @@ -501,7 +489,6 @@ parse_opts() { -w | --keep-work) KEEP_WORK=yes ;; -l | --log) LOGGING=yes ;; -h | --help) SHOWHELP=yes ;; - --no-prebuild) NO_PREBUILD=yes ;; --no-preinstall) NO_PREINSTALL=yes; OPTS+=($1) ;; --no-postinstall) OPTS+=($1) ;; --no-preupgrade) OPTS+=($1) ;; @@ -539,7 +526,6 @@ Options: --srcdir= override directory path for sources --pkgdir= override directory path for compiled package --logdir= override directory path for build logs - --no-prebuild skip prebuild script before build package --no-preinstall skip preinstall script before install package --no-postinstall skip postinstall script after install package --no-preupgrade skip preupgrade script before upgrade package diff --git a/pkgdel b/pkgdel index 8a37e53..d313ae0 100755 --- a/pkgdel +++ b/pkgdel @@ -103,9 +103,15 @@ isinstalled() { parse_opts $(extract_opt $@) -INDEX_DIR="$ROOT/var/lib/scratchpkg/index" -PKGDEL_DIR="$ROOT/var/lib/scratchpkg" -LOCK_FILE="$PKGDEL_DIR/spkg.lock" +ROOT_DIR=${ROOT:-/} +INDEX_DIR="$ROOT_DIR/var/lib/scratchpkg/index" +LOCK_FILE="$ROOT_DIR/var/lib/scratchpkg/spkg.lock" + +# disable pre/post remove script when remove from custom root location +if [ "$ROOT_DIR" != "/" ]; then + NO_PREREMOVE=yes + NO_POSTREMOVE=yes +fi # show help page if [ "$SHOWHELP" ] || [ -z "$RMNAME" ]; then @@ -147,56 +153,45 @@ if [ -z $name ] && [ -z $version ] && [ -z $release ]; then fi echo "remove: $name-$version-$release..." - -# source .install script -if [ "$ROOT" = "" ]; then - if [ -f $INDEX_DIR/$name/.pkginstall ]; then - source $INDEX_DIR/$name/.pkginstall - fi -fi -if [ ! "$NO_PREREMOVE" ]; then - if [ "`type -t pre_remove`" = "function" ]; then - pre_remove "$version" &>/dev/null - fi +if [ ! "$NO_PREREMOVE" ] && [ -f $INDEX_DIR/$name/.pkginstall ]; then + (cd $ROOT_DIR && sh $INDEX_DIR/$name/.pkginstall pre-remove "$version") fi if [ -f "$INDEX_DIR/$name/.bkpfiles" ]; then - while IFS=' ' read -r line; do - if [ -e "$ROOT/$line" ] || [ -L "$ROOT/$line" ]; then + while read -r line; do + if [ -e "$ROOT_DIR/$line" ] || [ -L "$ROOT_DIR/$line" ]; then [ "$VERBOSE_REMOVE" = yes ] && echo "<<< $line" - rm "$ROOT/$line" + rm "$ROOT_DIR/$line" fi done < <(tac $INDEX_DIR/$name/.bkpfiles) fi -while IFS=' ' read -r line; do - if [ -e "$ROOT/$line" ] || [ -L "$ROOT/$line" ]; then +while read -r line; do + if [ -e "$ROOT_DIR/$line" ] || [ -L "$ROOT_DIR/$line" ]; then [ "$VERBOSE_REMOVE" = yes ] && echo "<<< $line" - rm "$ROOT/$line" + rm "$ROOT_DIR/$line" fi done < <(tac $INDEX_DIR/$name/.files | grep -v '/$') -while IFS=' ' read -r line; do +while read -r line; do if [ ! "$(grep -R --exclude-dir="$name" -w "$line" "$INDEX_DIR")" ]; then - if [ -d "$ROOT/$line" ]; then + if [ -d "$ROOT_DIR/$line" ]; then [ "$VERBOSE_REMOVE" = yes ] && echo "<<< $line" - rmdir "$ROOT/$line" + rmdir "$ROOT_DIR/$line" fi fi done < <(tac $INDEX_DIR/$name/.files | grep '/$') -if [ ! "$NO_POSTREMOVE" ]; then - if [ "`type -t post_remove`" = "function" ]; then - post_remove "$version" &>/dev/null - fi +if [ ! "$NO_POSTREMOVE" ] && [ -f $INDEX_DIR/$name/.pkginstall ]; then + (cd $ROOT_DIR && sh $INDEX_DIR/$name/.pkginstall post-remove "$version") fi rm -rf $INDEX_DIR/$name # running ldconfig if [ -x /sbin/ldconfig ]; then - /sbin/ldconfig -r $ROOT/ + /sbin/ldconfig -r $ROOT_DIR fi ret 0 diff --git a/scratch b/scratch index 80834a3..540ce1b 100755 --- a/scratch +++ b/scratch @@ -179,7 +179,7 @@ scratch_integrity() { if [ "$1" ]; then pushd / if [ -f $INDEX_DIR/$1/.files ]; then - while IFS=' ' read -r line; do + while read -r line; do if [ ! -e "$line" ]; then MISSING_FILE=yes if [ -L "$line" ]; then @@ -197,7 +197,7 @@ scratch_integrity() { else pushd / for pkg in $(allinstalled); do - while IFS=' ' read -r line; do + while read -r line; do if [ ! -e "$line" ]; then MISSING_FILE=yes if [ -L "$line" ]; then @@ -360,7 +360,7 @@ scratch_files() { if ! isinstalled $1; then msg "Package'$1' not installed." else - while IFS=' ' read -r line; do + while read -r line; do echo "$line" done < <(cat $INDEX_DIR/$1/.files) fi