From daf2d77bb4570a90fba416dc54e854b9bc036567 Mon Sep 17 00:00:00 2001 From: emmett1 Date: Sat, 2 Jun 2018 22:39:08 +0800 Subject: [PATCH] updated --- buildpkg | 18 +++++++++-------- functions/message | 10 +++++----- installpkg | 49 ++++++++++++++++++++--------------------------- removepkg | 22 ++++++++++----------- scratch | 3 +-- 5 files changed, 48 insertions(+), 54 deletions(-) diff --git a/buildpkg b/buildpkg index baaa07f..2c275c6 100755 --- a/buildpkg +++ b/buildpkg @@ -239,7 +239,7 @@ buildpackage() { clearworkdir exitscript1 else - msg "Successfully build ${GREEN}$name-$version-$release${CRESET}." + msg "Build successfully." fi popd @@ -294,7 +294,7 @@ packaging() { [ -n "$depends" ] && for d in ${depends[@]}; do echo "depends = $d" >> .pkginfo; done [ -n "$noextract" ] && echo "noextract = $noextract" >> .pkginfo - msg "Packaging ${GREEN}$name-$version-$release${CRESET}..." + msg2 "Packaging..." for file in .pkginstall .pkgreadme; do if [ -f $file ]; then @@ -304,20 +304,22 @@ packaging() { tar -c -J -p -f $PACKAGE_DIR/$PKGNAME * .pkginfo "${addtotar[@]}" if [ $? != 0 ]; then - msgerr "Packaging ${RED}$PKGNAME${CRESET} failed." + msgerr "Packaging failed." if [ -f $PACKAGE_DIR/$PKGNAME ]; then rm $PACKAGE_DIR/$PKGNAME fi exitscript1 else pkgsize="$(ls -lh $PACKAGE_DIR/$PKGNAME | awk '{print $5}')" - $EXTPROG -t -v -f $PACKAGE_DIR/$PKGNAME - msg "Successfully create package ${GREEN}$PKGNAME${CRESET}. (${pkgsize})" + if [ "$VERBOSE" ]; then + $EXTPROG -t -v -f $PACKAGE_DIR/$PKGNAME + fi + msg "Successfully created package ${GREEN}$PKGNAME${CRESET}. (${pkgsize})" fi case $PREINSTALL_STATUS in - OK) echo -e "preinstall : ${GREEN}OK${CRESET}" ;; - KO) echo -e "preinstall : ${RED}FAIL${CRESET}" ;; + OK) msg2 "preinstall : ${GREEN}OK${CRESET}" ;; + KO) msg2 "preinstall : ${RED}FAIL${CRESET}" ;; esac popd @@ -536,7 +538,7 @@ parse_opts() { -r | --reinstall) REINSTALL_PKG=yes; OPTS+=($1) ;; -d | --no-dep) IGNORE_DEP=yes; OPTS+=($1) ;; -c | --ignore-conflict) OPTS+=($1) ;; - -v | --verbose) OPTS+=($1) ;; + -v | --verbose) VERBOSE=yes; OPTS+=($1) ;; -f | --force-rebuild) FORCE_REBUILD=yes ;; -m | --skip-mdsum) IGNORE_MDSUM=yes ;; -g | --genmdsum) UPDATE_MDSUM=yes ;; diff --git a/functions/message b/functions/message index 249ac42..be3f9a3 100644 --- a/functions/message +++ b/functions/message @@ -1,7 +1,11 @@ #!/bin/bash msg() { - echo -e "${GREEN}==>${CRESET} $1" + echo -e "${GREEN}>>>${CRESET} $1" +} + +msg2() { + echo -e " ${BLUE}*${CRESET} $1" } msginfo() { @@ -16,10 +20,6 @@ msgwarn() { echo -e "${YELLOW}==> WARNING:${CRESET} $1" } -msg2() { - echo -e "${BLUE} ->${CRESET} $1" -} - msg3() { echo -e "$1" } diff --git a/installpkg b/installpkg index 519fe60..281167e 100755 --- a/installpkg +++ b/installpkg @@ -15,12 +15,6 @@ spkglock() { installpkg() { - #ignore dependency check - #if [ ! "$IGNORE_DEP" ]; then - #msg2 "Checking package dependencies..." - # checkdeps - #fi - if [ "$UPGRADE_PKG" ]; then oprmsg=upgrade oprmsg2=Upgrading @@ -32,7 +26,7 @@ installpkg() { oprmsg2=Installing fi - echo -e "$oprmsg2 ${GREEN}$name-$version-$release${CRESET}..." + msg "$oprmsg2 ${GREEN}$name-$version-$release${CRESET}..." # noextract file into system for noextr in ${NO_EXTRACT[@]}; do @@ -41,13 +35,12 @@ installpkg() { #ignore conflict if [ ! "$IGNORE_CONFLICT" ]; then - echo -ne "Checking file conflict...\033[0K\r" + msg2 "Checking file conflict..." if [ "$UPGRADE_PKG" ] || [ "$REINSTALL_PKG" ]; then upcheckconflict else checkconflict fi - #checkpkgconflict fi # create lock file prevent simultaneous install package @@ -56,7 +49,7 @@ installpkg() { # backup conf as set in spkgbuld if upgrade or reinstall package if [ "$UPGRADE_PKG" ] || [ "$REINSTALL_PKG" ]; then if [ ! "$NO_BACKUP" ] && [ -n "$backup" ]; then - echo -ne "Backup ${PURPLE}$bkp${CRESET}...\033[0K\r" + msg2 "Backup configuration file..." backupconf fi fi @@ -68,20 +61,18 @@ installpkg() { # run preinstall script if no --no-preinstall flag and not upgrade package if [ ! "$NO_PREINSTALL" ] && [ ! "$UPGRADE_PKG" ]; then - echo -ne "Running preinstall script...\033[0K\r"; echo -ne "\033[0K" run_preinstall fi # run preupgrade script if package upgrade if [ "$UPGRADE_PKG" ] && [ ! "$NO_PREUPGRADE" ]; then - echo -ne "Running preupgrade script...\033[0K\r"; echo -ne "\033[0K" run_preupgrade fi #installing package into system - echo -ne "Extracting package...\033[0K\r" + msg2 "Extracting package..." if [ "$VERBOSE_INSTALL" ]; then - tar --keep-directory-symlink --no-overwrite-dir -p -x -v -f $PKGNAME -C $ROOT_DIR --exclude=.pkginfo --exclude=.pkginstall --exclude=.pkgreadme ${excludefile[@]} + tar --keep-directory-symlink --no-overwrite-dir -p -x -v -f $PKGNAME -C $ROOT_DIR --exclude=.pkginfo --exclude=.pkginstall --exclude=.pkgreadme ${excludefile[@]} | while read line; do echo -e " + $line"; done else tar --keep-directory-symlink --no-overwrite-dir -p -x -f $PKGNAME -C $ROOT_DIR --exclude=.pkginfo --exclude=.pkginstall --exclude=.pkgreadme ${excludefile[@]} fi @@ -98,51 +89,49 @@ installpkg() { fi if [ "$UPGRADE_PKG" ] || [ "$REINSTALL_PKG" ]; then - echo -ne "Removing old files...\033[0K\r" + msg2 "Removing old files..." removeoldfiles fi registerpkg if [ ! "$NO_POSTINSTALL" ] && [ ! "$UPGRADE_PKG" ]; then - echo -ne "Running postinstall script...\033[0K\r"; echo -ne "\033[0K" run_postinstall fi if [ "$UPGRADE_PKG" ] && [ ! "$NO_POSTUPGRADE" ]; then - echo -ne "Running postupgrade script...\033[0K\r"; echo -ne "\033[0K" run_postupgrade fi restoreconf case $PREINSTALL_STATUS in - OK) echo -e "preinstall : ${GREEN}OK${CRESET}" ;; - KO) echo -e "preinstall : ${RED}FAIL${CRESET}" ;; + OK) msg2 "preinstall : ${GREEN}OK${CRESET}" ;; + KO) msg2 "preinstall : ${RED}FAIL${CRESET}" ;; esac case $PREUPGRADE_STATUS in - OK) echo -e "preupgrade : ${GREEN}OK${CRESET}" ;; - KO) echo -e "preupgrade : ${RED}FAIL${CRESET}" ;; + OK) msg2 "preupgrade : ${GREEN}OK${CRESET}" ;; + KO) msg2 "preupgrade : ${RED}FAIL${CRESET}" ;; esac case $POSTINSTALL_STATUS in - OK) echo -e "postinstall : ${GREEN}OK${CRESET}" ;; - KO) echo -e "postinstall : ${RED}FAIL${CRESET}" ;; + OK) msg2 "postinstall : ${GREEN}OK${CRESET}" ;; + KO) msg2 "postinstall : ${RED}FAIL${CRESET}" ;; esac case $POSTUPGRADE_STATUS in - OK) echo -e "postupgrade : ${GREEN}OK${CRESET}" ;; - KO) echo -e "postupgrade : ${RED}FAIL${CRESET}" ;; + OK) msg2 "postupgrade : ${GREEN}OK${CRESET}" ;; + KO) msg2 "postupgrade : ${RED}FAIL${CRESET}" ;; esac runhooks if [ -f $INDEX_DIR/$name/.pkgreadme ]; then - echo -e "This package has ${GREEN}readme${CRESET}\033[0K\r" + msg2 "This package has ${GREEN}readme${CRESET}\033[0K\r" fi - msg "Successfully $oprmsg ${GREEN}$name-$version-$release${CRESET}." + msg "Successfully $oprmsg." # remove lock file spkglock @@ -305,6 +294,7 @@ checkoutdate() { run_preinstall() { if [ "`type -t pre_install`" = "function" ]; then + msg2 "Running preinstall script..." pre_install "$version" && PREINSTALL_STATUS=OK || PREINSTALL_STATUS=KO fi @@ -313,6 +303,7 @@ run_preinstall() { run_postinstall() { if [ "`type -t post_install`" = "function" ]; then + msg2 "Running postinstall script..." post_install "$version" && POSTINSTALL_STATUS=OK || POSTINSTALL_STATUS=KO fi } @@ -320,6 +311,7 @@ run_postinstall() { run_preupgrade() { if [ "`type -t pre_upgrade`" = "function" ]; then + msg2 "Running preupgrade script..." pre_upgrade "$version" "$iversion" && PREUPGRADE_STATUS=OK || PREUPGRADE_STATUS=KO fi @@ -328,6 +320,7 @@ run_preupgrade() { run_postupgrade() { if [ "`type -t post_upgrade`" = "function" ]; then + msg2 "Running postupgrade script..." post_upgrade "$version" "$iversion" && POSTUPGRADE_STATUS=OK || POSTUPGRADE_STATUS=KO fi @@ -349,7 +342,7 @@ runhooks() { if [ -n "$description" ] && [ -n "$operation" ] && [ -n "$target" ]; then if [ "$(echo $operation | grep -w "$opr" )" ]; then if [ "$(grep -E $target $INDEX_DIR/$name/.files)" ]; then - msg "$description" + echo -e " ${BLUE}*${CRESET} $description" . $hook if [ "`type -t exechook`" = "function" ]; then exechook diff --git a/removepkg b/removepkg index 6e84570..9a05168 100755 --- a/removepkg +++ b/removepkg @@ -19,7 +19,7 @@ removepkg() { ### CHECK DEPENDENCY ### if [ ! "$IGNORE_DEP" ]; then - echo -ne "Checking dependencies...\033[0K\r" + msg2 "Checking dependencies..." checkdeps $1 fi @@ -35,14 +35,14 @@ removepkg() { run_preremove fi - echo -ne "Removing files & dirs...\033[0K\r" + msg2 "Removing files & dirs..." pushd $ROOT_DIR for backup in $ibackup; do [ -f ${backup}.spkgnew ] && rm ${backup}.spkgnew done while IFS=' ' read -r line; do if [ "$VERBOSE_REMOVE" = "yes" ]; then - rm_silent "$line" && echo "$line" || msgwarn "Failed remove $line" + rm_silent "$line" && echo " - $line" || msgwarn "Failed remove $line" else rm_silent "$line" || msgwarn "Failed remove $line" fi @@ -53,7 +53,7 @@ removepkg() { while IFS=' ' read -r line; do if [ ! "$(grep -R --exclude-dir="$1" -w "$line" "$INDEX_DIR")" ]; then if [ "$VERBOSE_REMOVE" = "yes" ]; then - rmdir_silent "$line" && echo "$line" || msgwarn "Failed remove $line" + rmdir_silent "$line" && echo " - $line" || msgwarn "Failed remove $line" else rmdir_silent "$line" || msgwarn "Failed remove $line" fi @@ -76,18 +76,18 @@ removepkg() { fi case $PREREMOVE_STATUS in - OK) echo -e "preremove : ${GREEN}OK${CRESET}" ;; - KO) echo -e "preremove : ${RED}FAIL${CRESET}" ;; + OK) msg2 "preremove : ${GREEN}OK${CRESET}" ;; + KO) msg2 "preremove : ${RED}FAIL${CRESET}" ;; esac case $POSTREMOVE_STATUS in - OK) echo -e "postremove : ${GREEN}OK${CRESET}" ;; - KO) echo -e "postremove : ${RED}FAIL${CRESET}" ;; + OK) msg2 "postremove : ${GREEN}OK${CRESET}" ;; + KO) msg2 "postremove : ${RED}FAIL${CRESET}" ;; esac runremovehooks - msg "Successfully remove ${GREEN}$ipackagename${CRESET}." + msg "Successfully removed." unset -f pre_remove post_remove unset PREREMOVE_STATUS POSTREMOVE_STATUS @@ -99,7 +99,7 @@ removepkg() { run_preremove() { if [ "`type -t pre_remove`" = "function" ]; then - echo -ne "Running preremove script...\033[0K\r"; echo -ne "\033[0K" + msg2 "Running preremove script..." pre_remove "$iversion" && PREREMOVE_STATUS=OK || PREREMOVE_STATUS=KO fi @@ -108,7 +108,7 @@ run_preremove() { run_postremove() { if [ "`type -t post_remove`" = "function" ]; then - echo -ne "Running postremove script...\033[0K\r"; echo -ne "\033[0K\r" + msg2 "Running postremove script..." post_remove "$iversion" && POSTREMOVE_STATUS=OK || POSTREMOVE_STATUS=KO fi diff --git a/scratch b/scratch index 66aad96..9cfa359 100755 --- a/scratch +++ b/scratch @@ -1044,7 +1044,6 @@ if [ "$mode" = "search" ]; then exit 0 fi -# print help message if require mode not met or empty -help +echo "Run '$(basename $0) help' to see available mode and options" exit 0