The first Fremantle easy-deb-chroot (0.9.33) that is somewhat working.
[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 BZ2CMD1="bzcat"
33 #export BZ2CMD2="| tar xf -"
34 export GZCMD1="tar -xzf"
35
36 export EXTPATH1=$TARPATH
37 export PKGNAME1="EASY DEBIAN IMAGE FILE"
38 export BIGTAR1="debian-squeeze-m5-img.bz2"
39 export BIGIMG1="debian-squeeze-m5.img.ext2"
40 export BZ2CMD1="bzip2 -dc "
41 export BZ2CMD2=" > $TARPATH/$BIGIMG1"
42 export TARCMD1="$BZ2CMD1 $TARPATH/$BIGTAR1 $BZ2CMD2"
43 export MD51="f769bb84c99f75821bdfa37e5ea34e86"
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      # Oh wow, this is even more of an ugly hack than my
105      # usual ugly hacks. So sorry you had to see this.
106
107      # TARERR=`$TARCMD1 2>&1`
108      TARERR="unspecified bzip2 error"
109      # echo $TARCMD1
110      $BZ2CMD1 $TARPATH/$BIGTAR1 > $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