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)"
22 package="" ; inst_root=""
23 d_install="" ; install=""
24 verbose="" ; no_dep=""
30 inst_root="$2" ; package="$3" ; shift 3 ;;
32 inst_root="$2" ; package="$3" ; shift 3 ;;
33 dist-install) d_install="1"
34 inst_root="$2" ; dist_file="$3" ; shift 3 ;;
35 -v) verbose=1 ; shift 1 ;;
36 -a) auto_resolve_deps="1" ; shift 1 ;;
37 -no-dep) no_dep="1" ; shift 1 ;;
42 if [ -z "inst_root" -o -z "$package" ] ; then
46 # read hdw-get configs
47 net_addr="" ; bin_dir="" ; distf_dir=""
48 if [ -f /etc/hdw-get.conf ] ; then
50 if [ -z "$hdw_version" -o -z "$hdw_arch" -o -z "$hdw_arch_opt" ] ; then
51 echo "version, arch and arch_opt need to be specified."
52 echo "adjust /etc/hdw-get.conf file"
55 [ "$verbose" ] && echo "hdw-get.conf file looks good ..."
58 echo "/etc/hdw-get.conf file not found, aborting"
62 # create temp directory
63 mkdir -p /tmp/.hdw-get
66 if [ "$remove" = "1" ] ; then
67 # looking for flist file
69 for fl_file in $inst_root/var/adm/flists/$package-[0-9]*; do
70 fl_pris="`echo $fl_file | awk -F- '{ print $NF }'` $fl_pris"
73 for pri in $fl_pris; do
74 if [ "$pri" = "x" ] ; then
78 [ "$pri" -gt "$fl_max" ] && fl_max=$pri
80 fl_file="$inst_root/var/adm/flists/$package-$fl_max"
81 [ "$verbose" ] && echo "expecting flist file $fl_file"
82 if [ ! -f $fl_file ] ; then
83 echo "package $apckage is not installed (moved the flist file?)"
87 # care about info/dir file
88 rm -f /tmp/.hdw-get/dir* ; modify_info_dir=""
89 if [ -n "`grep usr/share/info/dir $fl_file`" ] ; then
91 cp $inst_root/usr/share/info/dir /tmp/.hdw-get/
92 for info_obj in `grep 'usr/share/info/.*.info' $fl_file | \
93 awk -F/ '{ print $4 }'`; do
94 info_o=`echo $info_obj | sed 's/.info//'`
95 [ "$verbose" ] && echo "deleting $info_o from info/dir"
96 grep -v \($info_o\)\. /tmp/.hdw-get/dir | \
97 grep -v ^$package\ info\ -\ added\ by\ hdw > \
99 mv /tmp/.hdw-get/dir~ /tmp/.hdw-get/dir
103 # remove the files/dirs
106 cat $fl_file | while read pkg file; do
108 if [ -e $inst_root/$file ] ; then
109 if [ "$file" != "tmp" ] ; then
110 if [ -d $inst_root/$file ] ; then
111 rmdir -p $inst_root/$file > /dev/null 2>&1
113 rm -f $inst_root/$file > /dev/null 2>&1
114 rmdir -p `dirname $file` > /dev/null 2>&1
119 echo -en "\rremoved $counter from $supposed supposed files"
123 # reinstall info/dir file
124 if [ "$modify_info_dir" ] ; then
125 [ "$verbose" ] && echo "restoring modified info/dir file"
126 cp /tmp/.hdw-get/dir $inst_root/usr/share/info/dir
127 rm -f /tmp/.hdw-get/dir*
131 elif [ "$install" = "1" ] ; then
132 # does inst_root exist
133 if [ ! -d $inst_root ] ; then
135 echo "the install directory doesnt exist, create it first"
140 # does package exist?
141 pkg=`basename $package | sed 's/.tar.bz2//'`
142 if [ -f $inst_root/var/adm/flists/${pkg}-[0-9]* ] ; then
143 echo "$pkg seems to be installed, candidates:"
144 for i in $inst_root/var/adm/flists/${pkg}-[0-9]*; do
150 # store info/dir file
151 rm -f /tmp/.hdw-get/dir*
152 if [ -f $inst_root/usr/share/info/dir ] ; then
153 [ "$verbose" ] && echo "backing up info/dir file"
154 cp $inst_root/usr/share/info/dir /tmp/.hdw-get/
157 # check/install package
158 if [ -f $package ] ; then
159 echo "extracting `basename $package` to $inst_root ..."
160 tar --use-compress-program=bzip2 -xf $package \
163 elif [ ! -z "$bin_dir" -a -f $bin_dir/${hdw_arch}-${hdw_arch_opt}/$package/$package.tar.bz2 ] ; then
164 echo "extracting $package to $inst_root ..."
165 tar --use-compress-program=bzip2 \
166 -xf $bin_dir/$package/$package.tar.bz2 -C $inst_root
167 elif [ ! -z "$net_addr" ] ; then
168 #echo "trying to get package $package via net ..."
169 wget $net_addr/hdw-linux/hdw-linux-$hdw_version/binaries/${hdw_arch}-${hdw_arch_opt}/$package/${package}.tar.bz2 > /dev/null 2>&1
171 echo "package not found at $net_addr, aborting ..."
174 tar --use-compress-program=bzip2 \
175 -xf ${package}.tar.bz2 -C $inst_root
176 rm ${package}.tar.bz2
180 echo "sorry, package $package not found"
184 # merging info/dir file
185 fl_file=`ls -A $inst_root/var/adm/flists/$pkg-[0-9]* | tail -1`
186 if [ -n "`grep usr/share/info/dir $fl_file`" ] ; then
187 echo "" >> /tmp/.hdw-get/dir
188 echo "$pkg info - added by hdw `date`" >> /tmp/.hdw-get/dir
189 for info_obj in `grep 'usr/share/info/.*.info' $fl_file | \
190 awk -F/ '{ print $4 }'`; do
191 info_o=`echo $info_obj | sed 's/.info//'`
192 if [ -z "`grep \($info_o\)\. /tmp/.hdw-get/dir`" ]
195 echo "merging $info_o to info/dir"
197 $inst_root/usr/share/info/dir >> \
202 cp /tmp/.hdw-get/dir $inst_root/usr/share/info/dir
203 rm -f /tmp/.hdw-get/dir
205 # check for runtime deps
206 #if [ -z $no_deps ] ; then
207 # alldeps=`get_all_deps $pkg`
208 # echo "$pkg depends on the following packages:"
209 # for i in $alldeps; do
212 # echo "continue? [y,n]"
213 # if [ -z $auto_resolve_deps ] ; then
215 # if [ "$answer" = "y" ] ; then
216 # for i in $alldeps; do
217 # $0 -no-dep install $inst_root $pkg
220 # echo -n "install dependencies on your own,"
221 # echo " things will not work without."
227 elif [ "$dist_install" = "1" ] ; then
229 if [ ! -f $dist_file ] ; then
230 echo "$dist_file not found, aborting"
232 # install all distribution related packages
233 for package in `cat $dist_file`; do
235 $0 install $inst_root $package
240 # remove temp directory