Code clean up
- utilize "||" as continuation character, remove unneeded "\" - remove excess empty lines - replace "shift; shift" with "shift 2" - move redirects to end of line - removed several "useless use of cat" - refactored several "awk" statements - replace 'echo ""' with 'echo'
This commit is contained in:
parent
01244a6998
commit
135b3abda5
134
apt-cyg
134
apt-cyg
|
@ -31,8 +31,8 @@ BZIP2=`which bzip2 2> /dev/null`
|
||||||
TAR=`which tar 2> /dev/null`
|
TAR=`which tar 2> /dev/null`
|
||||||
GAWK=`which awk 2> /dev/null`
|
GAWK=`which awk 2> /dev/null`
|
||||||
XZ=`which xz 2> /dev/null`
|
XZ=`which xz 2> /dev/null`
|
||||||
if test "-$WGET-" = "--" || test "-$BZIP2-" = "--" || test "-$TAR-" = "--" \
|
if test "-$WGET-" = "--" || test "-$BZIP2-" = "--" || test "-$TAR-" = "--" ||
|
||||||
|| test "-$GAWK-" = "--" || test "-$XZ-" = "--"
|
test "-$GAWK-" = "--" || test "-$XZ-" = "--"
|
||||||
then
|
then
|
||||||
echo You must install wget, tar, gawk, xz and bzip2 to use apt-cyg.
|
echo You must install wget, tar, gawk, xz and bzip2 to use apt-cyg.
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -58,8 +58,6 @@ function usage()
|
||||||
echo " --version"
|
echo " --version"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function version()
|
function version()
|
||||||
{
|
{
|
||||||
echo "apt-cyg version 0.59"
|
echo "apt-cyg version 0.59"
|
||||||
|
@ -68,7 +66,6 @@ function version()
|
||||||
echo "Copyright (c) 2005-9 Stephen Jungels. Released under the GPL."
|
echo "Copyright (c) 2005-9 Stephen Jungels. Released under the GPL."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function findworkspace()
|
function findworkspace()
|
||||||
{
|
{
|
||||||
# default working directory and mirror
|
# default working directory and mirror
|
||||||
|
@ -95,7 +92,6 @@ function findworkspace()
|
||||||
cd "$cache/$mirrordir"
|
cd "$cache/$mirrordir"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function getsetup()
|
function getsetup()
|
||||||
{
|
{
|
||||||
if test "$noscripts" == "0" -a "$noupdate" == "0"
|
if test "$noscripts" == "0" -a "$noupdate" == "0"
|
||||||
|
@ -121,7 +117,6 @@ function getsetup()
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function checkpackages()
|
function checkpackages()
|
||||||
{
|
{
|
||||||
if test "-$packages-" = "--"
|
if test "-$packages-" = "--"
|
||||||
|
@ -131,7 +126,6 @@ function checkpackages()
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# process options
|
# process options
|
||||||
|
|
||||||
noscripts=0
|
noscripts=0
|
||||||
|
@ -146,14 +140,14 @@ while test $# -gt 0
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
|
|
||||||
--mirror|-m)
|
--mirror | -m)
|
||||||
echo "$2" > /etc/setup/last-mirror
|
echo "$2" > /etc/setup/last-mirror
|
||||||
shift ; shift
|
shift 2
|
||||||
;;
|
;;
|
||||||
|
|
||||||
--cache|-c)
|
--cache | -c)
|
||||||
cygpath -aw "$2" > /etc/setup/last-cache
|
cygpath -aw "$2" > /etc/setup/last-cache
|
||||||
shift ; shift
|
shift 2
|
||||||
;;
|
;;
|
||||||
|
|
||||||
--noscripts)
|
--noscripts)
|
||||||
|
@ -161,7 +155,7 @@ do
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
|
||||||
--noupdate|-u)
|
--noupdate | -u)
|
||||||
noupdate=1
|
noupdate=1
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
@ -176,19 +170,19 @@ do
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
|
|
||||||
--file|-f)
|
--file | -f)
|
||||||
if ! test "-$2-" = "--"
|
if ! test "-$2-" = "--"
|
||||||
then
|
then
|
||||||
file="$2"
|
file="$2"
|
||||||
dofile=1
|
dofile=1
|
||||||
shift
|
shift
|
||||||
else
|
else
|
||||||
echo 1>&2 No file name provided, ignoring $1
|
echo No file name provided, ignoring $1 >&2
|
||||||
fi
|
fi
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
|
||||||
update|show|find|describe|packageof|install|remove)
|
update | show | find | describe | packageof | install | remove)
|
||||||
if test "-$command-" = "--"
|
if test "-$command-" = "--"
|
||||||
then
|
then
|
||||||
command=$1
|
command=$1
|
||||||
|
@ -196,19 +190,16 @@ do
|
||||||
packages="$packages $1"
|
packages="$packages $1"
|
||||||
fi
|
fi
|
||||||
shift
|
shift
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
packages="$packages $1"
|
packages="$packages $1"
|
||||||
shift
|
shift
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
if test $dofile = 1
|
if test $dofile = 1
|
||||||
then
|
then
|
||||||
if test -f "$file"
|
if test -f "$file"
|
||||||
|
@ -220,31 +211,22 @@ then
|
||||||
packages="$packages $filepackages"
|
packages="$packages $filepackages"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
case "$command" in
|
case "$command" in
|
||||||
|
|
||||||
update)
|
update)
|
||||||
|
|
||||||
findworkspace
|
findworkspace
|
||||||
getsetup
|
getsetup
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
|
||||||
show)
|
show)
|
||||||
|
echo The following packages are installed: >&2
|
||||||
echo 1>&2 The following packages are installed:
|
|
||||||
cat /etc/setup/installed.db | awk '/[^ ]+ [^ ]+ 0/ {print $1}'
|
cat /etc/setup/installed.db | awk '/[^ ]+ [^ ]+ 0/ {print $1}'
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
|
||||||
find)
|
find)
|
||||||
|
|
||||||
checkpackages
|
checkpackages
|
||||||
findworkspace
|
findworkspace
|
||||||
getsetup
|
getsetup
|
||||||
|
|
||||||
for pkg in $packages
|
for pkg in $packages
|
||||||
do
|
do
|
||||||
echo ""
|
echo ""
|
||||||
|
@ -252,30 +234,22 @@ case "$command" in
|
||||||
awk '/[^ ]+ [^ ]+ 0/ {if ($1 ~ query) print $1}' query="$pkg" /etc/setup/installed.db
|
awk '/[^ ]+ [^ ]+ 0/ {if ($1 ~ query) print $1}' query="$pkg" /etc/setup/installed.db
|
||||||
echo ""
|
echo ""
|
||||||
echo Searching for installable packages matching $pkg:
|
echo Searching for installable packages matching $pkg:
|
||||||
cat setup.ini | awk -v query="$pkg" \
|
awk '$1 ~ query && $0 = $1' RS='\n\n@ ' FS='\n' query="$pkg" setup.ini
|
||||||
'BEGIN{RS="\n\n@ "; FS="\n"; ORS="\n"} {if ($1 ~ query) {print $1}}'
|
|
||||||
done
|
done
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
|
||||||
describe)
|
describe)
|
||||||
|
|
||||||
checkpackages
|
checkpackages
|
||||||
findworkspace
|
findworkspace
|
||||||
getsetup
|
getsetup
|
||||||
for pkg in $packages
|
for pkg in $packages
|
||||||
do
|
do
|
||||||
echo ""
|
echo
|
||||||
cat setup.ini | awk -v query="$pkg" \
|
awk '$1 ~ query {print $0 "\n"}' RS='\n\n@ ' FS='\n' query="$pkg" setup.ini
|
||||||
'BEGIN{RS="\n\n@ "; FS="\n"; ORS="\n"} {if ($1 ~ query) {print $0 "\n"}}'
|
|
||||||
done
|
done
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
|
||||||
packageof)
|
packageof)
|
||||||
|
|
||||||
checkpackages
|
checkpackages
|
||||||
for pkg in $packages
|
for pkg in $packages
|
||||||
do
|
do
|
||||||
|
@ -294,16 +268,12 @@ case "$command" in
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
|
||||||
install)
|
install)
|
||||||
|
|
||||||
checkpackages
|
checkpackages
|
||||||
findworkspace
|
findworkspace
|
||||||
getsetup
|
getsetup
|
||||||
|
|
||||||
for pkg in $packages
|
for pkg in $packages
|
||||||
do
|
do
|
||||||
|
|
||||||
|
@ -313,16 +283,22 @@ case "$command" in
|
||||||
echo Package $pkg is already installed, skipping
|
echo Package $pkg is already installed, skipping
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
echo ""
|
echo
|
||||||
echo Installing $pkg
|
echo Installing $pkg
|
||||||
|
|
||||||
# look for package and save desc file
|
# look for package and save desc file
|
||||||
|
|
||||||
mkdir -p "release/$pkg"
|
mkdir -p "release/$pkg"
|
||||||
cat setup.ini | awk > "release/$pkg/desc" -v package="$pkg" \
|
awk '
|
||||||
'BEGIN{RS="\n\n@ "; FS="\n"} {if ($1 == package) {desc = $0; px++}} \
|
$1 == package {
|
||||||
END {if (px == 1 && desc != "") print desc; else print "Package not found"}'
|
desc = $0
|
||||||
|
px++
|
||||||
|
}
|
||||||
|
END {
|
||||||
|
if (px == 1 && desc) print desc
|
||||||
|
else print "Package not found"
|
||||||
|
}
|
||||||
|
' RS='\n\n@ ' FS='\n' package="$pkg" setup.ini > "release/$pkg/desc"
|
||||||
desc=`cat "release/$pkg/desc"`
|
desc=`cat "release/$pkg/desc"`
|
||||||
if test "-$desc-" = "-Package not found-"
|
if test "-$desc-" = "-Package not found-"
|
||||||
then
|
then
|
||||||
|
@ -346,7 +322,7 @@ case "$command" in
|
||||||
file=`basename $install`
|
file=`basename $install`
|
||||||
cd "release/$pkg"
|
cd "release/$pkg"
|
||||||
wget -nc $mirror/$install
|
wget -nc $mirror/$install
|
||||||
|
|
||||||
# check the md5
|
# check the md5
|
||||||
digest=`cat "desc" | awk '/^install: / { print $4; exit }'`
|
digest=`cat "desc" | awk '/^install: / { print $4; exit }'`
|
||||||
digactual=`md5sum $file | awk '{print $1}'`
|
digactual=`md5sum $file | awk '{print $1}'`
|
||||||
|
@ -355,32 +331,37 @@ case "$command" in
|
||||||
echo MD5 sum did not match, exiting
|
echo MD5 sum did not match, exiting
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Unpacking..."
|
echo "Unpacking..."
|
||||||
#determine file type
|
# determine file type
|
||||||
if [ "${file##*.}" == "xz" ]; then
|
if [ "${file##*.}" == "xz" ]
|
||||||
cat $file | tar > "/etc/setup/$pkg.lst" xvJf - -C /
|
then
|
||||||
|
cat $file | tar xvJf - -C / > "/etc/setup/$pkg.lst"
|
||||||
else
|
else
|
||||||
cat $file | bunzip2 | tar > "/etc/setup/$pkg.lst" xvf - -C /
|
cat $file | bunzip2 | tar xvf - -C / > "/etc/setup/$pkg.lst"
|
||||||
fi
|
fi
|
||||||
gzip -f "/etc/setup/$pkg.lst"
|
gzip -f "/etc/setup/$pkg.lst"
|
||||||
cd ../..
|
cd ../..
|
||||||
|
|
||||||
|
|
||||||
# update the package database
|
# update the package database
|
||||||
|
|
||||||
cat /etc/setup/installed.db | awk > /tmp/awk.$$ -v pkg="$pkg" -v bz=$file \
|
awk '
|
||||||
'{if (ins != 1 && pkg < $1) {print pkg " " bz " 0"; ins=1}; print $0} \
|
ins != 1 && pkg < $1 {
|
||||||
END{if (ins != 1) print pkg " " bz " 0"}'
|
printf "%s %s 0\n", pkg, bz
|
||||||
|
ins=1
|
||||||
|
}
|
||||||
|
1
|
||||||
|
END {
|
||||||
|
if (ins != 1) printf "%s %s 0\n", pkg, bz
|
||||||
|
}
|
||||||
|
' pkg="$pkg" bz=$file /etc/setup/installed.db > /tmp/awk.$$
|
||||||
mv /etc/setup/installed.db /etc/setup/installed.db-save
|
mv /etc/setup/installed.db /etc/setup/installed.db-save
|
||||||
mv /tmp/awk.$$ /etc/setup/installed.db
|
mv /tmp/awk.$$ /etc/setup/installed.db
|
||||||
|
|
||||||
|
|
||||||
# recursively install required packages
|
# recursively install required packages
|
||||||
|
|
||||||
echo > /tmp/awk.$$ '/^requires: / {s=gensub("(requires: )?([^ ]+) ?", "\\2 ", "g", $0); print s}'
|
echo '/^requires: / {s=gensub("(requires: )?([^ ]+) ?", "\\2 ", "g", $0); print s}' > /tmp/awk.$$
|
||||||
requires=`cat "release/$pkg/desc" | awk -f /tmp/awk.$$`
|
requires=`cat "release/$pkg/desc" | awk -f /tmp/awk.$$`
|
||||||
|
|
||||||
warn=0
|
warn=0
|
||||||
if ! test "-$requires-" = "--"
|
if ! test "-$requires-" = "--"
|
||||||
then
|
then
|
||||||
|
@ -395,16 +376,16 @@ case "$command" in
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
apt-cyg --noscripts install $package
|
apt-cyg --noscripts install $package
|
||||||
if ! test $? = 0 ; then warn=1; fi
|
(( $? )) && warn=1
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
if ! test $warn = 0
|
if ! test $warn = 0
|
||||||
then
|
then
|
||||||
echo "Warning: some required packages did not install, continuing"
|
echo "Warning: some required packages did not install, continuing"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# run all postinstall scripts
|
# run all postinstall scripts
|
||||||
|
|
||||||
pis=`ls /etc/postinstall/*.sh 2>/dev/null | wc -l`
|
pis=`ls /etc/postinstall/*.sh 2>/dev/null | wc -l`
|
||||||
if test $pis -gt 0 && ! test $noscripts -eq 1
|
if test $pis -gt 0 && ! test $noscripts -eq 1
|
||||||
then
|
then
|
||||||
|
@ -415,16 +396,12 @@ case "$command" in
|
||||||
mv $script $script.done
|
mv $script $script.done
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo Package $pkg installed
|
echo Package $pkg installed
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
|
||||||
remove)
|
remove)
|
||||||
|
|
||||||
checkpackages
|
checkpackages
|
||||||
for pkg in $packages
|
for pkg in $packages
|
||||||
do
|
do
|
||||||
|
@ -435,7 +412,6 @@ case "$command" in
|
||||||
echo Package $pkg is not installed, skipping
|
echo Package $pkg is not installed, skipping
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
dontremove="cygwin coreutils gawk bzip2 tar wget bash"
|
dontremove="cygwin coreutils gawk bzip2 tar wget bash"
|
||||||
for req in $dontremove
|
for req in $dontremove
|
||||||
do
|
do
|
||||||
|
@ -445,10 +421,9 @@ case "$command" in
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if ! test -e "/etc/setup/$pkg.lst.gz"
|
if ! test -e "/etc/setup/$pkg.lst.gz"
|
||||||
then
|
then
|
||||||
echo Package manifest missing, cannot remove $pkg. Exiting
|
echo Package manifest missing, cannot remove $pkg. Exiting
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo Removing $pkg
|
echo Removing $pkg
|
||||||
|
@ -460,24 +435,19 @@ case "$command" in
|
||||||
"/etc/preremove/$pkg.sh"
|
"/etc/preremove/$pkg.sh"
|
||||||
rm "/etc/preremove/$pkg.sh"
|
rm "/etc/preremove/$pkg.sh"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cat "/etc/setup/$pkg.lst.gz" | gzip -d | awk '/[^\/]$/ {print "rm -f \"/" $0 "\""}' | sh
|
cat "/etc/setup/$pkg.lst.gz" | gzip -d | awk '/[^\/]$/ {print "rm -f \"/" $0 "\""}' | sh
|
||||||
rm "/etc/setup/$pkg.lst.gz"
|
rm "/etc/setup/$pkg.lst.gz"
|
||||||
rm -f /etc/postinstall/$pkg.sh.done
|
rm -f /etc/postinstall/$pkg.sh.done
|
||||||
cat /etc/setup/installed.db | awk > /tmp/awk.$$ -v pkg="$pkg" '{if (pkg != $1) print $0}'
|
awk '$1 != pkg' pkg="$pkg" /etc/setup/installed.db > /tmp/awk.$$
|
||||||
mv /etc/setup/installed.db /etc/setup/installed.db-save
|
mv /etc/setup/installed.db /etc/setup/installed.db-save
|
||||||
mv /tmp/awk.$$ /etc/setup/installed.db
|
mv /tmp/awk.$$ /etc/setup/installed.db
|
||||||
echo Package $pkg removed
|
echo Package $pkg removed
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
|
|
||||||
usage
|
usage
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue