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=""
33 FL_DIR="var/adm/flists"
34 DEPS_DIR="var/adm/deps/run"
35 CONF="/etc/hdw-get.conf"
40 update) update="1" ; package="fake" ; inst_root="fake"
43 inst_root="$2" ; package="$3" ; shift 3 ;;
45 inst_root="$2" ; package="$3" ; shift 3 ;;
46 dist-install) d_install="1" ; package="fake"
47 inst_root="$2" ; dist_file="$3" ; shift 3 ;;
48 -v) verbose=1 ; shift 1 ;;
49 -a) auto_resolve_deps="1" ; shift 1 ;;
50 -no-dep) no_dep="1" ; shift 1 ;;
51 -s) simulate="1" ; shift 1 ;;
52 -b) base="1" ; no_dep="1" ; shift 1;;
57 if [ -z "inst_root" -o -z "$package" ] ; then
61 # read hdw-get configs
62 net_addr="" ; bin_dir="" ; distf_dir=""
63 if [ -f $CONF ] ; then
65 if [ -z "$hdw_version" -o -z "$hdw_arch" -o -z "$hdw_arch_opt" ] ; then
66 echo "version, arch and arch_opt need to be specified."
67 echo "adjust $CONF file"
70 [ "$verbose" ] && echo "hdw-get.conf file looks good ..."
73 echo "$CONF file not found, aborting"
77 if [ "$update" = "1" ] ; then
78 echo -en "updating hdw-get.db file ..."
79 wget -q $net_addr/hdw-linux/hdw-linux-$hdw_version/hdw-get/hdw-get.db \
81 echo -en " done. (`cat $DBF | wc -l` packages)\n"
85 if [ "$remove" = "1" ] ; then
86 # check if packages depend on package to be removed
89 for fl_file in $inst_root/$DEPS_DIR/*; do
90 if [ "`grep "^$package$" $fl_file`" != "" ] ; then
91 pkg=`echo $fl_file | sed "s%$inst_root/$DEPS_DIR/%%"`
92 if [ "$pkg" != "$package" ] ; then
98 if [ "$isdep" != "0" ] ; then
100 echo "run time dependencies were autegenerated by build system."
101 echo "they may be wrong. edit $inst_root/$DEPS_DIR/* files."
104 echo "package $package should not be removed ($isdep deps)"
105 [ "$no_dep" != "1" ] && exit 1
107 # looking for flist file
109 for fl_file in $inst_root/$FL_DIR/$package-[x,0-9]*; do
111 fl_pris="`echo $fl_file | awk -F- '{ print $NF }'` $fl_pris"
114 for pri in $fl_pris; do
115 if [ "$pri" = "x" ] ; then
119 [ "$pri" = "unknown" ] && break
120 [ "$pri" -gt "$fl_max" ] && fl_max=$pri
122 fl_file="$inst_root/$FL_DIR/$package-$fl_max"
123 [ "$verbose" ] && echo "expecting flist file $fl_file"
124 if [ ! -f $fl_file ] ; then
125 echo "package $package is not installed (moved the flist file?)"
129 if [ "$simulate" != "1" ] ; then
131 # remove the files/dirs
134 cat $fl_file | while read pkg file; do
136 if [ -e $inst_root/$file ] ; then
137 if [ "$file" != "tmp" ] ; then
138 if [ -d $inst_root/$file ] ; then
139 rmdir -p $inst_root/$file > /dev/null 2>&1
141 rm -f $inst_root/$file > /dev/null 2>&1
142 rmdir -p `dirname $file` > /dev/null 2>&1
147 echo -en "\rremoved $counter from $supposed supposed files"
151 # care about info/dir file
152 echo "recreating info dir file ..."
153 cd $inst_root/usr/share/info
156 install-info $f dir 2>/dev/null
162 elif [ "$install" = "1" ] ; then
163 # does inst_root exist
164 if [ ! -d $inst_root ] ; then
166 echo "the install directory doesnt exist, create it first"
171 # does package exist?
172 pkg=`basename $package | sed 's/.tar.bz2//'`
173 if [ -f $inst_root/$FL_DIR/${pkg}-[0-9]* ] ; then
174 echo "$pkg seems to be installed, candidates:"
175 for i in $inst_root/$FL_DIR/${pkg}-[0-9]*; do
181 # package in database?
182 if [ -z $base ] ; then
183 if [ "`grep "^$pkg\ -" $DBF`" = "" ] ; then
184 echo "sorry, package $package not found ..."
185 echo "(use 'hdw-get update' to update database)"
190 # check for runtime deps
191 if [ -z $no_dep ] ; then
192 deps="`grep "^$pkg\ -" $DBF | sed 's/.* -//'`"
196 [ ! -f $inst_root/$FL_DIR/$dep-* ] && \
199 while [ "$udeps" != "$tudeps" ] ; do
201 for tdep in $tudeps; do
202 deps="`grep "^$tdep\ -" $DBF | sed 's/.* -//'`"
205 [ -f $inst_root/$FL_DIR/$dep-* ] && \
208 [ "$i" = "$dep" ] && exists=1
210 [ "$exists" = "0" ] && \
215 echo "$pkg depends on the following uninstalled packages:"
218 echo "continue? [y,n] (default 'n')"
219 if [ -z $auto_resolve_deps ] ; then
221 if [ "$answer" = "y" ] ; then
223 [ "$simulate" != "1" ] && \
224 $0 -no-dep install $inst_root $i
230 if [ "$simulate" != "1" ] ; then
232 # check/install package
233 if [ -f $package ] ; then
234 echo "extracting `basename $package` to $inst_root ..."
235 tar --use-compress-program=bzip2 -xf $package \
238 elif [ ! -z "$bin_dir" -a -f $bin_dir/${hdw_arch}-${hdw_arch_opt}/$package/$package.tar.bz2 ] ; then
239 echo "extracting $package to $inst_root ..."
240 tar --use-compress-program=bzip2 \
241 -xf $bin_dir/$package/$package.tar.bz2 -C $inst_root
242 elif [ ! -z "$net_addr" ] ; then
243 echo "getting package $package via net ..."
244 wget $net_addr/hdw-linux/hdw-linux-$hdw_version/binaries/${hdw_arch}-${hdw_arch_opt}/$package/${package}.tar.bz2 > /dev/null 2>&1
246 if [ "$retval" != "0" ] ; then
247 echo "package not found at $net_addr, aborting ..."
250 echo "extracting $package to $inst_root ..."
251 tar --use-compress-program=bzip2 \
252 -xf ${package}.tar.bz2 -C $inst_root
253 rm ${package}.tar.bz2
257 echo "sorry, package $package not found"
261 # care about info/dir file
262 echo "recreating info dir file ..."
263 cd $inst_root/usr/share/info
266 install-info $f dir 2>/dev/null
272 elif [ "$d_install" = "1" ] ; then
274 if [ ! -f $dist_file ] ; then
275 echo "$dist_file not found, aborting"
277 # install all distribution related packages
278 for package in `cat $dist_file`; do
280 $0 -b install $inst_root $package