Fremantle updates: easy-chroot 0.2.7, easy-deb-chroot 0.9.42
[easy-deb-chroot] / fremantle / easy-deb-chroot / src / home / user / img-install / debian-installer.sh
1 #!/bin/sh
2
3 ## Download the list of images. Also use this opportunity to check
4 ## the Internet connection and availability of the server.
5
6 IMGLIST="imagelist-0.9.40"
7
8 mv $IMGLIST $IMGLIST.old
9 wget -t 3 http://qole.org/$IMGLIST
10 if [ $? != 0 ] ; then
11   MSG1=`printf "\
12 Cannot download the list of available images.\n\
13 $? \
14 Something is wrong with either your Internet connection\n\
15 or the qole.org file server.\n\n\
16 Check your Internet connection and the status\n\
17 of the server by browsing to http://qole.org"`
18   gxmessage -center -alignbuttons right -buttons GTK_STOCK_OK:0 -geometry 640x250 -title "Download Error" "$MSG1"
19   exit
20 fi
21
22 gxmessage -buttons \
23   "`awk -F ',' '/^[0-9],/ {print $2":"$1","}' $IMGLIST`Cancel:0" \
24   "`awk -F ',' '/^[0-9],/ {print $2":"$6}' $IMGLIST`"
25 IMGCHOICE=$? 
26
27 #Both 0 and 1 are Cancel
28
29 if [ "$IMGCHOICE" -le "1" ] ; then
30   exit 9
31 fi
32
33 DLURL=`awk -F"," '$1=='$IMGCHOICE' {print $3}' $IMGLIST`
34 PKGNAME1=`awk -F"," '$1=='"$IMGCHOICE"' {print $6}' $IMGLIST`
35 BIGTAR1=`awk -F"," '$1=='"$IMGCHOICE"' {print $4"."$5}' $IMGLIST`
36 BIGIMG1=`awk -F"," '$1=='"$IMGCHOICE"' {print $4}' $IMGLIST`
37 MD51=`awk -F"," '$1=='"$IMGCHOICE"' {print $7}' $IMGLIST`
38 IMGCMPRSS=`awk -F"," '$1=='"$IMGCHOICE"' {print $5}' $IMGLIST`
39
40 #echo $DLURL
41 #echo $PKGNAME1
42 #echo $BIGTAR1
43 #echo $BIGIMG1
44 #echo $MD51
45 #echo $IMGCMPRSS
46
47 ## Make sure the chroot is closed, to avoid spurious mounts
48
49 sudo closechroot >/dev/null
50
51 ## Ask where the user wishes to install the package with gxmessage:
52
53 export GXMSG=`printf "\
54 Where do you want your Debian image file installed?\n\
55 You need approximately 2.3GB initially.\n\
56 Free space left in internal memory or your memory card:\n\n"; \
57 df -h | grep "mmcblk.p1" | awk '{print $6 ": " $4 " free, " $2 " total (" $5 " full)"}' | sort`
58 gxmessage -center -buttons MyDocs:2,MicroSD:3 -geometry 690x380 -title "Choose Memory Card" "$GXMSG"
59 export SDNO=$?
60
61 case "$SDNO" in
62   2)
63     export SDCARD="/home/user/MyDocs" 
64     ;;
65   3)
66     export SDCARD="/media/mmc1" 
67     ;;
68   *)
69     exit 9
70     ;;
71 esac
72
73 echo "Downloading and extracting $BIGIMG1 to $SDCARD..."
74
75 # exit 0
76
77 ## HERE ARE THE REST OF THE VARIABLES:
78
79 export INSTPATH="/home/user/img-install"
80 export TARPATH="$SDCARD"
81 export EXTPATH1=$TARPATH
82 export EXTCMD1=""
83
84 #export CLEANUP="sudo rm -r $INSTPATH ; sudo rm /usr/share/applications/image-install.desktop "
85 export CLEANUP="echo All done!"
86
87 ## HERE'S THE SCRIPT:
88
89 # Download first package
90
91 echo " "
92 echo "Downloading $PKGNAME1 package..."
93
94 export GOTIT="no"
95
96 if [ -f $TARPATH/$BIGTAR1 ] ; then
97   echo You already have the big image file! 
98   echo   Checking to see if it is good...
99   if [ "`$INSTPATH/md5sum  $TARPATH/$BIGTAR1 | awk '{print $1}'`" = "$MD51" ] ; then 
100     export GOTIT="yes"
101   fi
102 fi
103
104 export GOOD=1
105 export TEST=2
106
107 while test $TEST != $GOOD 
108 do
109  cd $TARPATH
110  if [ ! "$GOTIT" = "yes" ] ; then
111    wget -c $DLURL/$BIGTAR1
112  fi
113
114  if test -e  $TARPATH/$BIGTAR1
115   then
116
117    cd $INSTPATH
118    export GOOD=$MD51
119    if [ ! "$GOTIT" = "yes" ] ; then
120      echo Testing the file to see if it is good.
121      export TEST=`$INSTPATH/md5sum  $TARPATH/$BIGTAR1 | awk '{print $1}'`
122    else
123      export TEST=$MD51
124    fi
125
126    if test $TEST = $GOOD
127     then
128
129      cd $EXTPATH1
130
131 # Warn the user that the decompression is going to take a long time.
132
133      export MSG1=`printf "\
134 Extracting the image file.\n\
135 This could take a very long time and could\n\
136 cause your device to become unresponsive."`
137      gxmessage -center -alignbuttons right -buttons GTK_STOCK_OK:0 -geometry 640x250 -title "Decompressing" "$MSG1" &
138
139      echo " "
140      echo "Extracting $BIGTAR1 package..."
141
142      TARERR="Unknown lzma error"
143      # read -p 'press enter' key
144      #$TARCMD1
145      lzma -kd $TARPATH/$BIGTAR1
146      if [ "$?" = 0 ] ; then
147          rm -rf $TARPATH/$BIGTAR1
148          $EXTCMD1
149          export MSG1=`printf "CONGRATULATIONS!\n\nAll has gone well!\n\nSuccess installing $PKGNAME1 package!"`
150          gxmessage -center -alignbuttons right -buttons GTK_STOCK_OK:0 -geometry 640x250 -title "SUCCESS!" "$MSG1"
151        else
152          export ERR1=`printf "ERROR! DECOMPRESSION FAILED!\nUnable to install $PKGNAME1\n$TARERR"`
153          gxmessage -center -alignbuttons right -buttons GTK_STOCK_OK:0 -geometry 640x380 -title "DECOMPRESSION ERROR" "$ERR1"
154          exit 99
155       fi        
156     else
157       export ERR1=`printf "$PKGNAME1 package appears damaged.\nPress OK to try downloading again.\nCancel keeps the damaged file."`
158       gxmessage -center -alignbuttons right -buttons GTK_STOCK_OK:0,GTK_STOCK_CANCEL:1 -geometry 640x100 -title "DOWNLOAD ERROR" "$ERR1"
159       if [ "$?" = 1 ] ; then
160         exit 99
161       fi
162       rm $TARPATH/$BIGTAR1
163     fi
164   fi
165 done
166
167 $CLEANUP
168 exit 0