Some fixes and cleanup of Fremantle easy-chroot scripts
[easy-deb-chroot] / fremantle / easy-deb-chroot / src / home / user / img-install / debian-installer.sh
1 #!/bin/sh
2
3 ## Ask where the user wishes to install the package with gxmessage:
4
5 export GXMSG=`printf "\
6 Where do you want your Debian image file installed?\n\
7 You need approximately 1.3GB initially.\n\
8 Free space left in internal memory or your memory card:\n\n"; \
9 df -h | grep "mmcblk.p1" | awk '{print $6 ": " $4 " free, " $2 " total (" $5 " full)"}' | sort`
10 gxmessage -center -buttons MyDocs:1,MicroSD:2 -geometry 690x380 -title "Choose Memory Card" "$GXMSG"
11 export SDNO=$?
12
13 case "$SDNO" in
14   1)
15     export SDCARD="/home/user/MyDocs" 
16     ;;
17   *)
18     export SDCARD="/media/mmc1" 
19     ;;
20 esac
21
22 echo "Downloading and extracting to $SDCARD..."
23
24 #exit 0
25
26 ## HERE ARE THE VARIABLES:
27
28 export INSTPATH="/home/user/img-install"
29 export TARPATH="$SDCARD"
30 export DLURL="http://qole.org/files"
31 #This doesn't work:
32 export GZCMD1="tar -xzf"
33
34 export EXTPATH1=$TARPATH
35 export PKGNAME1="EASY DEBIAN IMAGE FILE"
36 export BIGTAR1="debian-m5-v2.img.ext2.bz2"
37 export BIGIMG1="debian-m5-v2.img.ext2"
38 # export BZ2CMD1="bzip2 -d "
39 # export BZ2CMD2=" > $TARPATH/$BIGIMG1"
40 # export BZ2CMD1="cat "
41 # export BZ2CMD2=" | bunzip2 > "
42 # export TARCMD1="cat $TARPATH/$BIGTAR1 | bunzip2 > $TARPATH/$BIGIMG1"
43 export MD51="1c02d35d6453fd35390ae025bd930ba2"
44 export EXTCMD1=""
45
46 #Set SKIPPKG2=1 to skip the second package.
47
48 export SKIPPKG2=1
49 export EXTPATH2=$EXTPATH1
50 export PKGNAME2="SECOND TEST"
51 export BIGTAR2="test2.tgz"
52 export TARCMD2="$GZCMD1 $TARPATH/$BIGTAR2"
53 export MD52="ec3ccde37f4cd026fd03911df7579d6a"
54 export EXTCMD2=""
55
56 #export CLEANUP="sudo rm -r $INSTPATH ; sudo rm /usr/share/applications/image-install.desktop "
57 export CLEANUP="echo All done!"
58
59 ## HERE'S THE SCRIPT:
60
61 # Download first package
62
63 export GOTIT="no"
64
65 if [ -f $TARPATH/$BIGTAR1 ] ; then
66   echo You already have the big image file! 
67   echo   Checking to see if it is good...
68   if [ "`$INSTPATH/md5sum  $TARPATH/$BIGTAR1 | awk '{print $1}'`" = "$MD51" ] ; then 
69     export GOTIT="yes"
70   fi
71 fi
72
73 echo " "
74 echo "Downloading $PKGNAME1 package..."
75
76 export GOOD=1
77 export TEST=2
78
79 while test $TEST != $GOOD 
80 do
81  cd $TARPATH
82  if [ ! "$GOTIT" = "yes" ] ; then
83    wget -c $DLURL/$BIGTAR1
84  fi
85
86  if test -e  $TARPATH/$BIGTAR1
87   then
88
89    cd $INSTPATH
90    export GOOD=$MD51
91    if [ ! "$GOTIT" = "yes" ] ; then
92      echo Testing the file to see if it is good.
93      export TEST=`$INSTPATH/md5sum  $TARPATH/$BIGTAR1 | awk '{print $1}'`
94    else
95      export TEST=$MD51
96    fi
97
98    if test $TEST = $GOOD
99     then
100
101      cd $EXTPATH1
102      echo Extracting the image file. This will take some time.
103
104      # echo $TARCMD1
105      # echo 'cat $TARPATH/$BIGTAR1 | bunzip2 > $TARPATH/$BIGIMG1'
106      # TARERR=`$TARCMD1 2>&1`
107      TARERR="Unknown bzip2 error"
108      # read -p 'press enter' key
109      #$TARCMD1
110      cat $TARPATH/$BIGTAR1 | bunzip2 > $TARPATH/$BIGIMG1
111      if [ "$?" = 0 ] ; then
112          rm -rf $TARPATH/$BIGTAR1
113          $EXTCMD1
114          export MSG1=`printf "CONGRATULATIONS!\n\nAll has gone well!\n\nSuccess installing $PKGNAME1 package!"`
115          gxmessage -center -alignbuttons right -buttons GTK_STOCK_OK:0 -geometry 640x250 -title "SUCCESS!" "$MSG1"
116        else
117          export ERR1=`printf "ERROR! TAR FAILED!\nUnable to install $PKGNAME1\n$TARERR"`
118          gxmessage -center -alignbuttons right -buttons GTK_STOCK_OK:0 -geometry 640x380 -title "TAR ERROR" "$ERR1"
119          exit 99
120       fi        
121     else
122       export ERR1=`printf "$PKGNAME1 package appears damaged.\nPress OK to try downloading again.\nCancel keeps the damaged file."`
123       gxmessage -center -alignbuttons right -buttons GTK_STOCK_OK:0,GTK_STOCK_CANCEL:1 -geometry 640x100 -title "DOWNLOAD ERROR" "$ERR1"
124       if [ "$?" = 1 ] ; then
125         exit 99
126       fi
127       rm $TARPATH/$BIGTAR1
128     fi
129   fi
130 done
131
132 # Stop if only getting one package
133
134 if test $SKIPPKG2 == 1
135  then
136   $CLEANUP
137   exit 0
138 fi
139
140 # Download second package
141
142 echo " "
143 echo "Downloading $PKGNAME2 package..."
144 export GOOD2=1
145 export TEST2=2
146
147 while test $TEST2 != $GOOD2
148 do
149   cd $INSTPATH
150   wget -c $DLURL/$BIGTAR2
151   if test -e  $TARPATH/$BIGTAR2
152    then
153
154     export GOOD2=$MD52
155     export TEST2=`$INSTPATH/md5sum  $TARPATH/$BIGTAR2 | awk '{print $1}'`
156
157     if test $TEST2 = $GOOD2
158      then
159       cd $EXTPATH2
160       TARERR=`$TARCMD2 2>&1`
161       if [ "$?" = 0 ] ; then
162         rm -rf $TARPATH/$BIGTAR2
163         $EXTCMD2
164         export MSG2=`printf "CONGRATULATIONS!\n\nAll has gone well!\n\nSuccess installing $PKGNAME2 package!"`
165         gxmessage -center -alignbuttons right -buttons GTK_STOCK_OK:0 -geometry 640x250 -title "SUCCESS!" "$MSG2"
166       else
167         export ERR2=`printf "ERROR! ERROR! ERROR!\nTAR FAILED!\n\nUnable to install $PKGNAME2\n\n$TARERR"`
168         gxmessage -center -alignbuttons right -buttons GTK_STOCK_OK:0 -geometry 640x250 -title "TAR ERROR" "$ERR2"
169         exit 99
170       fi
171      else
172       echo "$PKGNAME2 package seems damaged, trying again!"
173      fi
174    fi
175 done
176
177 $CLEANUP
178 exit 0