From 61f601698ae7bb5f1dc9d394d565a43e0fc7f13b Mon Sep 17 00:00:00 2001 From: emmett1 Date: Sun, 6 Aug 2017 16:36:14 +0800 Subject: [PATCH] updated and add {pre,post}upgrade script --- buildpkg | 30 ++++++++++------ installpkg | 75 ++++++++++++++++++++++++++++++++------- scratch | 101 +++++++++++++++++++++++++++++++++++++++++------------ 3 files changed, 160 insertions(+), 46 deletions(-) diff --git a/buildpkg b/buildpkg index fb2251b..3ccd45b 100755 --- a/buildpkg +++ b/buildpkg @@ -96,7 +96,7 @@ preparesource() { for i in ${noextract[@]}; do if [ "$i" = "$tarballname" ]; then NO_EXTRACT=yes - cp $SOURCE_DIR/$tarballname $SRC && msg "Preparing ${color_green}$tarballname${color_reset}..." || ERROR_PREPARE_SOURCE=yes + msg "Preparing ${color_green}$tarballname${color_reset}..." && cp $SOURCE_DIR/$tarballname $SRC || ERROR_PREPARE_SOURCE=yes break fi done @@ -109,19 +109,18 @@ preparesource() { COMMAND="cp $SOURCE_DIR/$tarballname $SRC" MODE="Preparing" ;; esac - + + msg "$MODE ${color_green}$tarballname${color_reset}..." $COMMAND if [ $? != 0 ]; then msg "$MODE ${color_red}$tarballname${color_reset} failed." clearworkdir exitscript1 - else - msg "$MODE ${color_green}$tarballname${color_reset}..." fi fi else - cp $sources $SRC && msg "Preparing ${color_green}$sources${color_reset}..." || ERROR_PREPARE_SOURCE=yes + msg "Preparing ${color_green}$sources${color_reset}..." && cp $sources $SRC || ERROR_PREPARE_SOURCE=yes fi done @@ -131,7 +130,7 @@ preparesource() { exitscript1 fi - for runscript in preinstall postinstall preremove postremove readme; do + for runscript in preinstall postinstall preupgrade postupgrade preremove postremove readme; do if [ -f $runscript ]; then [ ! -d $PKG/.pkginstall ] && mkdir $PKG/.pkginstall cp $runscript $PKG/.pkginstall @@ -142,8 +141,8 @@ preparesource() { loadspkgbuild() { if [ -f $BUILD_SCRIPT ]; then - getpkginfo . $BUILD_SCRIPT + getpkginfo else msg "${color_red}Error no $BUILD_SCRIPT found.${color_reset}" exitscript1 @@ -193,6 +192,7 @@ packaging() { compressinfomanpages purgefiles + # only installed depends will get written into package for dep in ${depends[@]}; do if [ -d $INDEX_DIR/$dep ]; then if [ -z "$newdep" ]; then @@ -203,6 +203,7 @@ packaging() { fi done + # only installed makedepends will get written into package for mdep in ${makedepends[@]}; do if [ -d $INDEX_DIR/$mdep ]; then if [ -z "$newmdep" ]; then @@ -225,12 +226,13 @@ packaging() { [ -n "$conflict" ] && echo "conflict = ${conflict[@]}" >> .pkginfo [ -n "$newdep" ] && echo "depends = ${newdep[@]}" >> .pkginfo [ -n "$newmdep" ] && echo "makedepends = ${newmdep[@]}" >> .pkginfo + [ -n "$noextract" ] && echo "noextract = $noextract" >> .pkginfo msg "Packaging ${color_green}$name-$version-$release${color_reset}..." if [ -d .pkginstall ]; then - tar -c -J -f $PACKAGE_DIR/$PKGNAME * .pkginfo .pkginstall + tar -c -J -p -f $PACKAGE_DIR/$PKGNAME * .pkginfo .pkginstall else - tar -c -J -f $PACKAGE_DIR/$PKGNAME * .pkginfo + tar -c -J -p -f $PACKAGE_DIR/$PKGNAME * .pkginfo fi if [ $? != 0 ]; then @@ -301,8 +303,11 @@ buildpkg() { preparesource + [ "$UPGRADE_PKG" ] && NO_PREINSTALL=yes + if [ ! "$NO_PREINSTALL" ]; then runpreinstall + NO_PREINSTALL=yes fi buildpackage @@ -441,6 +446,9 @@ parse_options() { --no-preinstall) NO_PREINSTALL=yes ;; + --no-preinstall) + NO_POSTINSTALL=yes + ;; -rd|--redownload) REDOWNLOAD_SOURCE=yes ;; @@ -571,7 +579,9 @@ main() { REINSTALL_PKG="$REINSTALL_PKG" \ UPGRADE_PKG="$UPGRADE_PKG" \ VERBOSE_INSTALL="$VERBOSE_INSTALL" \ - installpkg $PACKAGE_DIR/$PKGNAME --no-preinstall + NO_PREINSTALL="$NO_PREINSTALL" \ + NO_POSTINSTALL="$NO_POSTINSTALL" \ + installpkg $PACKAGE_DIR/$PKGNAME exitscript0 fi diff --git a/installpkg b/installpkg index c852684..f4e7c03 100755 --- a/installpkg +++ b/installpkg @@ -25,20 +25,22 @@ installpkg() { # create lock file prevent simultaneous install package spkglock - # read preinstall in package & run it - if [ ! $NO_PREINSTALL ]; then - if [ $(tar -tf "$PKGNAME" | grep ".pkginstall/preinstall") ]; then - msg "Running preinstall script..." - tar -xf $PKGNAME .pkginstall/preinstall -O | sh && PREINSTALL_STATUS=OK || PREINSTALL_STATUS=KO - fi + # run preinstall script if no --no-preinstall flag and not upgrade package + if [ ! "$NO_PREINSTALL" ] && [ ! "$UPGRADE_PKG" ]; then + run_preinstall + fi + + # run preupgrade script if package upgrade + if [ "$UPGRADE_PKG" ] && [ ! "$NO_PREUPGRADE" ]; then + run_preupgrade fi #installing package into system msg "Installing ${color_green}$packagename${color_reset}..." if [ "$VERBOSE_INSTALL" ]; then - tar -x -v -h -f $PKGNAME -C $ROOT_DIR --exclude=.pkginfo --exclude=.pkginstall + tar --keep-directory-symlink -x -v -p -f $PKGNAME -C $ROOT_DIR --exclude=.pkginfo --exclude=.pkginstall else - tar -x -h -f $PKGNAME -C $ROOT_DIR --exclude=.pkginfo --exclude=.pkginstall + tar --keep-directory-symlink -x -p -f $PKGNAME -C $ROOT_DIR --exclude=.pkginfo --exclude=.pkginstall fi if [ $? != 0 ]; then @@ -56,26 +58,40 @@ installpkg() { tar -x -f $PKGNAME -C $INDEX_DIR/$name .pkginfo tar -t -f $PKGNAME --exclude=.pkginfo --exclude=.pkginstall > $INDEX_DIR/$name/.files - tar -x -f $PKGNAME -C $INDEX_DIR/$name .pkginstall/preinstall .pkginstall/postinstall .pkginstall/preremove .pkginstall/postremove .pkginstall/readme --strip=1 >/dev/null 2>&1 + tar -x -f $PKGNAME -C $INDEX_DIR/$name .pkginstall/preinstall .pkginstall/postinstall .pkginstall/preupgrade .pkginstall/postupgrade .pkginstall/preremove .pkginstall/postremove .pkginstall/readme --strip=1 >/dev/null 2>&1 msg "Successfully install ${color_green}$packagename${color_reset}." - restoreconf - - if [ ! $NO_POSTINSTALL ]; then + if [ ! "$NO_POSTINSTALL" ] && [ ! "$UPGRADE_PKG" ]; then run_postinstall fi + if [ "$UPGRADE_PKG" ] && [ ! "$NO_POSTUPGRADE" ]; then + run_postupgrade + fi + + restoreconf + case $PREINSTALL_STATUS in OK) msg "preinstall : ${color_green}OK${color_reset}" ;; KO) msg "preinstall : ${color_red}FAIL${color_reset}" ;; esac + case $PREUPGRADE_STATUS in + OK) msg "preupgrade : ${color_green}OK${color_reset}" ;; + KO) msg "preupgrade : ${color_red}FAIL${color_reset}" ;; + esac + case $POSTINSTALL_STATUS in OK) msg "postinstall : ${color_green}OK${color_reset}" ;; KO) msg "postinstall : ${color_red}FAIL${color_reset}" ;; esac + case $POSTUPGRADE_STATUS in + OK) msg "postupgrade : ${color_green}OK${color_reset}" ;; + KO) msg "postupgrade : ${color_red}FAIL${color_reset}" ;; + esac + if [ -f $INDEX_DIR/$name/readme ]; then msg "This package has ${color_green}readme${color_reset}" fi @@ -240,13 +256,40 @@ check_directory() { } +run_preinstall() { + + if [ $(tar -tf "$PKGNAME" | grep ".pkginstall/preinstall") ]; then + msg "Running preinstall script..." + tar -xf $PKGNAME .pkginstall/preinstall -O | sh && PREINSTALL_STATUS=OK || PREINSTALL_STATUS=KO + fi + +} + +run_preupgrade() { + + if [ $(tar -tf "$PKGNAME" | grep ".pkginstall/preupgrade") ]; then + msg "Running preupgrade script..." + tar -xf $PKGNAME .pkginstall/preupgrade -O | sh && PREUPGRADE_STATUS=OK || PREUPGRADE_STATUS=KO + fi + +} + run_postinstall() { if [ -f $INDEX_DIR/$name/postinstall ]; then msg "Running postinstall script..." sh $INDEX_DIR/$name/postinstall && POSTINSTALL_STATUS=OK || POSTINSTALL_STATUS=KO fi -} +} + +run_postupgrade() { + + if [ -f $INDEX_DIR/$name/postupgrade ]; then + msg "Running postupgrade script..." + sh $INDEX_DIR/$name/postupgrade && POSTUPGRADE_STATUS=OK || POSTUPGRADE_STATUS=KO + fi + +} parse_options() { @@ -273,6 +316,12 @@ parse_options() { --no-postinstall) NO_POSTINSTALL=yes ;; + --no-preupgrade) + NO_PREUPGRADE=yes + ;; + --no-preupgrade) + NO_POSTUPGRADE=yes + ;; --no-backup) NO_BACKUP=yes ;; diff --git a/scratch b/scratch index 4be249c..ed16b3b 100755 --- a/scratch +++ b/scratch @@ -290,6 +290,31 @@ showglobaldependent() { done } +catport() { + + for cat in ${PORT_REPO[@]}; do + if [ -d $cat ]; then + if [ -f $cat/$CAT_PORT/$BUILD_SCRIPT ]; then + cat $cat/$CAT_PORT/$BUILD_SCRIPT + break + fi + fi + done + +} + +showportpath() { + + for path in ${PORT_REPO[@]}; do + if [ -d $cat ]; then + if [ -d $path/$PORT_PATH ]; then + msg "$path/$PORT_PATH" + fi + fi + done + +} + interrupted() { echo "" msg "${color_yellow}Interrupted!${color_reset}" @@ -333,34 +358,44 @@ parse_options() { --no-color) NO_COLOR=yes ;; + -c|--cat-port) + if [ ! "$2" ]; then + msg "Option '$1' require an argument (package to show its port script)" + exit 1 + fi + CAT_PORT="$2" + shift + ;; -dp|--dependent) - if [ ! "$2" ]; then - info "Option '$1' require an argument (package to show its dependent)" - exit 1 - fi - PACKAGE_DEPENDENT="$2" - shift ;; + if [ ! "$2" ]; then + msg "Option '$1' require an argument (package to show its dependent)" + exit 1 + fi + PACKAGE_DEPENDENT="$2" + shift + ;; -gdp|--global-dependent) - if [ ! "$2" ]; then - info "Option '$1' require an argument (package to show its dependent)" - exit 1 - fi - GLOBAL_PACKAGE_DEPENDENT="$2" - shift ;; + if [ ! "$2" ]; then + msg "Option '$1' require an argument (package to show its dependent)" + exit 1 + fi + GLOBAL_PACKAGE_DEPENDENT="$2" + shift + ;; -d|--depends) - if [ ! "$2" ]; then - info "Option '$1' require an argument (package name to show its depends)" - exit 1 - fi - PACKAGE_DEPENDS="$2" - shift + if [ ! "$2" ]; then + msg "Option '$1' require an argument (package name to show its depends)" + exit 1 + fi + PACKAGE_DEPENDS="$2" + shift ;; -pi|--package-info) if [ ! "$2" ] || [ ! "$(echo $2 | grep '.spkg.txz')" ]; then msg "Option '$1' require an argument (package '*.spkg.txz' to show its info)." exit 1 fi - PACKAGE_INFO="$2" + PACKAGE_INFO="$2" shift ;; -co|--check-owner) @@ -368,7 +403,7 @@ parse_options() { msg "Option '$1' require an argument (file name to show its owner)." exit 1 fi - OWNER_FILE_NAME="$2" + OWNER_FILE_NAME="$2" shift ;; -st|--show-tree) @@ -384,7 +419,7 @@ parse_options() { msg "Option '$1' require an argument (package name to search)." exit 1 fi - SEARCH_PKG="$2" + SEARCH_PKG="$2" shift ;; -p|--package) @@ -392,7 +427,7 @@ parse_options() { msg "Option '$1' require an argument (package name to install/build)." exit 1 fi - PORTNAME="$2" + PORTNAME="$2" shift ;; -t|--create-template) @@ -400,7 +435,15 @@ parse_options() { msg "Option '$1' require an argument (port name to create template)." exit 1 fi - TEMPLATE_NAME="$2" + TEMPLATE_NAME="$2" + shift + ;; + --path) + if [ ! "$2" ]; then + msg "Option '$1' require an argument (package name to show its path)" + exit 1 + fi + PORT_PATH="$2" shift ;; *) @@ -426,6 +469,18 @@ main() { loadconfigfile + ### SHOW PORT PATH ### + if [ $PORT_PATH ]; then + showportpath + exit 0 + fi + + ### CAT PORT ### + if [ $CAT_PORT ]; then + catport + exit 0 + fi + ### CREATE PORT TEMPLATE ### if [ $TEMPLATE_NAME ]; then createtemplate