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]"
17 echo "-v tell me whats going on"
18 echo "-a auto resolve deps, do not prompt user"
19 echo "-no-dep do not care for dependencies (used by hdw-get itself)"
20 echo "-s simulation only, do not install/remove packages"
21 echo "-b base package, not listed in hdw-get.db"
25 package="" ; inst_root=""
27 d_install="" ; install=""
28 verbose="" ; no_dep=""
34 FL_DIR="var/adm/flists"
35 DEPS_DIR="var/adm/deps/run"
36 CONF="/etc/hdw-get.conf"
41 update) update="1" ; package="fake" ; inst_root="fake"
44 inst_root="$2" ; package="$3" ; shift 3 ;;
46 inst_root="$2" ; package="$3" ; shift 3 ;;
47 dist-install) d_install="1" ; package="fake"
48 inst_root="$2" ; dist_file="$3" ; shift 3 ;;
49 -v) verbose=1 ; shift 1 ;;
50 -a) auto_resolve_deps="1" ; shift 1 ;;
51 -no-dep) no_dep="1" ; shift 1 ;;
52 -s) simulate="1" ; shift 1 ;;
53 -b) base="1" ; no_dep="1" ; shift 1;;
58 if [ -z "inst_root" -o -z "$package" ] ; then
62 # read hdw-get configs
63 net_addr="" ; bin_dir="" ; distf_dir=""
64 if [ -f $CONF ] ; then
66 if [ -z "$hdw_version" -o -z "$hdw_arch" -o -z "$hdw_arch_opt" ] ; then
67 echo "version, arch and arch_opt need to be specified."
68 echo "adjust $CONF file"
71 [ "$verbose" ] && echo "hdw-get.conf file looks good ..."
74 echo "$CONF file not found, aborting"
78 if [ "$update" = "1" ] ; then
79 echo -en "updating hdw-get.db file ..."
80 wget -q $net_addr/hdw-linux/hdw-linux-$hdw_version/hdw-get/hdw-get.db \
82 echo -en " done. (`cat $DBF | wc -l` packages)\n"
86 if [ "$remove" = "1" ] ; then
87 # check if packages depend on package to be removed
90 for fl_file in $inst_root/$DEPS_DIR/*; do
91 if [ "`grep "^$package$" $fl_file`" != "" ] ; then
92 pkg=`echo $fl_file | sed "s%$inst_root/$DEPS_DIR/%%"`
93 if [ "$pkg" != "$package" ] ; then
99 if [ "$isdep" != "0" ] ; then
101 echo "run time dependencies were autegenerated by build system."
102 echo "they may be wrong. edit $inst_root/$DEPS_DIR/* files."
105 echo "package $package should not be removed ($isdep deps)"
106 [ "$no_dep" != "1" ] && exit 1
108 # looking for flist file
110 for fl_file in $inst_root/$FL_DIR/$package-[x,0-9]*; do
112 fl_pris="`echo $fl_file | awk -F- '{ print $NF }'` $fl_pris"
115 for pri in $fl_pris; do
116 if [ "$pri" = "x" ] ; then
120 [ "$pri" = "unknown" ] && break
121 [ "$pri" -gt "$fl_max" ] && fl_max=$pri
123 fl_file="$inst_root/$FL_DIR/$package-$fl_max"
124 [ "$verbose" ] && echo "expecting flist file $fl_file"
125 if [ ! -f $fl_file ] ; then
126 echo "package $package is not installed (moved the flist file?)"
130 if [ "$simulate" != "1" ] ; then
132 # remove the files/dirs
135 cat $fl_file | while read pkg file; do
137 if [ -e $inst_root/$file ] ; then
138 if [ "$file" != "tmp" ] ; then
139 if [ -d $inst_root/$file ] ; then
140 rmdir -p $inst_root/$file > /dev/null 2>&1
142 rm -f $inst_root/$file > /dev/null 2>&1
143 rmdir -p `dirname $file` > /dev/null 2>&1
148 #echo -en "\rremoved $counter from $supposed supposed files"
152 # care about info/dir file
153 echo "recreating info dir file ..."
154 cd $inst_root/usr/share/info
157 install-info $f dir 2>/dev/null
163 elif [ "$install" = "1" ] ; then
164 # does inst_root exist
165 if [ ! -d $inst_root ] ; then
167 echo "the install directory doesnt exist, create it first"
172 # does package exist?
173 pkg=`basename $package | sed 's/.tar.bz2//'`
174 if [ -f $inst_root/$FL_DIR/${pkg}-[0-9]* ] ; then
175 echo "$pkg seems to be installed, candidates:"
176 for i in $inst_root/$FL_DIR/${pkg}-[0-9]*; do
182 # package in database?
183 if [ -z $base ] ; then
184 if [ "`grep "^$pkg\ -" $DBF`" = "" ] ; then
185 echo "sorry, package $package not found ..."
186 echo "(use 'hdw-get update' to update database)"
191 # check for runtime deps
192 if [ -z $no_dep ] ; then
193 deps="`grep "^$pkg\ -" $DBF | sed 's/.* -//'`"
197 [ "$dep" != "$pkg" ] &&
198 [ ! -f $inst_root/$FL_DIR/$dep-[0-9]* ] && \
201 while [ "$udeps" != "$tudeps" ] ; do
203 for tdep in $tudeps; do
204 deps="`grep "^$tdep\ -" $DBF | sed 's/.* -//'`"
207 [ "$dep" = "$pkg" ] && break
208 [ -f $inst_root/$FL_DIR/$dep-* ] && \
211 [ "$i" = "$dep" ] && exists=1
213 [ "$exists" = "0" ] && \
218 if [ ".$udeps" != "." ] ; then
219 echo "$pkg uninstalled depends:"
222 echo "continue? [y,n] (default 'n')"
224 if [ "$auto_resolve_deps" != "1" ] ; then
226 if [ "$answer" = "y" ] ; then
228 [ "$simulate" != "1" ] && \
229 $0 -no-dep install $inst_root $i
236 if [ "$simulate" != "1" -a "$answer" = "y" ] ; then
238 # check/install package
239 if [ -f $package ] ; then
240 echo "extracting `basename $package` to $inst_root ..."
241 tar --use-compress-program=bzip2 -xf $package \
244 elif [ ! -z "$bin_dir" -a -f $bin_dir/${hdw_arch}-${hdw_arch_opt}/$package/$package.tar.bz2 ] ; then
245 echo "extracting $package to $inst_root ..."
246 tar --use-compress-program=bzip2 \
247 -xf $bin_dir/$package/$package.tar.bz2 -C $inst_root
248 elif [ ! -z "$net_addr" ] ; then
249 echo "getting package $package via net ..."
250 wget $net_addr/hdw-linux/hdw-linux-$hdw_version/binaries/${hdw_arch}-${hdw_arch_opt}/$package/${package}.tar.bz2 > /dev/null 2>&1
252 if [ "$retval" != "0" ] ; then
253 echo "package not found at $net_addr, aborting ..."
256 echo "extracting $package to $inst_root ..."
257 tar --use-compress-program=bzip2 \
258 -xf ${package}.tar.bz2 -C $inst_root
259 rm ${package}.tar.bz2
263 echo "sorry, package $package not found"
267 # care about info/dir file
268 echo "recreating info dir file ..."
269 cd $inst_root/usr/share/info
272 install-info $f dir 2>/dev/null
278 elif [ "$d_install" = "1" ] ; then
280 if [ ! -f $dist_file ] ; then
281 echo "$dist_file not found, aborting"
283 # install all distribution related packages
284 for package in `cat $dist_file`; do
287 [ "$auto_resolve_deps" = "1" ] && auto="-a"
288 $0 $auto -b install $inst_root $package