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