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 [ ! -f $inst_root/$FL_DIR/$dep-[0-9]* ] && \
198 [ "$pkg" != "$dep" ] && \
201 while [ "$udeps" != "$tudeps" ] ; do
203 for tdep in $tudeps; do
204 deps="`grep "^$tdep\ -" $DBF | sed 's/.* -//'`"
207 [ -f $inst_root/$FL_DIR/$dep-* ] && \
210 [ "$i" = "$dep" ] && exists=1
212 [ "$exists" = "0" ] && \
213 [ "$dep" != "$pkg" ] && \
218 if [ -n "$udeps" ] ; then
219 echo "$pkg has unresolved dependencies:"
222 echo "continue? [y,n] (default 'n')"
223 if [ -z $auto_resolve_deps ] ; then
225 if [ "$answer" = "y" ] ; then
227 [ "$simulate" != "1" ] && \
228 $0 -no-dep install $inst_root $i
235 if [ "$simulate" != "1" -a "$answer" != "n" ] ; then
237 # check/install package
238 if [ -f $package ] ; then
239 echo "extracting `basename $package` to $inst_root ..."
240 tar --use-compress-program=bzip2 -xf $package \
243 elif [ ! -z "$bin_dir" -a -f $bin_dir/${hdw_arch}-${hdw_arch_opt}/$package/$package.tar.bz2 ] ; then
244 echo "extracting $package to $inst_root ..."
245 tar --use-compress-program=bzip2 \
246 -xf $bin_dir/$package/$package.tar.bz2 -C $inst_root
247 elif [ ! -z "$net_addr" ] ; then
248 echo "getting package $package via net ..."
249 wget $net_addr/hdw-linux/hdw-linux-$hdw_version/binaries/${hdw_arch}-${hdw_arch_opt}/$package/${package}.tar.bz2 > /dev/null 2>&1
251 if [ "$retval" != "0" ] ; then
252 echo "package not found at $net_addr, aborting ..."
255 echo "extracting $package to $inst_root ..."
256 tar --use-compress-program=bzip2 \
257 -xf ${package}.tar.bz2 -C $inst_root
258 rm ${package}.tar.bz2
262 echo "sorry, package $package not found"
266 # care about info/dir file
267 echo "recreating info dir file ..."
268 cd $inst_root/usr/share/info
271 install-info $f dir 2>/dev/null
277 elif [ "$d_install" = "1" ] ; then
279 if [ ! -f $dist_file ] ; then
280 echo "$dist_file not found, aborting"
282 # install all distribution related packages
283 for package in `cat $dist_file`; do
286 [ "$auto_resolve_deps" = "1" ] && auto="-a"
287 $0 $auto -b install $inst_root $package