bc9021b317ea635cfeeed3c0ecd9cdeb899c8265
[easy-deb-chroot] / fremantle / easy-deb-chroot / .py2deb_build_folder / easy-deb-chroot / src / home / user / img-install / debian-installer.sh
1 #!/bin/sh
2
3 ## New! 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 export BZ2CMD1="bzip2 -d "
32 export BZ2CMD2="$TARPATH"
33 #This doesn't work:
34 #export BZ2CMD1="bzcat"
35 #export BZ2CMD2="| tar xf -"
36 export GZCMD1="tar -xzf"
37
38 export EXTPATH1=$TARPATH
39 export PKGNAME1="EASY DEBIAN IMAGE FILE"
40 export BIGTAR1="debian-squeeze-m5-img.bz2"
41 export TARCMD1="$BZ2CMD1 $TARPATH/$BIGTAR1 $BZ2CMD2"
42 export MD51="f769bb84c99f75821bdfa37e5ea34e86"
43 export EXTCMD1=""
44
45 #Set SKIPPKG2=1 to skip the second package.
46
47 export SKIPPKG2=1
48 export EXTPATH2=$EXTPATH1
49 export PKGNAME2="SECOND TEST"
50 export BIGTAR2="test2.tgz"
51 export TARCMD2="$GZCMD1 $TARPATH/$BIGTAR2"
52 export MD52="ec3ccde37f4cd026fd03911df7579d6a"
53 export EXTCMD2=""
54
55 #export CLEANUP="sudo rm -r $INSTPATH ; sudo rm /usr/share/applications/image-install.desktop "
56 export CLEANUP="echo All done!"
57
58 ## HERE'S THE SCRIPT:
59
60 # Download first package
61
62 export GOTIT="no"
63
64 if [ -f $TARPATH/$BIGTAR1 ] ; then
65   echo You already have the big image file! 
66   echo   Checking to see if it is good...
67   if [ "`$INSTPATH/md5sum  $TARPATH/$BIGTAR1 | awk '{print $1}'`" = "$MD51" ] ; then 
68     export GOTIT="yes"
69   fi
70 fi
71
72 echo " "
73 echo "Downloading $PKGNAME1 package..."
74
75 export GOOD=1
76 export TEST=2
77
78 while test $TEST != $GOOD 
79 do
80  cd $TARPATH
81  if [ ! "$GOTIT" = "yes" ] ; then
82    wget -c $DLURL/$BIGTAR1
83  fi
84
85  if test -e  $TARPATH/$BIGTAR1
86   then
87
88    cd $INSTPATH
89    export GOOD=$MD51
90    if [ ! "$GOTIT" = "yes" ] ; then
91      echo Testing the file to see if it is good.
92      export TEST=`$INSTPATH/md5sum  $TARPATH/$BIGTAR1 | awk '{print $1}'`
93    else
94      export TEST=$MD51
95    fi
96
97    if test $TEST = $GOOD
98     then
99
100      cd $EXTPATH1
101      echo Extracting the image file. This will take some time.
102      TARERR=`$TARCMD1 2>&1`
103      if [ "$?" = 0 ] ; then
104          rm -rf $TARPATH/$BIGTAR1
105          $EXTCMD1
106          export MSG1=`printf "CONGRATULATIONS!\n\nAll has gone well!\n\nSuccess installing $PKGNAME1 package!"`
107          gxmessage -center -alignbuttons right -buttons GTK_STOCK_OK:0 -geometry 640x250 -title "SUCCESS!" "$MSG1"
108        else
109          export ERR1=`printf "ERROR! TAR FAILED!\nUnable to install $PKGNAME1\n$TARERR"`
110          gxmessage -center -alignbuttons right -buttons GTK_STOCK_OK:0 -geometry 640x380 -title "TAR ERROR" "$ERR1"
111          exit 99
112       fi        
113     else
114       export ERR1=`printf "$PKGNAME1 package appears damaged.\nPress OK to try downloading again.\nCancel keeps the damaged file."`
115       gxmessage -center -alignbuttons right -buttons GTK_STOCK_OK:0,GTK_STOCK_CANCEL:1 -geometry 640x100 -title "DOWNLOAD ERROR" "$ERR1"
116       if [ "$?" = 1 ] ; then
117         exit 99
118       fi
119       rm $TARPATH/$BIGTAR1
120     fi
121   fi
122 done
123
124 # Stop if only getting one package
125
126 if test $SKIPPKG2 == 1
127  then
128   $CLEANUP
129   exit 0
130 fi
131
132 # Download second package
133
134 echo " "
135 echo "Downloading $PKGNAME2 package..."
136 export GOOD2=1
137 export TEST2=2
138
139 while test $TEST2 != $GOOD2
140 do
141   cd $INSTPATH
142   wget -c $DLURL/$BIGTAR2
143   if test -e  $TARPATH/$BIGTAR2
144    then
145
146     export GOOD2=$MD52
147     export TEST2=`$INSTPATH/md5sum  $TARPATH/$BIGTAR2 | awk '{print $1}'`
148
149     if test $TEST2 = $GOOD2
150      then
151       cd $EXTPATH2
152       TARERR=`$TARCMD2 2>&1`
153       if [ "$?" = 0 ] ; then
154         rm -rf $TARPATH/$BIGTAR2
155         $EXTCMD2
156         export MSG2=`printf "CONGRATULATIONS!\n\nAll has gone well!\n\nSuccess installing $PKGNAME2 package!"`
157         gxmessage -center -alignbuttons right -buttons GTK_STOCK_OK:0 -geometry 640x250 -title "SUCCESS!" "$MSG2"
158       else
159         export ERR2=`printf "ERROR! ERROR! ERROR!\nTAR FAILED!\n\nUnable to install $PKGNAME2\n\n$TARERR"`
160         gxmessage -center -alignbuttons right -buttons GTK_STOCK_OK:0 -geometry 640x250 -title "TAR ERROR" "$ERR2"
161         exit 99
162       fi
163      else
164       echo "$PKGNAME2 package seems damaged, trying again!"
165      fi
166    fi
167 done
168
169 $CLEANUP
170 exit 0