diff --git a/apt-cyg b/apt-cyg index ca1d323..a501839 100755 --- a/apt-cyg +++ b/apt-cyg @@ -68,19 +68,21 @@ function findworkspace() cache=/setup # work wherever setup worked last, if possible - - if test -e /etc/setup/last-cache + if [ -e /etc/setup/last-cache ] then - tmp="`head -1 /etc/setup/last-cache`" - cache="`cygpath -au "$tmp"`" + tmp=$(/dev/null | sed "s:^/::"` - if test "-$key-" = "--" + key=$(type -P "$pkg" | sed s./..) + if (( ! ${#key} )) then - key="$pkg" + key=$pkg fi for manifest in /etc/setup/*.lst.gz do found=$(gzip -cd $manifest | grep -c "$key") - if test $found -gt 0 + if (( found )) then - package=`echo $manifest | sed -e "s:/etc/setup/::" -e "s/.lst.gz//"` + package=$(sed ' + s,/etc/setup/,, + s,.lst.gz,, + ' <<< $manifest) echo Found $key in the package $package fi done @@ -273,7 +274,7 @@ case "$command" in do already=`grep -c "^$pkg " /etc/setup/installed.db` - if test $already -ge 1 + if (( already )) then echo Package $pkg is already installed, skipping continue @@ -295,7 +296,7 @@ case "$command" in } ' RS='\n\n@ ' FS='\n' package="$pkg" setup.ini > "release/$pkg/desc" desc=$(<"release/$pkg/desc") - if test "-$desc-" = "-Package not found-" + if [[ $desc = 'Package not found' ]] then echo Package $pkg not found or ambiguous name, exiting rm -r "release/$pkg" @@ -308,7 +309,7 @@ case "$command" in # pick the latest version, which comes first install=$(awk '/^install: / {print $2; exit}' "release/$pkg/desc") - if test "-$install-" = "--" + if (( ! ${#install} )) then echo 'Could not find "install" in package description: obsolete package?' exit 1 @@ -321,7 +322,7 @@ case "$command" in # check the md5 digest=$(awk '/^install: / {print $4; exit}' desc) digactual=$(md5sum $file | awk NF=1) - if ! test $digest = $digactual + if [ $digest != $digactual ] then echo MD5 sum did not match, exiting exit 1 @@ -356,31 +357,31 @@ case "$command" in } ' rq='^requires: ' "release/$pkg/desc") warn=0 - if ! test "-$requires-" = "--" + if (( ${#requires} )) then echo Package $pkg requires the following packages, installing: echo $requires for package in $requires do already=`grep -c "^$package " /etc/setup/installed.db` - if test $already -ge 1 + if (( already )) then echo Package $package is already installed, skipping continue fi apt-cyg --noscripts install $package - (( $? )) && warn=1 + (( $? && warn++ )) done fi - if ! test $warn = 0 + if (( warn )) then - echo "Warning: some required packages did not install, continuing" + echo 'Warning: some required packages did not install, continuing' fi # run all postinstall scripts pis=`ls /etc/postinstall/*.sh 2>/dev/null | wc -l` - if test $pis -gt 0 && ! test $noscripts -eq 1 + if (( pis && ! noscripts )) then echo Running postinstall scripts for script in /etc/postinstall/*.sh @@ -400,7 +401,7 @@ case "$command" in do already=`grep -c "^$pkg " /etc/setup/installed.db` - if test $already = 0 + if (( ! already )) then echo Package $pkg is not installed, skipping continue @@ -408,13 +409,13 @@ case "$command" in dontremove="cygwin coreutils gawk bzip2 tar wget bash" for req in $dontremove do - if test "-$pkg-" = "-$req-" + if [[ $pkg = $req ]] then echo apt-cyg cannot remove package $pkg, exiting exit 1 fi done - if ! test -e "/etc/setup/$pkg.lst.gz" + if [ ! -e "/etc/setup/$pkg.lst.gz" ] then echo Package manifest missing, cannot remove $pkg. Exiting exit 1 @@ -423,7 +424,7 @@ case "$command" in # run preremove scripts - if test -e "/etc/preremove/$pkg.sh" + if [ -e "/etc/preremove/$pkg.sh" ] then "/etc/preremove/$pkg.sh" rm "/etc/preremove/$pkg.sh"