initial checkin of new hdw-linux development cvs repository
[hdw-linux/hdw-linux.git] / misc / hdw-tools / hdw-get
1 #!/bin/sh
2 #
3 # author: hackbard@hackdaworld.dyndns.org
4 #
5 # hdw-tools: 
6 # this is hdw-get script, used to install/remove/(update) binary packages
7
8
9 usage() {
10         echo
11         echo "usage: $0 [install/remove] [directory] [package]"
12         echo
13 }
14 package="" ; inst_root=""
15 verbose=""
16
17 while [ "$1" ] ; do
18         case "$1" in
19                 install)        install="1" 
20                                 inst_root="$2" ; package="$3" ; shift 3 ;;
21                 remove)         remove="1" 
22                                 inst_root="$2" ; package="$3" ; shift 3 ;;
23                 -v)             verbose=1 ; shift 1 ;;
24                 *)              usage ; exit 1 ;;
25         esac
26 done
27                         
28 if [ -z "inst_root" -o -z "$package" ] ; then
29         usage ; exit 1
30 fi
31         
32 # read hdw-get configs
33 net_addr="" ; bin_dir=""
34 if [ -f /etc/hdw-get.conf ] ; then
35         . /etc/hdw-get.conf
36         if [ -z "$hdw_version" -o -z "$hdw_arch" -o -z "$hdw_arch_opt" ] ; then
37                 echo "version, arch and arch_opt need to be specified."
38                 echo "adjust /etc/hdw-get.conf file"
39                 exit
40         else
41                 echo "hdw-get.conf file looks good ..."
42         fi
43 else
44         echo "/etc/hdw-get.conf file not found, aborting"
45         exit 1
46 fi
47
48 # remove
49 if [ "$remove" = "1" ] ; then
50         # looking for flist file
51         fl_pris=""
52         for fl_file in $inst_root/var/adm/flists/$package-*; do
53                 fl_pris="`echo $fl_file | awk -F- '{ print $NF }'` $fl_pris"
54         done
55         fl_max="0"
56         for pri in $fl_pris; do
57                 if [ "$pri" = "x" ] ; then
58                         fl_max="x"
59                         break
60                 fi
61                 [ "$pri" -gt "$fl_max" ] && fl_max=$pri
62         done
63         fl_file="$inst_root/var/adm/flists/$package-$fl_max"
64         [ "$verbose" ] && echo "expecting flist file $fl_file"
65         if [ ! -f $fl_file ] ; then
66                 echo "package $apckage is not installed (moved the flist file?)"
67                 exit 1
68         fi
69         ((supposed = 0))
70         ((counter = 0))
71         cat $fl_file | while read pkg file; do
72                 ((supposed += 1))
73                 if [ -e $inst_root/$file ] ; then
74                         if [ "$file" != "tmp" ] ; then
75                         if [ -d $inst_root/$file ] ; then
76                                 rmdir -p $inst_root/$file > /dev/null 2>&1
77                         else
78                                 rm -f $inst_root/$file > /dev/null 2>&1
79                                 rmdir -p `dirname $file` > /dev/null 2>&1
80                         fi
81                         ((counter += 1))
82                         fi
83                 fi
84                 echo -en "\rremoved $counter from $supposed supposed files"
85         done
86         echo -en "\ndone.\n"
87
88 # install
89 elif [ "$install" = "1" ] ; then
90         # does inst_root exist
91         if [ ! -d $inst_root ] ; then
92                 echo
93                 echo "the install directory doesnt exist, create it first"
94                 echo
95                 exit 1
96         fi
97         # does the package exist
98         if [ -f $package ] ; then
99                 echo "extracting `basename $package` to $inst_root ..."
100                 tar --use-compress-program=bzip2 -xf $package \
101                         -C $inst_root
102                 echo "done"
103         elif [ ! -z "$bin_dir" -a -f $bin_dir/$package/$package.tar.bz2 ] ; then
104                 echo "extracting $package to $inst_root ..."
105                 tar --use-compress-program=bzip2 \
106                 -xf $bin_dir/$package/$package.tar.bz2 -C $inst_root
107         elif [ ! -z "$net_addr" ] ; then
108                 #echo "trying to get package $package via net ..."
109                 wget $net_addr/hdw-linux/hdw-linux-$hdw_version/binaries/${hdw_arch}-${hdw_arch_opt}/$package/${package}.tar.bz2 &&
110                 tar --use-compress-program=bzip2 \
111                 -xf ${package}.tar.bz2 -C $inst_root
112                 rm ${package}.tar.bz2
113                 echo "done"
114         else
115                 echo "sorry, package $package not found"
116         fi
117 fi
118