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 package="" ; inst_root=""
17 d_install="" ; install=""
23 inst_root="$2" ; package="$3" ; shift 3 ;;
25 inst_root="$2" ; package="$3" ; shift 3 ;;
26 dist-install) d_install="1"
27 inst_root="$2" ; dist_file="$3" ; shift 3 ;;
28 -v) verbose=1 ; shift 1 ;;
33 if [ -z "inst_root" -o -z "$package" ] ; then
37 # read hdw-get configs
38 net_addr="" ; bin_dir="" ; distf_dir=""
39 if [ -f /etc/hdw-get.conf ] ; then
41 if [ -z "$hdw_version" -o -z "$hdw_arch" -o -z "$hdw_arch_opt" ] ; then
42 echo "version, arch and arch_opt need to be specified."
43 echo "adjust /etc/hdw-get.conf file"
46 echo "hdw-get.conf file looks good ..."
49 echo "/etc/hdw-get.conf file not found, aborting"
53 # create temp directory
54 mkdir -p /tmp/.hdw-get
57 if [ "$remove" = "1" ] ; then
58 # looking for flist file
60 for fl_file in $inst_root/var/adm/flists/$package-[0-9]*; do
61 fl_pris="`echo $fl_file | awk -F- '{ print $NF }'` $fl_pris"
64 for pri in $fl_pris; do
65 if [ "$pri" = "x" ] ; then
69 [ "$pri" -gt "$fl_max" ] && fl_max=$pri
71 fl_file="$inst_root/var/adm/flists/$package-$fl_max"
72 [ "$verbose" ] && echo "expecting flist file $fl_file"
73 if [ ! -f $fl_file ] ; then
74 echo "package $apckage is not installed (moved the flist file?)"
78 # care about info/dir file
79 rm -f /tmp/.hdw-get/dir* ; modify_info_dir=""
80 if [ -n "`grep usr/share/info/dir $fl_file`" ] ; then
82 cp $inst_root/usr/share/info/dir /tmp/.hdw-get/
83 for info_obj in `grep 'usr/share/info/.*.info' $fl_file | \
84 awk -F/ '{ print $4 }'`; do
85 info_o=`echo $info_obj | sed 's/.info//'`
86 [ "$verbose" ] && echo "deleting $info_o from info/dir"
87 grep -v \($info_o\)\. /tmp/.hdw-get/dir | \
88 grep -v ^$package\ info\ -\ added\ by\ hdw > \
90 mv /tmp/.hdw-get/dir~ /tmp/.hdw-get/dir
94 # remove the files/dirs
97 cat $fl_file | while read pkg file; do
99 if [ -e $inst_root/$file ] ; then
100 if [ "$file" != "tmp" ] ; then
101 if [ -d $inst_root/$file ] ; then
102 rmdir -p $inst_root/$file > /dev/null 2>&1
104 rm -f $inst_root/$file > /dev/null 2>&1
105 rmdir -p `dirname $file` > /dev/null 2>&1
110 echo -en "\rremoved $counter from $supposed supposed files"
114 # reinstall info/dir file
115 if [ "$modify_info_dir" ] ; then
116 [ "$verbose" ] && echo "restoring modified info/dir file"
117 cp /tmp/.hdw-get/dir $inst_root/usr/share/info/dir
118 rm -f /tmp/.hdw-get/dir*
122 elif [ "$install" = "1" ] ; then
123 # does inst_root exist
124 if [ ! -d $inst_root ] ; then
126 echo "the install directory doesnt exist, create it first"
131 # store info/dir file
132 rm -f /tmp/.hdw-get/dir*
133 if [ -f $inst_root/usr/share/info/dir ] ; then
134 [ "$verbose" ] && echo "backing up info/dir file"
135 cp $inst_root/usr/share/info/dir /tmp/.hdw-get/
138 # check/install package
139 if [ -f $package ] ; then
140 echo "extracting `basename $package` to $inst_root ..."
141 tar --use-compress-program=bzip2 -xf $package \
144 elif [ ! -z "$bin_dir" -a -f $bin_dir/${hdw_arch}-${hdw_arch_opt}/$package/$package.tar.bz2 ] ; then
145 echo "extracting $package to $inst_root ..."
146 tar --use-compress-program=bzip2 \
147 -xf $bin_dir/$package/$package.tar.bz2 -C $inst_root
148 elif [ ! -z "$net_addr" ] ; then
149 #echo "trying to get package $package via net ..."
150 wget $net_addr/hdw-linux/hdw-linux-$hdw_version/binaries/${hdw_arch}-${hdw_arch_opt}/$package/${package}.tar.bz2 > /dev/null 2>&1
152 echo "package not found at $net_addr, aborting ..."
155 tar --use-compress-program=bzip2 \
156 -xf ${package}.tar.bz2 -C $inst_root
157 rm ${package}.tar.bz2
161 echo "sorry, package $package not found"
164 # merging info/dir file
165 pkg=`basename $package | sed 's/.tar.bz2//'`
166 fl_file=`ls -A $inst_root/var/adm/flists/$pkg-[0-9]* | tail -1`
167 if [ -n "`grep usr/share/info/dir $fl_file`" ] ; then
168 echo "" >> /tmp/.hdw-get/dir
169 echo "$pkg info - added by hdw `date`" >> /tmp/.hdw-get/dir
170 for info_obj in `grep 'usr/share/info/.*.info' $fl_file | \
171 awk -F/ '{ print $4 }'`; do
172 info_o=`echo $info_obj | sed 's/.info//'`
173 if [ -z "`grep \($info_o\)\. /tmp/.hdw-get/dir`" ]
176 echo "merging $info_o to info/dir"
178 $inst_root/usr/share/info/dir >> \
183 cp /tmp/.hdw-get/dir $inst_root/usr/share/info/dir
184 rm -f /tmp/.hdw-get/dir
187 elif [ "$dist_install" = "1" ] ; then
189 if [ ! -f $dist_file ] ; then
190 echo "$dist_file not found, aborting"
192 # install all distribution related packages
193 for package in `cat $dist_file`; do
195 $0 install $inst_root $package
200 # remove temp directory