2013-07-28 09:12:28 -07:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
# apt-cyg: install tool for cygwin similar to debian apt-get
|
|
|
|
|
|
|
|
|
|
# The MIT License (MIT)
|
|
|
|
|
#
|
|
|
|
|
# Copyright (c) 2013 Trans-code Design
|
|
|
|
|
#
|
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
# in the Software without restriction, including without limitation the rights
|
|
|
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
# furnished to do so, subject to the following conditions:
|
|
|
|
|
#
|
|
|
|
|
# The above copyright notice and this permission notice shall be included in
|
|
|
|
|
# all copies or substantial portions of the Software.
|
|
|
|
|
#
|
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
# THE SOFTWARE.
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
# this script requires some packages
|
2014-03-08 17:01:04 -08:00
|
|
|
|
if ! type awk bzip2 tar wget xz &>/dev/null
|
2013-07-28 09:12:28 -07:00
|
|
|
|
then
|
2013-10-23 03:59:49 -07:00
|
|
|
|
echo You must install wget, tar, gawk, xz and bzip2 to use apt-cyg.
|
2013-07-28 09:12:28 -07:00
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2014-03-08 17:01:04 -08:00
|
|
|
|
[ $HOSTTYPE = x86_64 ] && ARCH=x86_64 || ARCH=x86
|
2013-07-28 09:12:28 -07:00
|
|
|
|
|
|
|
|
|
function usage()
|
|
|
|
|
{
|
|
|
|
|
echo apt-cyg: Installs and removes Cygwin packages.
|
2014-03-06 10:06:25 -08:00
|
|
|
|
echo ' "apt-cyg install <package names>" to install packages'
|
|
|
|
|
echo ' "apt-cyg remove <package names>" to remove packages'
|
|
|
|
|
echo ' "apt-cyg update" to update setup.ini'
|
2014-03-13 22:06:08 -07:00
|
|
|
|
echo ' "apt-cyg list" to list installed packages'
|
2014-03-06 10:06:25 -08:00
|
|
|
|
echo ' "apt-cyg find <patterns>" to find packages matching patterns'
|
|
|
|
|
echo ' "apt-cyg describe <patterns>" to describe packages matching patterns'
|
|
|
|
|
echo ' "apt-cyg packageof <commands or files>" to locate parent packages'
|
2014-03-08 17:01:04 -08:00
|
|
|
|
echo Options:
|
2014-03-06 10:06:25 -08:00
|
|
|
|
echo ' --mirror, -m <url> : set mirror'
|
|
|
|
|
echo ' --cache, -c <dir> : set cache'
|
|
|
|
|
echo ' --file, -f <file> : read package names from file'
|
|
|
|
|
echo ' --noupdate, -u : don’t update setup.ini from mirror'
|
|
|
|
|
echo ' --help'
|
|
|
|
|
echo ' --version'
|
2013-07-28 09:12:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function version()
|
|
|
|
|
{
|
2014-03-08 22:59:40 -08:00
|
|
|
|
echo apt-cyg version 0.59
|
|
|
|
|
echo Written by Stephen Jungels
|
2014-03-06 23:33:21 -08:00
|
|
|
|
echo
|
|
|
|
|
echo 'Copyright (c) 2005-9 Stephen Jungels. Released under the GPL.'
|
2013-07-28 09:12:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function findworkspace()
|
|
|
|
|
{
|
|
|
|
|
# default working directory and mirror
|
2014-02-19 12:26:48 -08:00
|
|
|
|
mirror=http://mirrors.kernel.org/sourceware/cygwin
|
2013-07-28 09:12:28 -07:00
|
|
|
|
cache=/setup
|
|
|
|
|
|
|
|
|
|
# work wherever setup worked last, if possible
|
2014-03-08 21:09:09 -08:00
|
|
|
|
if [ -e /etc/setup/last-cache ]
|
2013-07-28 09:12:28 -07:00
|
|
|
|
then
|
2014-03-08 22:59:40 -08:00
|
|
|
|
cache=$(cygpath -f /etc/setup/last-cache)
|
2013-07-28 09:12:28 -07:00
|
|
|
|
fi
|
2014-03-08 21:09:09 -08:00
|
|
|
|
|
|
|
|
|
if [ -e /etc/setup/last-mirror ]
|
2013-07-28 09:12:28 -07:00
|
|
|
|
then
|
2014-03-08 21:09:09 -08:00
|
|
|
|
mirror=$(</etc/setup/last-mirror)
|
2013-07-28 09:12:28 -07:00
|
|
|
|
fi
|
2014-03-08 21:09:09 -08:00
|
|
|
|
mirrordir=$(sed '
|
|
|
|
|
s / %2f g
|
|
|
|
|
s : %3a g
|
|
|
|
|
' <<< "$mirror")
|
|
|
|
|
|
2013-07-28 09:12:28 -07:00
|
|
|
|
echo Working directory is $cache
|
|
|
|
|
echo Mirror is $mirror
|
|
|
|
|
mkdir -p "$cache/$mirrordir"
|
|
|
|
|
cd "$cache/$mirrordir"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getsetup()
|
|
|
|
|
{
|
2014-03-08 21:09:09 -08:00
|
|
|
|
(( noscripts || noupdate )) && return
|
|
|
|
|
touch setup.ini
|
|
|
|
|
mv setup.ini setup.ini-save
|
|
|
|
|
wget -N $mirror/$ARCH/setup.bz2
|
|
|
|
|
if [ -e setup.bz2 ]
|
2013-07-28 09:12:28 -07:00
|
|
|
|
then
|
2014-03-08 21:09:09 -08:00
|
|
|
|
bunzip2 setup.bz2
|
|
|
|
|
mv setup setup.ini
|
|
|
|
|
echo Updated setup.ini
|
|
|
|
|
else
|
|
|
|
|
wget -N $mirror/$ARCH/setup.ini
|
|
|
|
|
if [ -e setup.ini ]
|
2013-07-28 09:12:28 -07:00
|
|
|
|
then
|
|
|
|
|
echo Updated setup.ini
|
|
|
|
|
else
|
2014-03-08 21:09:09 -08:00
|
|
|
|
mv setup.ini-save setup.ini
|
|
|
|
|
echo Error updating setup.ini, reverting
|
2013-07-28 09:12:28 -07:00
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function checkpackages()
|
|
|
|
|
{
|
2014-03-08 21:09:09 -08:00
|
|
|
|
(( ${#packages} )) && return
|
|
|
|
|
echo Nothing to do, exiting
|
|
|
|
|
exit
|
2013-07-28 09:12:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# process options
|
2014-03-08 22:59:40 -08:00
|
|
|
|
dofile=0
|
2013-07-28 09:12:28 -07:00
|
|
|
|
noscripts=0
|
|
|
|
|
noupdate=0
|
2014-03-08 22:59:40 -08:00
|
|
|
|
command=''
|
|
|
|
|
file=''
|
|
|
|
|
filepackages=''
|
|
|
|
|
packages=''
|
2013-07-28 09:12:28 -07:00
|
|
|
|
|
2014-03-08 21:09:09 -08:00
|
|
|
|
while (( $# ))
|
2013-07-28 09:12:28 -07:00
|
|
|
|
do
|
|
|
|
|
case "$1" in
|
|
|
|
|
|
2014-03-05 23:28:44 -08:00
|
|
|
|
--mirror | -m)
|
2013-07-28 09:12:28 -07:00
|
|
|
|
echo "$2" > /etc/setup/last-mirror
|
2014-03-05 23:28:44 -08:00
|
|
|
|
shift 2
|
2013-07-28 09:12:28 -07:00
|
|
|
|
;;
|
|
|
|
|
|
2014-03-05 23:28:44 -08:00
|
|
|
|
--cache | -c)
|
2013-07-28 09:12:28 -07:00
|
|
|
|
cygpath -aw "$2" > /etc/setup/last-cache
|
2014-03-05 23:28:44 -08:00
|
|
|
|
shift 2
|
2013-07-28 09:12:28 -07:00
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
--noscripts)
|
|
|
|
|
noscripts=1
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
|
2014-03-05 23:28:44 -08:00
|
|
|
|
--noupdate | -u)
|
2013-07-28 09:12:28 -07:00
|
|
|
|
noupdate=1
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
--help)
|
|
|
|
|
usage
|
|
|
|
|
exit 0
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
--version)
|
|
|
|
|
version
|
|
|
|
|
exit 0
|
|
|
|
|
;;
|
|
|
|
|
|
2014-03-05 23:28:44 -08:00
|
|
|
|
--file | -f)
|
2014-03-08 21:09:09 -08:00
|
|
|
|
if (( ${#2} ))
|
2013-07-28 09:12:28 -07:00
|
|
|
|
then
|
2014-03-08 22:59:40 -08:00
|
|
|
|
file=$2
|
2013-07-28 09:12:28 -07:00
|
|
|
|
dofile=1
|
|
|
|
|
shift
|
|
|
|
|
else
|
2014-03-05 23:28:44 -08:00
|
|
|
|
echo No file name provided, ignoring $1 >&2
|
2013-07-28 09:12:28 -07:00
|
|
|
|
fi
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
|
2014-03-13 22:06:08 -07:00
|
|
|
|
update | list | find | describe | packageof | install | remove)
|
2014-03-08 21:09:09 -08:00
|
|
|
|
if (( ${#command} ))
|
2013-07-28 09:12:28 -07:00
|
|
|
|
then
|
2014-03-08 21:09:09 -08:00
|
|
|
|
packages+=" $1"
|
2013-07-28 09:12:28 -07:00
|
|
|
|
else
|
2014-03-08 21:09:09 -08:00
|
|
|
|
command=$1
|
2013-07-28 09:12:28 -07:00
|
|
|
|
fi
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
*)
|
2014-03-08 21:09:09 -08:00
|
|
|
|
packages+=" $1"
|
2013-07-28 09:12:28 -07:00
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
|
2014-03-08 21:09:09 -08:00
|
|
|
|
if (( dofile ))
|
2013-07-28 09:12:28 -07:00
|
|
|
|
then
|
2014-03-08 21:09:09 -08:00
|
|
|
|
if [ -f "$file" ]
|
2013-07-28 09:12:28 -07:00
|
|
|
|
then
|
2014-03-06 10:06:25 -08:00
|
|
|
|
filepackages+=$(awk '{printf " %s", $0}' "$file")
|
2013-07-28 09:12:28 -07:00
|
|
|
|
else
|
|
|
|
|
echo File $file not found, skipping
|
|
|
|
|
fi
|
2014-03-06 10:06:25 -08:00
|
|
|
|
packages+=" $filepackages"
|
2013-07-28 09:12:28 -07:00
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
case "$command" in
|
|
|
|
|
|
|
|
|
|
update)
|
|
|
|
|
findworkspace
|
|
|
|
|
getsetup
|
|
|
|
|
;;
|
|
|
|
|
|
2014-03-13 22:06:08 -07:00
|
|
|
|
list)
|
2014-03-05 23:28:44 -08:00
|
|
|
|
echo The following packages are installed: >&2
|
2014-03-06 10:06:25 -08:00
|
|
|
|
awk 'NR>1 && $0=$1' /etc/setup/installed.db
|
2013-07-28 09:12:28 -07:00
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
find)
|
|
|
|
|
checkpackages
|
|
|
|
|
findworkspace
|
|
|
|
|
getsetup
|
|
|
|
|
for pkg in $packages
|
|
|
|
|
do
|
2014-03-06 10:06:25 -08:00
|
|
|
|
echo
|
2013-07-28 09:12:28 -07:00
|
|
|
|
echo Searching for installed packages matching $pkg:
|
2014-03-06 10:06:25 -08:00
|
|
|
|
awk 'NR>1 && $1~query && $0=$1' query="$pkg" /etc/setup/installed.db
|
|
|
|
|
echo
|
2013-07-28 09:12:28 -07:00
|
|
|
|
echo Searching for installable packages matching $pkg:
|
2014-03-05 23:28:44 -08:00
|
|
|
|
awk '$1 ~ query && $0 = $1' RS='\n\n@ ' FS='\n' query="$pkg" setup.ini
|
2013-07-28 09:12:28 -07:00
|
|
|
|
done
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
describe)
|
|
|
|
|
checkpackages
|
|
|
|
|
findworkspace
|
|
|
|
|
getsetup
|
|
|
|
|
for pkg in $packages
|
|
|
|
|
do
|
2014-03-05 23:28:44 -08:00
|
|
|
|
echo
|
|
|
|
|
awk '$1 ~ query {print $0 "\n"}' RS='\n\n@ ' FS='\n' query="$pkg" setup.ini
|
2013-07-28 09:12:28 -07:00
|
|
|
|
done
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
packageof)
|
|
|
|
|
checkpackages
|
|
|
|
|
for pkg in $packages
|
|
|
|
|
do
|
2014-03-08 21:09:09 -08:00
|
|
|
|
key=$(type -P "$pkg" | sed s./..)
|
2014-03-13 22:06:08 -07:00
|
|
|
|
(( ${#key} )) || key=$pkg
|
2013-07-28 09:12:28 -07:00
|
|
|
|
for manifest in /etc/setup/*.lst.gz
|
|
|
|
|
do
|
2014-03-06 10:06:25 -08:00
|
|
|
|
found=$(gzip -cd $manifest | grep -c "$key")
|
2014-03-08 21:09:09 -08:00
|
|
|
|
if (( found ))
|
2013-07-28 09:12:28 -07:00
|
|
|
|
then
|
2014-03-08 21:09:09 -08:00
|
|
|
|
package=$(sed '
|
|
|
|
|
s,/etc/setup/,,
|
|
|
|
|
s,.lst.gz,,
|
|
|
|
|
' <<< $manifest)
|
2013-07-28 09:12:28 -07:00
|
|
|
|
echo Found $key in the package $package
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
done
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
install)
|
|
|
|
|
checkpackages
|
|
|
|
|
findworkspace
|
|
|
|
|
getsetup
|
|
|
|
|
for pkg in $packages
|
|
|
|
|
do
|
|
|
|
|
|
|
|
|
|
already=`grep -c "^$pkg " /etc/setup/installed.db`
|
2014-03-08 21:09:09 -08:00
|
|
|
|
if (( already ))
|
2013-07-28 09:12:28 -07:00
|
|
|
|
then
|
|
|
|
|
echo Package $pkg is already installed, skipping
|
|
|
|
|
continue
|
|
|
|
|
fi
|
2014-03-05 23:28:44 -08:00
|
|
|
|
echo
|
2013-07-28 09:12:28 -07:00
|
|
|
|
echo Installing $pkg
|
|
|
|
|
|
|
|
|
|
# look for package and save desc file
|
|
|
|
|
|
|
|
|
|
mkdir -p "release/$pkg"
|
2014-03-05 23:28:44 -08:00
|
|
|
|
awk '
|
|
|
|
|
$1 == package {
|
|
|
|
|
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"
|
2014-03-06 23:33:21 -08:00
|
|
|
|
desc=$(<"release/$pkg/desc")
|
2014-03-08 21:09:09 -08:00
|
|
|
|
if [[ $desc = 'Package not found' ]]
|
2013-07-28 09:12:28 -07:00
|
|
|
|
then
|
|
|
|
|
echo Package $pkg not found or ambiguous name, exiting
|
|
|
|
|
rm -r "release/$pkg"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
echo Found package $pkg
|
|
|
|
|
|
2013-10-23 03:59:49 -07:00
|
|
|
|
# download and unpack the bz2 or xz file
|
2013-07-28 09:12:28 -07:00
|
|
|
|
|
|
|
|
|
# pick the latest version, which comes first
|
2014-03-06 23:33:21 -08:00
|
|
|
|
install=$(awk '/^install: / {print $2; exit}' "release/$pkg/desc")
|
2013-07-28 09:12:28 -07:00
|
|
|
|
|
2014-03-08 21:09:09 -08:00
|
|
|
|
if (( ! ${#install} ))
|
2013-07-28 09:12:28 -07:00
|
|
|
|
then
|
2014-03-06 10:06:25 -08:00
|
|
|
|
echo 'Could not find "install" in package description: obsolete package?'
|
2013-07-28 09:12:28 -07:00
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
file=`basename $install`
|
|
|
|
|
cd "release/$pkg"
|
|
|
|
|
wget -nc $mirror/$install
|
2014-03-05 23:28:44 -08:00
|
|
|
|
|
2013-07-28 09:12:28 -07:00
|
|
|
|
# check the md5
|
2014-03-06 23:33:21 -08:00
|
|
|
|
digest=$(awk '/^install: / {print $4; exit}' desc)
|
|
|
|
|
digactual=$(md5sum $file | awk NF=1)
|
2014-03-08 21:09:09 -08:00
|
|
|
|
if [ $digest != $digactual ]
|
2013-07-28 09:12:28 -07:00
|
|
|
|
then
|
|
|
|
|
echo MD5 sum did not match, exiting
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2014-03-05 23:28:44 -08:00
|
|
|
|
|
2013-07-28 09:12:28 -07:00
|
|
|
|
echo "Unpacking..."
|
2014-03-06 23:33:21 -08:00
|
|
|
|
tar xvf $file -C / > "/etc/setup/$pkg.lst"
|
2013-07-28 09:12:28 -07:00
|
|
|
|
gzip -f "/etc/setup/$pkg.lst"
|
|
|
|
|
cd ../..
|
2014-03-05 23:28:44 -08:00
|
|
|
|
|
2013-07-28 09:12:28 -07:00
|
|
|
|
# update the package database
|
2014-03-05 23:28:44 -08:00
|
|
|
|
|
|
|
|
|
awk '
|
|
|
|
|
ins != 1 && pkg < $1 {
|
|
|
|
|
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.$$
|
2013-07-28 09:12:28 -07:00
|
|
|
|
mv /etc/setup/installed.db /etc/setup/installed.db-save
|
|
|
|
|
mv /tmp/awk.$$ /etc/setup/installed.db
|
2014-03-05 23:28:44 -08:00
|
|
|
|
|
2013-07-28 09:12:28 -07:00
|
|
|
|
# recursively install required packages
|
2014-03-05 23:28:44 -08:00
|
|
|
|
|
2014-03-06 23:33:21 -08:00
|
|
|
|
requires=$(awk '
|
|
|
|
|
$0 ~ rq {
|
|
|
|
|
sub(rq, "")
|
|
|
|
|
print
|
|
|
|
|
}
|
|
|
|
|
' rq='^requires: ' "release/$pkg/desc")
|
2013-07-28 09:12:28 -07:00
|
|
|
|
warn=0
|
2014-03-08 21:09:09 -08:00
|
|
|
|
if (( ${#requires} ))
|
2013-07-28 09:12:28 -07:00
|
|
|
|
then
|
|
|
|
|
echo Package $pkg requires the following packages, installing:
|
|
|
|
|
echo $requires
|
|
|
|
|
for package in $requires
|
|
|
|
|
do
|
|
|
|
|
already=`grep -c "^$package " /etc/setup/installed.db`
|
2014-03-08 21:09:09 -08:00
|
|
|
|
if (( already ))
|
2013-07-28 09:12:28 -07:00
|
|
|
|
then
|
|
|
|
|
echo Package $package is already installed, skipping
|
|
|
|
|
continue
|
|
|
|
|
fi
|
|
|
|
|
apt-cyg --noscripts install $package
|
2014-03-08 21:09:09 -08:00
|
|
|
|
(( $? && warn++ ))
|
2013-07-28 09:12:28 -07:00
|
|
|
|
done
|
|
|
|
|
fi
|
2014-03-08 21:09:09 -08:00
|
|
|
|
if (( warn ))
|
2013-07-28 09:12:28 -07:00
|
|
|
|
then
|
2014-03-08 21:09:09 -08:00
|
|
|
|
echo 'Warning: some required packages did not install, continuing'
|
2013-07-28 09:12:28 -07:00
|
|
|
|
fi
|
2014-03-05 23:28:44 -08:00
|
|
|
|
|
2013-07-28 09:12:28 -07:00
|
|
|
|
# run all postinstall scripts
|
2014-03-05 23:28:44 -08:00
|
|
|
|
|
2013-07-28 09:12:28 -07:00
|
|
|
|
pis=`ls /etc/postinstall/*.sh 2>/dev/null | wc -l`
|
2014-03-08 21:09:09 -08:00
|
|
|
|
if (( pis && ! noscripts ))
|
2013-07-28 09:12:28 -07:00
|
|
|
|
then
|
|
|
|
|
echo Running postinstall scripts
|
|
|
|
|
for script in /etc/postinstall/*.sh
|
|
|
|
|
do
|
|
|
|
|
$script
|
|
|
|
|
mv $script $script.done
|
|
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
echo Package $pkg installed
|
|
|
|
|
|
|
|
|
|
done
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
remove)
|
|
|
|
|
checkpackages
|
|
|
|
|
for pkg in $packages
|
|
|
|
|
do
|
|
|
|
|
|
|
|
|
|
already=`grep -c "^$pkg " /etc/setup/installed.db`
|
2014-03-08 21:09:09 -08:00
|
|
|
|
if (( ! already ))
|
2013-07-28 09:12:28 -07:00
|
|
|
|
then
|
|
|
|
|
echo Package $pkg is not installed, skipping
|
|
|
|
|
continue
|
|
|
|
|
fi
|
2014-03-08 22:59:40 -08:00
|
|
|
|
for req in cygwin coreutils gawk bzip2 tar wget bash
|
2013-07-28 09:12:28 -07:00
|
|
|
|
do
|
2014-03-08 21:09:09 -08:00
|
|
|
|
if [[ $pkg = $req ]]
|
2013-07-28 09:12:28 -07:00
|
|
|
|
then
|
|
|
|
|
echo apt-cyg cannot remove package $pkg, exiting
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
done
|
2014-03-08 21:09:09 -08:00
|
|
|
|
if [ ! -e "/etc/setup/$pkg.lst.gz" ]
|
2013-07-28 09:12:28 -07:00
|
|
|
|
then
|
2014-03-05 23:28:44 -08:00
|
|
|
|
echo Package manifest missing, cannot remove $pkg. Exiting
|
2013-07-28 09:12:28 -07:00
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
echo Removing $pkg
|
|
|
|
|
|
|
|
|
|
# run preremove scripts
|
|
|
|
|
|
2014-03-08 21:09:09 -08:00
|
|
|
|
if [ -e "/etc/preremove/$pkg.sh" ]
|
2013-07-28 09:12:28 -07:00
|
|
|
|
then
|
|
|
|
|
"/etc/preremove/$pkg.sh"
|
|
|
|
|
rm "/etc/preremove/$pkg.sh"
|
|
|
|
|
fi
|
2014-03-06 23:33:21 -08:00
|
|
|
|
gzip -cd "/etc/setup/$pkg.lst.gz" |
|
|
|
|
|
awk '/[^\/]$/ {print "rm -f \"/" $0 "\""}' | sh
|
2013-07-28 09:12:28 -07:00
|
|
|
|
rm "/etc/setup/$pkg.lst.gz"
|
|
|
|
|
rm -f /etc/postinstall/$pkg.sh.done
|
2014-03-05 23:28:44 -08:00
|
|
|
|
awk '$1 != pkg' pkg="$pkg" /etc/setup/installed.db > /tmp/awk.$$
|
2013-07-28 09:12:28 -07:00
|
|
|
|
mv /etc/setup/installed.db /etc/setup/installed.db-save
|
|
|
|
|
mv /tmp/awk.$$ /etc/setup/installed.db
|
|
|
|
|
echo Package $pkg removed
|
|
|
|
|
|
|
|
|
|
done
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
*)
|
|
|
|
|
usage
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
esac
|