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 > /tmp/.hdw-get/dir~
88 mv /tmp/.hdw-get/dir~ /tmp/.hdw-get/dir
92 # remove the files/dirs
95 cat $fl_file | while read pkg file; do
97 if [ -e $inst_root/$file ] ; then
98 if [ "$file" != "tmp" ] ; then
99 if [ -d $inst_root/$file ] ; then
100 rmdir -p $inst_root/$file > /dev/null 2>&1
102 rm -f $inst_root/$file > /dev/null 2>&1
103 rmdir -p `dirname $file` > /dev/null 2>&1
108 echo -en "\rremoved $counter from $supposed supposed files"
112 # reinstall info/dir file
113 if [ "$modify_info_dir" ] ; then
114 [ "$verbose" ] && echo "restoring modified info/dir file"
115 cp /tmp/.hdw-get/dir $inst_root/usr/share/info/dir
116 rm -f /tmp/.hdw-get/dir*
120 elif [ "$install" = "1" ] ; then
121 # does inst_root exist
122 if [ ! -d $inst_root ] ; then
124 echo "the install directory doesnt exist, create it first"
129 # store info/dir file
130 rm -f /tmp/.hdw-get/dir*
131 if [ -f $inst_root/usr/share/info/dir ] ; then
132 [ "$verbose" ] && echo "backing up info/dir file"
133 cp $inst_root/usr/share/info/dir /tmp/.hdw-get/
136 # check/install package
137 if [ -f $package ] ; then
138 echo "extracting `basename $package` to $inst_root ..."
139 tar --use-compress-program=bzip2 -xf $package \
142 elif [ ! -z "$bin_dir" -a -f $bin_dir/${hdw_arch}-${hdw_arch_opt}/$package/$package.tar.bz2 ] ; then
143 echo "extracting $package to $inst_root ..."
144 tar --use-compress-program=bzip2 \
145 -xf $bin_dir/$package/$package.tar.bz2 -C $inst_root
146 elif [ ! -z "$net_addr" ] ; then
147 #echo "trying to get package $package via net ..."
148 wget $net_addr/hdw-linux/hdw-linux-$hdw_version/binaries/${hdw_arch}-${hdw_arch_opt}/$package/${package}.tar.bz2 > /dev/null 2>&1
150 echo "package not found at $net_addr, aborting ..."
153 tar --use-compress-program=bzip2 \
154 -xf ${package}.tar.bz2 -C $inst_root
155 rm ${package}.tar.bz2
159 echo "sorry, package $package not found"
162 # merging info/dir file
163 fl_file=`ls -A $inst_root/var/adm/flists/$package-[0-9]* | tail -1`
164 if [ -n "`grep usr/share/info/dir $fl_file`" ] ; then
165 echo "" >> /tmp/.hdw-get/dir
166 echo "$package info - added by hdw `date`" >> /tmp/.hdw-get/dir
167 for info_obj in `grep 'usr/share/info/.*.info' $fl_file | \
168 awk -F/ '{ print $4 }'`; do
169 info_o=`echo $info_obj | sed 's/.info//'`
170 if [ -z "`grep \($info_o\)\. /tmp/.hdw-get/dir`" ]
173 echo "merging $info_o to info/dir"
175 $inst_root/usr/share/info/dir >> \
180 cp /tmp/.hdw-get/dir $inst_root/usr/share/info/dir
181 rm -f /tmp/.hdw-get/dir
184 elif [ "$dist_install" = "1" ] ; then
186 if [ ! -f $dist_file ] ; then
187 echo "$dist_file not found, aborting"
189 # install all distribution related packages
190 for package in `cat $dist_file`; do
192 $0 install $inst_root $package
197 # remove temp directory