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"
80 # create temp directory
81 mkdir -p /tmp/.hdw-get
84 if [ "$remove" = "1" ] ; then
85 # check if packages depend on package to be removed
88 for fl_file in $inst_root/$DEPS_DIR/*; do
89 if [ "`grep "^$package$" $fl_file`" != "" ] ; then
90 pkg=`echo $fl_file | sed "s%$inst_root/$DEPS_DIR/%%"`
91 if [ "$pkg" != "$package" ] ; then
97 if [ "$isdep" != "0" ] ; then
99 echo "run time dependencies were autegenerated by build system."
100 echo "they may be wrong. edit $inst_root/$DEPS_DIR/* files."
103 echo "package $package should not be removed ($isdep deps)"
104 [ "$no_dep" != "1" ] && exit 1
106 # looking for flist file
108 for fl_file in $inst_root/$FL_DIR/$package-[x,0-9]*; do
110 fl_pris="`echo $fl_file | awk -F- '{ print $NF }'` $fl_pris"
113 for pri in $fl_pris; do
114 if [ "$pri" = "x" ] ; then
118 [ "$pri" = "unknown" ] && break
119 [ "$pri" -gt "$fl_max" ] && fl_max=$pri
121 fl_file="$inst_root/$FL_DIR/$package-$fl_max"
122 [ "$verbose" ] && echo "expecting flist file $fl_file"
123 if [ ! -f $fl_file ] ; then
124 echo "package $package is not installed (moved the flist file?)"
128 if [ "$simulate" != "1" ] ; then
130 # care about info/dir file
131 rm -f /tmp/.hdw-get/dir* ; modify_info_dir=""
132 if [ -n "`grep usr/share/info/dir $fl_file`" ] ; then
134 cp $inst_root/usr/share/info/dir /tmp/.hdw-get/
135 for info_obj in `grep 'usr/share/info/.*.info' $fl_file | \
136 awk -F/ '{ print $4 }'`; do
137 info_o=`echo $info_obj | sed 's/.info//'`
138 [ "$verbose" ] && echo "deleting $info_o from info/dir"
139 grep -v \($info_o\)\. /tmp/.hdw-get/dir | \
140 grep -v ^$package\ info\ -\ added\ by\ hdw > \
142 mv /tmp/.hdw-get/dir~ /tmp/.hdw-get/dir
146 # remove the files/dirs
149 cat $fl_file | while read pkg file; do
151 if [ -e $inst_root/$file ] ; then
152 if [ "$file" != "tmp" ] ; then
153 if [ -d $inst_root/$file ] ; then
154 rmdir -p $inst_root/$file > /dev/null 2>&1
156 rm -f $inst_root/$file > /dev/null 2>&1
157 rmdir -p `dirname $file` > /dev/null 2>&1
162 echo -en "\rremoved $counter from $supposed supposed files"
166 # reinstall info/dir file
167 if [ "$modify_info_dir" ] ; then
168 [ "$verbose" ] && echo "restoring modified info/dir file"
169 cp /tmp/.hdw-get/dir $inst_root/usr/share/info/dir
170 rm -f /tmp/.hdw-get/dir*
176 elif [ "$install" = "1" ] ; then
177 # does inst_root exist
178 if [ ! -d $inst_root ] ; then
180 echo "the install directory doesnt exist, create it first"
185 # does package exist?
186 pkg=`basename $package | sed 's/.tar.bz2//'`
187 if [ -f $inst_root/$FL_DIR/${pkg}-[0-9]* ] ; then
188 echo "$pkg seems to be installed, candidates:"
189 for i in $inst_root/$FL_DIR/${pkg}-[0-9]*; do
195 # package in database?
196 if [ "`grep "^$pkg\ -" $DBF`" = "" ] ; then
197 echo "sorry, package $package not found ..."
198 echo "(use 'hdw-get update' to update database)"
202 # check for runtime deps
203 if [ -z $no_deps ] ; then
204 deps="`grep "^$pkg\ -" $DBF | sed 's/.* -//'`"
208 [ ! -f $inst_root/$FL_DIR/$dep-* ] && \
211 while [ "$udeps" != "$tudeps" ] ; do
213 for tdep in $tudeps; do
214 deps="`grep "^$tdep\ -" $DBF | sed 's/.* -//'`"
217 [ -f $inst_root/$FL_DIR/$dep-* ] && \
220 [ "$i" = "$dep" ] && exists=1
222 [ "$exists" = "0" ] && \
227 echo "$pkg depends on the following uninstalled packages:"
230 echo "continue? [y,n] (default 'n')"
231 if [ -z $auto_resolve_deps ] ; then
233 if [ "$answer" = "y" ] ; then
235 [ "$simulate" != "1" ] && \
236 $0 -no-dep install $inst_root $i
242 if [ "$simulate" != "1" ] ; then
244 # store info/dir file
245 rm -f /tmp/.hdw-get/dir*
246 if [ -f $inst_root/usr/share/info/dir ] ; then
247 [ "$verbose" ] && echo "backing up info/dir file"
248 cp $inst_root/usr/share/info/dir /tmp/.hdw-get/
251 # check/install package
252 if [ -f $package ] ; then
253 echo "extracting `basename $package` to $inst_root ..."
254 tar --use-compress-program=bzip2 -xf $package \
257 elif [ ! -z "$bin_dir" -a -f $bin_dir/${hdw_arch}-${hdw_arch_opt}/$package/$package.tar.bz2 ] ; then
258 echo "extracting $package to $inst_root ..."
259 tar --use-compress-program=bzip2 \
260 -xf $bin_dir/$package/$package.tar.bz2 -C $inst_root
261 elif [ ! -z "$net_addr" ] ; then
262 echo "getting package $package via net ..."
263 wget $net_addr/hdw-linux/hdw-linux-$hdw_version/binaries/${hdw_arch}-${hdw_arch_opt}/$package/${package}.tar.bz2 > /dev/null 2>&1
265 if [ "$retval" != "0" ] ; then
266 echo "package not found at $net_addr, aborting ..."
269 echo "extracting $package to $inst_root ..."
270 tar --use-compress-program=bzip2 \
271 -xf ${package}.tar.bz2 -C $inst_root
272 rm ${package}.tar.bz2
276 echo "sorry, package $package not found"
280 # merging info/dir file
281 if [ "$pkg" != "00-dirtree" ] ; then
282 fl_file=`ls -A $inst_root/$FL_DIR/$pkg-[0-9]* | tail -1`
283 if [ -n "`grep usr/share/info/dir $fl_file`" ] ; then
284 echo "" >> /tmp/.hdw-get/dir
285 echo "$pkg info - added by hdw `date`" >> /tmp/.hdw-get/dir
286 for info_obj in `grep 'usr/share/info/.*.info' $fl_file | \
287 awk -F/ '{ print $4 }'`; do
288 info_o=`echo $info_obj | sed 's/.info//'`
289 if [ -z "`grep \($info_o\)\. /tmp/.hdw-get/dir`" ]
292 echo "merging $info_o to info/dir"
294 $inst_root/usr/share/info/dir >> \
300 [ -f /tmp/.hdw-get/dir ] && \
301 cp /tmp/.hdw-get/dir $inst_root/usr/share/info/dir
302 rm -f /tmp/.hdw-get/dir
307 elif [ "$d_install" = "1" ] ; then
309 if [ ! -f $dist_file ] ; then
310 echo "$dist_file not found, aborting"
312 # install all distribution related packages
313 for package in `cat $dist_file`; do
315 $0 install $inst_root $package
320 # remove temp directory