From c9e26fb4c4774474171f169d3776ababfd39d29d Mon Sep 17 00:00:00 2001 From: emmett1 Date: Fri, 14 Jun 2019 23:57:48 +0800 Subject: [PATCH] improve scripts --- INSTALL.sh | 3 +-- pkgadd | 22 ++++++++---------- pkgbuild | 21 ++++++++--------- pkgdel | 10 ++++---- pkgdeplist | 6 ++--- pkglibdepends | 8 ++++--- revdep | 53 ++++++++++++++++++++++++------------------- scratch | 63 +++++++++++++++++++++++++-------------------------- 8 files changed, 95 insertions(+), 91 deletions(-) diff --git a/INSTALL.sh b/INSTALL.sh index 10d608a..d3a8418 100755 --- a/INSTALL.sh +++ b/INSTALL.sh @@ -1,9 +1,8 @@ -#!/bin/sh +#!/bin/bash BINDIR=/usr/bin CONFDIR=/etc CACHE_DIR=/var/cache/scratchpkg -INDEX_DIR=/var/lib/scratchpkg PORT_DIR=/usr/ports REVDEPD=/etc/revdep.d REVDEPCONF=/etc/revdep.conf diff --git a/pkgadd b/pkgadd index 76fcf82..dd5feb3 100755 --- a/pkgadd +++ b/pkgadd @@ -91,7 +91,6 @@ parse_opts() { --no-preupgrade) NO_PREUPGRADE=yes ;; --no-postupgrade) NO_POSTUPGRADE=yes ;; --no-backup) NO_BACKUP=yes ;; - --no-color) NOCOLOR=yes ;; --root=*) ROOT="${1#*=}" ;; *.spkg.tar.*) PKGNAME="$(realpath $1)" ;; *) msg "Invalid option! ($1)"; exit 1 ;; @@ -108,7 +107,7 @@ ret() { } isinstalled() { - if [ -s $INDEX_DIR/$1/.pkginfo ] && [[ $(grep $1 $INDEX_DIR/$1/.pkginfo) ]]; then + if [ -s $INDEX_DIR/$1/.pkginfo ] && grep -q $1 $INDEX_DIR/$1/.pkginfo; then return 0 else return 1 @@ -177,9 +176,8 @@ name=${noextname%-*} # get package information if installed if isinstalled $name; then - iname=$(cat $INDEX_DIR/$name/.pkginfo | grep ^name | cut -d " " -f3-) - iversion=$(cat $INDEX_DIR/$name/.pkginfo | grep ^version | cut -d " " -f3-) - irelease=$(cat $INDEX_DIR/$name/.pkginfo | grep ^release | cut -d " " -f3-) + iversion=$(grep ^version $INDEX_DIR/$name/.pkginfo | cut -d " " -f3-) + irelease=$(grep ^release $INDEX_DIR/$name/.pkginfo | cut -d " " -f3-) ALREADYINSTALLED=yes fi @@ -231,7 +229,7 @@ if [ ! "$IGNORE_CONFLICT" ]; then fi if [ -e "$ROOT_DIR/$line" ] || [ -L "$ROOT_DIR/$line" ]; then if [ "$UPGRADE_PKG" ] || [ "$REINSTALL_PKG" ]; then - if [ ! "$(grep -Fx "$line" "$INDEX_DIR/$name/.files")" ]; then + if ! grep -Fx "$line" "$INDEX_DIR/$name/.files"; then echo "$line" conflictedfile=yes fi @@ -240,7 +238,7 @@ if [ ! "$IGNORE_CONFLICT" ]; then conflictedfile=yes fi fi - done < <(cat $TMP_PKGADD | grep -Ev ^.pkg* | grep -v '/$') + done < <(grep -Ev ^.pkg* $TMP_PKGADD | grep -v '/$') if [ "$conflictedfile" = "yes" ]; then msgerr "File conflict found!" @@ -248,7 +246,7 @@ if [ ! "$IGNORE_CONFLICT" ]; then fi fi -if [ $(grep -x .pkginstall $TMP_PKGADD) ]; then +if grep -qx .pkginstall $TMP_PKGADD; then if [ ! "$NO_PREINSTALL" ] && [ ! "$UPGRADE_PKG" ]; then (cd "$ROOT_DIR"/ && sh <(tar -xf "$PKGNAME" .pkginstall -O) pre-install "$version") fi @@ -262,7 +260,7 @@ for i in $(grep ^.pkg* $TMP_PKGADD); do done rm -f $TMP_PKGINSTALL $TMP_PKGINSTALL_BKP -tar --keep-directory-symlink -p -x -v -f $PKGNAME -C "$ROOT_DIR"/ $excludefile | while read line; do +tar --keep-directory-symlink -p -x -v -f $PKGNAME -C "$ROOT_DIR"/ $excludefile | while read -r line; do if [ "$line" = "${line%.*}.spkgnew" ]; then echo "$line" >> $TMP_PKGINSTALL_BKP line=${line%.*} @@ -281,12 +279,12 @@ 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 read line; do + grep -v '/$' $TMP_PKGADD_RMLIST | while read -r line; do [ "$VERBOSE_INSTALL" = yes ] && echo "- $line" rm "$ROOT_DIR/$line" &>/dev/null done - grep '/$' $TMP_PKGADD_RMLIST | tac | while read line; do - if [ ! "$(grep -Rx "$line" "$INDEX_DIR"/*/.files | grep -v "$INDEX_DIR"/$name/.files)" ]; then + grep '/$' $TMP_PKGADD_RMLIST | tac | while read -r line; do + if ! grep -Rx "$line" "$INDEX_DIR"/*/.files | grep -v "$INDEX_DIR"/$name/.files; then [ "$VERBOSE_INSTALL" = yes ] && echo "- $line" rmdir "$ROOT_DIR/$line" &>/dev/null fi diff --git a/pkgbuild b/pkgbuild index 89291a9..068db75 100755 --- a/pkgbuild +++ b/pkgbuild @@ -74,7 +74,7 @@ updatemdsum() { checkmdsum() { - if [ ! -z "$source" -a -z "$md5sum" ]; then + if [ -n "$source" ] && [ -z "$md5sum" ]; then msgerr "md5sum=() is empty, please provide it." abort 1 fi @@ -300,12 +300,12 @@ strip_files() { } compressinfomanpages() { - find . -type f -path "*/man/man*/*" | while read file; do + find . -type f -path "*/man/man*/*" | while read -r file; do if [ "$file" = "${file%%.gz}" ]; then gzip -9 -f "$file" fi done - find . -type l -path "*/man/man*/*" | while read file; do + find . -type l -path "*/man/man*/*" | while read -r file; do FILE="${file%%.gz}.gz" TARGET="$(readlink $file)" TARGET="${TARGET##*/}" @@ -377,7 +377,7 @@ packaging() { bz2) COMPRESS="-j" ;; esac - tar -c $COMPRESS -f $PACKAGE_DIR/$PKGNAME * "${addtotar[@]}" + tar -c $COMPRESS -f $PACKAGE_DIR/$PKGNAME ./* "${addtotar[@]}" if [ $? != 0 ]; then rm -f $PACKAGE_DIR/$PKGNAME msgerr "Packaging '$PKGNAME' failed." @@ -396,7 +396,7 @@ check_buildscript() { if [ -z "$name" ]; then msgerr "'name' is empty!" exit 1 - elif [ "$(basename `pwd`)" != "$name" ]; then + elif [ "$(basename $(pwd))" != "$name" ]; then msgerr "Port name and Directory name is different!" exit 1 elif [ -z "$version" ]; then @@ -405,13 +405,13 @@ check_buildscript() { elif [ -z "$release" ]; then msgerr "'release' is empty!" exit 1 - elif [ "`type -t build`" != "function" ]; then + elif [ "$(type -t build)" != "function" ]; then msgerr "'build' function not exist!" exit 1 - elif $(echo "$version" | grep -q '-'); then + elif echo "$version" | grep -q '-'; then msgerr "'version' should not contain '-'." exit 1 - elif $(echo "$release" | grep -q '-'); then + elif echo "$release" | grep -q '-'; then msgerr "'release' should not contain '-'." exit 1 elif [ -z "$description" ]; then @@ -447,10 +447,10 @@ checkdir() { if [ ! -d $DIR ]; then msgerr "Directory '$DIR' not exist." abort 1 - elif [ ! -w $dir ]; then + elif [ ! -w $DIR ]; then msgerr "Directory '$DIR' not writable." abort 1 - elif [ ! -x $dir ] || [ ! -r $1 ]; then + elif [ ! -x $DIR ] || [ ! -r $1 ]; then msgerr "Directory '$DIR' not readable." abort 1 fi @@ -591,7 +591,6 @@ main() { if [ -f $PKGBUILD_BSCRIPT ]; then 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:]]*//') noextract=$(grep "^# noextract[[:blank:]]*:" $PKGBUILD_BSCRIPT | sed 's/^# noextract[[:blank:]]*:[[:blank:]]*//') source $PKGBUILD_BSCRIPT else diff --git a/pkgdel b/pkgdel index d42c172..d0609e0 100755 --- a/pkgdel +++ b/pkgdel @@ -94,7 +94,7 @@ ret() { } isinstalled() { - if [ -s $INDEX_DIR/$1/.pkginfo ] && [[ $(grep $1 $INDEX_DIR/$1/.pkginfo) ]]; then + if [ -s $INDEX_DIR/$1/.pkginfo ] && grep -q $1 $INDEX_DIR/$1/.pkginfo; then return 0 else return 1 @@ -143,9 +143,9 @@ if [ "$UID" != "0" ]; then ret 1 fi -name=$(cat $INDEX_DIR/$RMNAME/.pkginfo | grep ^name | cut -d " " -f3-) -version=$(cat $INDEX_DIR/$RMNAME/.pkginfo | grep ^version | cut -d " " -f3-) -release=$(cat $INDEX_DIR/$RMNAME/.pkginfo | grep ^release | cut -d " " -f3-) +name=$(grep ^name $INDEX_DIR/$RMNAME/.pkginfo | cut -d " " -f3-) +version=$(grep ^version $INDEX_DIR/$RMNAME/.pkginfo | cut -d " " -f3-) +release=$(grep ^release $INDEX_DIR/$RMNAME/.pkginfo | cut -d " " -f3-) if [ -z $name ] && [ -z $version ] && [ -z $release ]; then msgerr "Package '$RMNAME' not installed but exist in database." @@ -175,7 +175,7 @@ while read -r line; do done < <(tac $INDEX_DIR/$name/.files | grep -v '/$') while read -r line; do - if [ ! "$(grep -Rx "$line" "$INDEX_DIR"/*/.files | grep -v "$INDEX_DIR"/$name/.files)" ]; then + if grep -Rx "$line" "$INDEX_DIR"/*/.files | grep -v "$INDEX_DIR"/$name/.files; then if [ -d "$ROOT_DIR/$line" ]; then [ "$VERBOSE_REMOVE" = yes ] && echo "- $line" rmdir "$ROOT_DIR/$line" diff --git a/pkgdeplist b/pkgdeplist index b02fb76..1de3b2c 100755 --- a/pkgdeplist +++ b/pkgdeplist @@ -57,7 +57,7 @@ checkdep() { getportpath() { for repo in ${PORT_REPO[@]}; do if [[ -f $repo/$1/spkgbuild ]]; then - echo "$(dirname $repo/$1/spkgbuild)" + dirname $repo/$1/spkgbuild return 0 fi done @@ -82,7 +82,7 @@ deplist() { # check dependencies for i in $(checkdep $1); do - [ -e $INDEX_DIR/$i/.pkginfo -a "$QUICK" ] && continue + [ -e $INDEX_DIR/$i/.pkginfo ] && [ "$QUICK" ] && continue if [[ $(echo ${DEP[@]} | tr " " "\n" | grep -x $i) = "" ]]; then deplist $i fi @@ -148,7 +148,7 @@ if [ "${#PKG[@]}" = 0 ]; then exit 1 fi -while read repodir repourl junk; do +while read -r repodir repourl junk; do case $repodir in ""|"#"*) continue ;; esac diff --git a/pkglibdepends b/pkglibdepends index 8b6da14..ce2e96c 100755 --- a/pkglibdepends +++ b/pkglibdepends @@ -53,11 +53,11 @@ pushd / >/dev/null esac libpath=$(ldd "$LINE" | grep -v "not found" | grep -w "$i" | awk '{print $3}') if [ "$libpath" ]; then - FILEPATH=$(readlink -f $(echo $libpath)) - FILENAME=$(echo $FILEPATH | sed -e '1s/^.//') + FILEPATH=$(readlink -f $libpath) + FILENAME=$(sed -e '1s/^.//' $FILEPATH) PKG_NAME=$(basename $(dirname $(grep -Rx $FILENAME $INDEX_DIR | cut -d ':' -f1))) if [ "$PKG_NAME" != $1 ]; then - if [ ! "$(echo "$deppkg" | grep -w "$PKG_NAME")" ]; then + if ! echo "$deppkg" | grep -qw "$PKG_NAME"; then deppkg="$deppkg $PKG_NAME " fi fi @@ -70,3 +70,5 @@ pushd / >/dev/null popd >/dev/null echo $deppkg | tr ' ' '\n' + +exit 0 diff --git a/revdep b/revdep index 1a70860..618e1cb 100755 --- a/revdep +++ b/revdep @@ -138,41 +138,48 @@ if [ "$PKG" ] && [ ! -f "$INDEX_DIR/$PKG/.files" ]; then exit 1 fi -while read line; do - if [[ $(echo ${line::1}) = "/" ]]; then +while read -r line; do + if [[ "${line::1}" = "/" ]]; then EXTRA_SEARCH_DIRS+="$line " fi done < /etc/ld.so.conf if [ -d /etc/ld.so.conf.d/ ]; then - for dir in $(ls /etc/ld.so.conf.d/); do - while read line; do - if [[ $(echo ${line::1}) = "/" ]]; then + for dir in /etc/ld.so.conf.d/*.conf; do + while read -r line; do + if [[ "${line::1}" = "/" ]]; then EXTRA_SEARCH_DIRS+="$line " fi - done < /etc/ld.so.conf.d/$dir + done < $dir done fi # excluded dirs -EXCLUDE_DIR="$(cat /etc/revdep.conf 2>/dev/null | grep -v ^# | grep /$ | sed 's/\/*$//g')" -EXCLUDE_DIR+=" $(cat /etc/revdep.d/*.conf 2>/dev/null | grep -v ^# | grep /$ | sed 's/\/*$//g')" +EXCLUDE_DIRS="$(grep -v ^# /etc/revdep.conf 2>/dev/null | grep /$ | uniq | sed 's/\/*$//g')" +EXCLUDE_DIRS+=" $(grep -v ^# /etc/revdep.d/*.conf 2>/dev/null | cut -d : -f2 | grep /$ | uniq | sed 's/\/*$//g')" -EXCLUDE_DIRS=$(echo $EXCLUDE_DIR | tr ' ' '\n' | sort | uniq) +for dd in $EXCLUDE_DIRS; do + if [ -d $dd ]; then + _DIRS+=" $dd" + fi +done + +EXCLUDE_DIRS=$(echo $_DIRS | tr ' ' '\n' | sort | uniq) for d in $EXCLUDE_DIRS; do EXCLUDED_DIRS+="-path $d -prune -o " done # excluded files -EXCLUDE_FILES="$(cat /etc/revdep.conf 2>/dev/null | grep -v ^# | grep -v /$)" -EXCLUDE_FILES+=" $(cat /etc/revdep.d/*.conf 2>/dev/null | grep -v ^# | grep -v /$)" +EXCLUDE_FILES="$(grep -v ^# /etc/revdep.conf 2>/dev/null | grep -v /$ | grep ^/)" +EXCLUDE_FILES+=" $(grep -v ^# /etc/revdep.d/*.conf 2>/dev/null | cut -d : -f2 | grep -v /$ | grep ^/)" for ff in $EXCLUDE_FILES; do if [ -f $ff ]; then _FILES+=" $ff" fi done + EXCLUDE_FILES=$(echo $_FILES | tr ' ' '\n' | sort | uniq) for f in $EXCLUDE_FILES; do @@ -180,8 +187,8 @@ for f in $EXCLUDE_FILES; do done # excluded libraries -EXCLUDE_LIBS="$(cat /etc/revdep.conf 2>/dev/null | grep -v ^# | grep -v ^/ | grep ".*.so.*")" -EXCLUDE_LIBS+=" $(cat /etc/revdep.d/*.conf 2>/dev/null | grep -v ^# | grep -v ^/ | grep ".*.so.*")" +EXCLUDE_LIBS="$(grep -v ^# /etc/revdep.conf 2>/dev/null | grep -v ^/ | uniq | grep ".*.so.*")" +EXCLUDE_LIBS+=" $(grep -v ^# /etc/revdep.d/*.conf 2>/dev/null | cut -d : -f2 | grep -v ^/ | uniq | grep ".*.so.*")" EXCLUDED_LIBS=$(echo $EXCLUDE_LIBS | tr ' ' '\n' | sort | uniq) @@ -223,13 +230,13 @@ if [ "$PKG" ]; then done gx="$gx -e *\.so -e *\.so\.*" echo -n "Find '$PKG' files... " - cat $INDEX_DIR/$PKG/.files | sed 's/^/\//' | grep $gx > $FILE_LIST + sed 's/^/\//' $INDEX_DIR/$PKG/.files | grep $gx > $FILE_LIST else echo -n "Find all files... " find ${SEARCH_DIRS[@]} $EXCLUDED_DIRS $EXCLUDED_FILES -type f \( -perm /+u+x -o -name '*.so' -o -name '*.so.*' \) -print 2> /dev/null | sort -u > $FILE_LIST fi -total=$(cat $FILE_LIST | wc -l) +total=$(wc -l $FILE_LIST | awk '{print $1}') count=0 echo "$total files found" @@ -237,15 +244,15 @@ echo "$total files found" echo "Checking for broken linkage..." while IFS=' ' read -r line; do - count=$(( $count + 1 )) + count=$(( count + 1 )) libname=$(basename "$line") - echo -ne " $(( 100*$count/$total ))% $libname\033[0K\r" + echo -ne " $(( 100*count/total ))% $libname\033[0K\r" case "$(file -bi "$line")" in *application/x-sharedlib* | *application/x-executable* | *application/x-pie-executable*) - if [ "$(ldd $line 2>/dev/null | grep "not found")" ]; then + if ldd $line 2>/dev/null | grep -q "not found"; then LIB_NAME=$(ldd $line 2>/dev/null | grep "not found" | sort | uniq | awk '{print $1}') for l in $LIB_NAME; do - if [ ! "$(echo $EXCLUDED_LIBS | grep -w $l)" ]; then + if ! echo $EXCLUDED_LIBS | grep -qw $l; then NEW_LIB_NAME+=" $l" fi done @@ -254,15 +261,15 @@ while IFS=' ' read -r line; do line2=$(echo $line | sed 's#^/##') PKG_NAME=$(grep -Rx $line2 "$INDEX_DIR"/*/.files | cut -d : -f1) [[ $PKG_NAME ]] || continue - PKG_NAME=$(dirname $(echo $PKG_NAME)) - PKG_NAME=$(basename $(echo $PKG_NAME)) + PKG_NAME=$(dirname $PKG_NAME) + PKG_NAME=$(basename $PKG_NAME) + echo $expkg | tr ' ' '\n' | grep -qx $PKG_NAME && continue REQ_LIB=$(objdump -p $line 2>/dev/null | grep NEEDED | awk '{print $2}' | tr '\n' ' ') - LIB=$(echo $LIB_NAME | tr '\n' ' ') for i in $LIB_NAME; do [ "$PRINTALL" = 1 ] && echo -e " $PKG_NAME -> $line (requires $i)" if echo $REQ_LIB | tr ' ' '\n' | grep -qx $i; then [ "$PRINTALL" = 1 ] || echo -e " $PKG_NAME -> $line (requires $i)" - if [[ "$(echo ${ALLPKG[@]} | tr ' ' '\n' | grep -x "$PKG_NAME")" ]]; then + if echo "${ALLPKG[@]}" | tr ' ' '\n' | grep -qx "$PKG_NAME"; then continue else ALLPKG+="$PKG_NAME " diff --git a/scratch b/scratch index ac619b8..ec2e819 100755 --- a/scratch +++ b/scratch @@ -63,7 +63,7 @@ needroot() { if [ "$#" -eq 0 ]; then needroot "This operation" else - msgerr "$@ need root access!" + msgerr "$* need root access!" fi exit 1 fi @@ -72,7 +72,7 @@ needroot() { getportpath() { for repo in ${PORT_REPO[@]}; do if [[ -f $repo/$1/$BUILD_SCRIPT ]]; then - echo "$(dirname $repo/$1/$BUILD_SCRIPT)" + dirname $repo/$1/$BUILD_SCRIPT return 0 fi done @@ -99,7 +99,7 @@ vercomp() { installed_pkg_info() { if isinstalled $2; then - echo $(cat $INDEX_DIR/$2/.pkginfo | grep ^$1 | cut -d " " -f3-) + grep ^$1 $INDEX_DIR/$2/.pkginfo | cut -d " " -f3- fi } @@ -127,7 +127,7 @@ checktool() { } needarg() { - if [[ -z "$@" ]]; then + if [ -z "$*" ]; then msgerr "This operation required an arguments!" exit 1 fi @@ -151,7 +151,7 @@ isinstalled() { } settermtitle() { - echo -en "\033]0;$@\a" + echo -en "\033]0;$*\a" } scratch_missingdep() { @@ -335,7 +335,7 @@ scratch_dependent() { if [ $dep = $1 ]; then GDP=yes pname=$(dirname $all) - pname=$(echo ${pname##*/}) + pname=${pname##*/} if isinstalled $pname; then msginst "$pname" else @@ -352,7 +352,7 @@ scratch_dependent() { scratch_own() { local arg - arg=$(echo $1 | sed 's:^/::') + arg=${1/\/} grep -R $arg $INDEX_DIR/*/.files | sed "s:$INDEX_DIR/::" | sed "s:/.files::" | tr : " " | column -t } @@ -428,7 +428,7 @@ scratch_search() { description=$(grep "^# description[[:blank:]]*:" $BUILD_SCRIPT | sed 's/^# description[[:blank:]]*:[[:blank:]]*//') . $BUILD_SCRIPT popd - if [ ! -z "$name" ] && [ ! -z "$version" ] && [ ! -z "$release" ]; then + if [ -n "$name" ] && [ -n "$version" ] && [ -n "$release" ]; then portname=$(basename $port) search_result="${PURPLE}($portname)${CRESET} $name ${CYAN}$version-$release${CRESET} $description" if isinstalled $name; then @@ -466,13 +466,13 @@ scratch_info() { release="-" iver="-" irel="-" - if $(isinstalled $1); then + if isinstalled $1; then iver=$(installed_pkg_info version $1) irel=$(installed_pkg_info release $1) INSTALLED=1 fi portpath=$(getportpath $1) - if [ ! -z $portpath ]; then + if [ -n "$portpath" ]; then . $portpath/$BUILD_SCRIPT PORTEXIST=1 else @@ -489,7 +489,7 @@ scratch_info() { scratch_trigger() { needroot "Run trigger" - if [[ -z "$@" ]]; then + if [ -z "$@" ]; then for i in trig_{1..12}; do eval $i=1 done @@ -857,7 +857,7 @@ scratch_install() { echo pkgcount=0 for pkg in $INST; do - pkgcount=$(( $pkgcount + 1 )) + pkgcount=$(( pkgcount + 1 )) echo -en "[${GREEN}i${CRESET}] $pkg " done echo; echo @@ -871,7 +871,7 @@ scratch_install() { count=0 total=$(echo $INST | wc -w) for int in ${INST[@]}; do - count=$(( $count + 1 )) + count=$(( count + 1 )) portpathh=$(getportpath $int) if [ "$portpathh" ]; then pushd $portpathh @@ -879,7 +879,7 @@ scratch_install() { pkgbuild -i ${OPTS[@]} if [ $? != 0 ]; then error=1 - count=$(( $count - 1 )) + count=$(( count - 1 )) break fi done_pkg+=($int) @@ -953,7 +953,7 @@ scratch_remove() { pkgcount=0 count=0 for pkg in ${IPKG[@]}; do - pkgcount=$(( $pkgcount + 1 )) + pkgcount=$(( pkgcount + 1 )) echo -en "[${RED}x${CRESET}] $pkg " done echo; echo @@ -964,7 +964,7 @@ scratch_remove() { echo fi for pkg in ${IPKG[@]}; do - count=$(( $count + 1 )) + count=$(( count + 1 )) pre_triggers $pkg settermtitle "[ $count/$pkgcount ] Removing $pkg..." pkgdel $pkg ${OPTS[@]} || return 1 @@ -1021,11 +1021,11 @@ scratch_sysup() { if [ "$(echo $PKGOUTDATE | tr ' ' '\n' | grep -x $d)" = "$d" ]; then echo -ne "[${GREEN}u${CRESET}] $d " WILLINSTALL+=($d) - UPGPKG=$(( $UPGPKG + 1 )) + UPGPKG=$(( UPGPKG + 1 )) elif ! isinstalled $d && [ $(getportpath "$d") ]; then echo -ne "[${CYAN}n${CRESET}] $d " WILLINSTALL+=($d) - NEWPKG=$(( $NEWPKG + 1 )) + NEWPKG=$(( NEWPKG + 1 )) fi done else @@ -1033,7 +1033,7 @@ scratch_sysup() { for dd in ${PKGOUTDATE[@]}; do echo -ne "[${GREEN}u${CRESET}] $dd " WILLINSTALL+=($dd) - UPGPKG=$(( $UPGPKG + 1 )) + UPGPKG=$(( UPGPKG + 1 )) done fi echo @@ -1048,14 +1048,14 @@ scratch_sysup() { count=0 total=$(echo ${WILLINSTALL[@]} | wc -w) for inst in ${WILLINSTALL[@]}; do # install all required dependencies and target packages itself - count=$(( $count + 1 )) + count=$(( count + 1 )) pushd $(getportpath $inst) if ! isinstalled $inst; then settermtitle "[ $count/$total ] Installing $inst..." pkgbuild -i ${OPTS[@]} if [ $? != 0 ]; then error=1 - count=$(( $count - 1 )) + count=$(( count - 1 )) break fi else @@ -1063,7 +1063,7 @@ scratch_sysup() { pkgbuild -u ${OPTS[@]} if [ $? != 0 ]; then error=1 - count=$(( $count - 1 )) + count=$(( count - 1 )) break fi fi @@ -1129,11 +1129,11 @@ scratch_upgrade() { echo count=0 for i in ${NEWPKG[@]}; do - count=$(( $count + 1 )) + count=$(( count + 1 )) echo -en "[${CYAN}n${CRESET}] $i " done for i in ${PKGNAME[@]}; do - count=$(( $count + 1 )) + count=$(( count + 1 )) echo -en "[${GREEN}u${CRESET}] $i " done echo @@ -1148,13 +1148,13 @@ scratch_upgrade() { fi if [ ${#NEWPKG[@]} -gt 0 ]; then for newpkg in ${NEWPKG[@]}; do - count=$(( $count + 1 )) + count=$(( count + 1 )) pushd $(getportpath $newpkg) settermtitle "[ $count/$total ] Installing $newpkg..." pkgbuild -i ${OPTS[@]} if [ $? != 0 ]; then error=1 - count=$(( $count - 1 )) + count=$(( count - 1 )) break fi done_pkg+=($newpkg) @@ -1162,13 +1162,13 @@ scratch_upgrade() { done fi for pkg in ${PKGNAME[@]}; do # upgrade all target packages - count=$(( $count + 1 )) + count=$(( count + 1 )) pushd $(getportpath $pkg) settermtitle "[ $count/$total ] Upgrading $pkg..." pkgbuild -u ${OPTS[@]} if [ $? != 0 ]; then error=1 - count=$(( $count - 1 )) + count=$(( count - 1 )) break fi done_pkg+=($pkg) @@ -1251,7 +1251,7 @@ getpkgcache() { for port in $repo/*/$BUILD_SCRIPT; do . $port PORT_PACKAGES+=($name-$version-$release.spkg.tar.$COMPRESSION_MODE) - if [ ! -z $source ]; then + if [ -n "$source" ]; then for src in ${source[@]}; do if [ $(echo $src | grep -E "(ftp|http|https)://") ]; then if [ $(echo $src | grep -E "::(ftp|http|https)://") ]; then @@ -1328,13 +1328,12 @@ scratch_path() { } scratch_dup() { - dup=$(find ${PORT_REPO[@]} -type d -print | egrep -xv "($(echo ${PORT_REPO[@]} | tr ' ' '|'))" | \ + dup=$(find ${PORT_REPO[@]} -type d -print | grep -Exv "($(echo ${PORT_REPO[@]} | tr ' ' '|'))" | \ rev | cut -d '/' -f1 | rev | sort | uniq -d) if [ "$dup" ]; then for dp in $dup; do for repo in ${PORT_REPO[@]}; do - reponame=$(basename $repo) [ -d $repo/$dp ] && echo "$repo/$dp" done done @@ -1512,7 +1511,7 @@ if [ ! -f "$REPO_FILE" ]; then msgerr "repo file not exist. ($REPO_FILE)" exit 1 else - while read repodir repourl junk; do + while read -r repodir repourl junk; do case $repodir in ""|"#"*) continue ;; esac