3 # author: hackbard@hackdaworld.dyndns.org
6 # this is hdw-get script, used to install/remove/(update) binary packages
12 echo "$0 [install/remove] [root] [package]"
13 echo "$0 [dist-install] [root] [dist file]"
16 echo "-v tell me whats going on"
17 echo "-a auto resolve deps, do not prompt user"
18 echo "-no-dep do not care for dependencies (used by hdw-get itself)"
19 echo "-s simulation only, do not install/remove packages"
23 package="" ; inst_root=""
25 d_install="" ; install=""
26 verbose="" ; no_dep=""
30 FL_DIR="var/adm/flists"
31 DEPS_DIR="var/adm/deps/run"
32 CONF="/etc/hdw-get.conf"
37 update) update="1" ; package="fake" ; inst_root="fake"
40 inst_root="$2" ; package="$3" ; shift 3 ;;
42 inst_root="$2" ; package="$3" ; shift 3 ;;
43 dist-install) d_install="1" ; package="fake"
44 inst_root="$2" ; dist_file="$3" ; shift 3 ;;
45 -v) verbose=1 ; shift 1 ;;
46 -a) auto_resolve_deps="1" ; shift 1 ;;
47 -no-dep) no_dep="1" ; shift 1 ;;
48 -s) simulate="1" ; shift 1 ;;
53 if [ -z "inst_root" -o -z "$package" ] ; then
57 # read hdw-get configs
58 net_addr="" ; bin_dir="" ; distf_dir=""
59 if [ -f $CONF ] ; then
61 if [ -z "$hdw_version" -o -z "$hdw_arch" -o -z "$hdw_arch_opt" ] ; then
62 echo "version, arch and arch_opt need to be specified."
63 echo "adjust $CONF file"
66 [ "$verbose" ] && echo "hdw-get.conf file looks good ..."
69 echo "$CONF file not found, aborting"
73 if [ "$update" = "1" ] ; then
74 echo -en "updating hdw-get.db file ..."
75 wget -q $net_addr/hdw-linux/hdw-linux-$hdw_version/hdw-get/hdw-get.db \
77 echo -en " done. (`cat $DBF | wc -l` packages)\n"
81 if [ "$remove" = "1" ] ; then
82 # check if packages depend on package to be removed
85 for fl_file in $inst_root/$DEPS_DIR/*; do
86 if [ "`grep "^$package$" $fl_file`" != "" ] ; then
87 pkg=`echo $fl_file | sed "s%$inst_root/$DEPS_DIR/%%"`
88 if [ "$pkg" != "$package" ] ; then
94 if [ "$isdep" != "0" ] ; then
96 echo "run time dependencies were autegenerated by build system."
97 echo "they may be wrong. edit $inst_root/$DEPS_DIR/* files."
100 echo "package $package should not be removed ($isdep deps)"
101 [ "$no_dep" != "1" ] && exit 1
103 # looking for flist file
105 for fl_file in $inst_root/$FL_DIR/$package-[x,0-9]*; do
107 fl_pris="`echo $fl_file | awk -F- '{ print $NF }'` $fl_pris"
110 for pri in $fl_pris; do
111 if [ "$pri" = "x" ] ; then
115 [ "$pri" = "unknown" ] && break
116 [ "$pri" -gt "$fl_max" ] && fl_max=$pri
118 fl_file="$inst_root/$FL_DIR/$package-$fl_max"
119 [ "$verbose" ] && echo "expecting flist file $fl_file"
120 if [ ! -f $fl_file ] ; then
121 echo "package $package is not installed (moved the flist file?)"
125 if [ "$simulate" != "1" ] ; then
127 # remove the files/dirs
130 cat $fl_file | while read pkg file; do
132 if [ -e $inst_root/$file ] ; then
133 if [ "$file" != "tmp" ] ; then
134 if [ -d $inst_root/$file ] ; then
135 rmdir -p $inst_root/$file > /dev/null 2>&1
137 rm -f $inst_root/$file > /dev/null 2>&1
138 rmdir -p `dirname $file` > /dev/null 2>&1
143 echo -en "\rremoved $counter from $supposed supposed files"
147 # care about info/dir file
148 echo "recreating info dir file ..."
149 cd $inst_root/usr/share/info
152 install-info $f dir 2>/dev/null
158 elif [ "$install" = "1" ] ; then
159 # does inst_root exist
160 if [ ! -d $inst_root ] ; then
162 echo "the install directory doesnt exist, create it first"
167 # does package exist?
168 pkg=`basename $package | sed 's/.tar.bz2//'`
169 if [ -f $inst_root/$FL_DIR/${pkg}-[0-9]* ] ; then
170 echo "$pkg seems to be installed, candidates:"
171 for i in $inst_root/$FL_DIR/${pkg}-[0-9]*; do
177 # package in database?
178 if [ "`grep "^$pkg\ -" $DBF`" = "" ] ; then
179 echo "sorry, package $package not found ..."
180 echo "(use 'hdw-get update' to update database)"
184 # check for runtime deps
185 if [ -z $no_deps ] ; then
186 deps="`grep "^$pkg\ -" $DBF | sed 's/.* -//'`"
190 [ ! -f $inst_root/$FL_DIR/$dep-* ] && \
193 while [ "$udeps" != "$tudeps" ] ; do
195 for tdep in $tudeps; do
196 deps="`grep "^$tdep\ -" $DBF | sed 's/.* -//'`"
199 [ -f $inst_root/$FL_DIR/$dep-* ] && \
202 [ "$i" = "$dep" ] && exists=1
204 [ "$exists" = "0" ] && \
209 echo "$pkg depends on the following uninstalled packages:"
212 echo "continue? [y,n] (default 'n')"
213 if [ -z $auto_resolve_deps ] ; then
215 if [ "$answer" = "y" ] ; then
217 [ "$simulate" != "1" ] && \
218 $0 -no-dep install $inst_root $i
224 if [ "$simulate" != "1" ] ; then
226 # check/install package
227 if [ -f $package ] ; then
228 echo "extracting `basename $package` to $inst_root ..."
229 tar --use-compress-program=bzip2 -xf $package \
232 elif [ ! -z "$bin_dir" -a -f $bin_dir/${hdw_arch}-${hdw_arch_opt}/$package/$package.tar.bz2 ] ; then
233 echo "extracting $package to $inst_root ..."
234 tar --use-compress-program=bzip2 \
235 -xf $bin_dir/$package/$package.tar.bz2 -C $inst_root
236 elif [ ! -z "$net_addr" ] ; then
237 echo "getting package $package via net ..."
238 wget $net_addr/hdw-linux/hdw-linux-$hdw_version/binaries/${hdw_arch}-${hdw_arch_opt}/$package/${package}.tar.bz2 > /dev/null 2>&1
240 if [ "$retval" != "0" ] ; then
241 echo "package not found at $net_addr, aborting ..."
244 echo "extracting $package to $inst_root ..."
245 tar --use-compress-program=bzip2 \
246 -xf ${package}.tar.bz2 -C $inst_root
247 rm ${package}.tar.bz2
251 echo "sorry, package $package not found"
255 # care about info/dir file
256 echo "recreating info dir file ..."
257 cd $inst_root/usr/share/info
260 install-info $f dir 2>/dev/null
266 elif [ "$d_install" = "1" ] ; then
268 if [ ! -f $dist_file ] ; then
269 echo "$dist_file not found, aborting"
271 # install all distribution related packages
272 for package in `cat $dist_file`; do
274 $0 install $inst_root $package