sfsget 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. #!/bin/sh
  2. #(c) copyright Barry Kauler 2011, bkhome.org
  3. #Licence 2011 GPL V3 (/usr/share/doc/legal)
  4. #$1 is optional name of an sfs file passed on commandline, download it. ex: devx.sfs
  5. #$1 optional prefix, sub-directory on the official download URL. ex: wary-5.2/devx.sfs
  6. #110402 first version.
  7. #110422 DISTRO_VERSION variable now has dotted format. note, also now using full dotted version# in puppy filenames.
  8. #110813 bug fix, sfs file has '_' in name.
  9. #120202 BK: internationalized.
  10. #120204 more gettext.
  11. #120224 bugfix for racy.
  12. #120224 add slacko support.
  13. #120323 replace 'xmessage' with 'pupmessage'.
  14. #120325 add dir for precise sfs's.
  15. #121025 add case retroprecise.
  16. #121103 file DISTRO_SPECS now has variable DISTRO_DB_SUBNAME.
  17. #130128 also exclude udf and audiocd.
  18. export TEXTDOMAIN=sfsget
  19. export OUTPUT_CHARSET=UTF-8
  20. SFS_FILE=''; SFS_DIR=''
  21. if [ $1 ];then
  22. [ "`echo "$1" | grep '\.sfs$'`" = "" ] && exit 1
  23. SFS_FILE="`basename $1`"
  24. SFS_DIR="dirname $1"
  25. fi
  26. . /etc/rc.d/PUPSTATE #has PUP_HOME
  27. . /etc/DISTRO_SPECS #has DISTRO_BINARY_COMPAT, DISTRO_COMPAT_VERSION DISTRO_DB_SUBNAME
  28. . /root/.packages/DISTRO_PET_REPOS #has PET_REPOS, PACKAGELISTS_PET_ORDER
  29. if [ "`echo -n "$DISTRO_VERSION" | grep '\.'`" = "" ];then #110422
  30. #convert version to abreviated-dotted, ex1: 142 to 1.4.2 ex2: 150 to 1.5
  31. for ONECNT in 1 2 3
  32. do
  33. ONEDIGIT="`echo -n $DISTRO_VERSION | cut -c $ONECNT`"
  34. case $ONECNT in
  35. 1) DOTVER=$ONEDIGIT ;;
  36. 2) DOTVER="${DOTVER}.${ONEDIGIT}" ;;
  37. 3) [ "$ONEDIGIT" != "0" ] && DOTVER="${DOTVER}.${ONEDIGIT}" ;;
  38. esac
  39. done
  40. else
  41. DOTVER="$DISTRO_VERSION"
  42. fi
  43. #SFS_DIR0 is the release-dir, SFS_DIR1 as general collection of sfs's...
  44. MAJNUM="`echo -n "$DOTVER" | cut -f 1 -d '.'`" #110422
  45. case $DISTRO_FILE_PREFIX in
  46. qrky)
  47. x_REPOS="`echo -n "$PET_REPOS" | tr ' ' '\n' | grep '/quirky'`"
  48. SFS_DIR0="quirky-${DOTVER}"
  49. SFS_DIR1='sfs'
  50. ;;
  51. racy) #120224
  52. x_REPOS="`echo -n "$PET_REPOS" | tr ' ' '\n' | grep '/quirky'`"
  53. SFS_DIR0="racy-${DOTVER}"
  54. SFS_DIR1='sfs'
  55. ;;
  56. wary)
  57. x_REPOS="`echo -n "$PET_REPOS" | tr ' ' '\n' | grep '/quirky'`"
  58. SFS_DIR0="wary-${DOTVER}"
  59. SFS_DIR1='sfs'
  60. ;;
  61. lupu) #playdayz' Lucid Puppy
  62. x_REPOS="`echo -n "$PET_REPOS" | tr ' ' '\n' | grep -v '/quirky'`"
  63. SFS_DIR0="puppy-${DOTVER}"
  64. SFS_DIR1='pet-packages-lucid'
  65. SFS_DIR2="sfs_modules-${MAJNUM}"
  66. ;;
  67. fd64) #kirk's fatdog64
  68. x_REPOS="`echo -n "$PET_REPOS" | tr ' ' '\n' | grep '/fatdog'`"
  69. SFS_DIR0="sfs/${MAJNUM}00"
  70. ;;
  71. slacko) #01micko's spup
  72. x_REPOS="`echo -n "$PET_REPOS" | tr ' ' '\n' | grep -v '/quirky'`"
  73. SFS_DIR0="puppy-${DOTVER}"
  74. SFS_DIR1="pet_packages-${DISTRO_DB_SUBNAME}" #121103
  75. ;;
  76. *precise*) #Ubuntu Precise Pangolin 12.04. 121025 add retroprecise. 121103
  77. x_REPOS="`echo -n "$PET_REPOS" | tr ' ' '\n' | grep '/quirky'`"
  78. SFS_DIR0="${DISTRO_FILE_PREFIX}-${DOTVER}" #121103
  79. SFS_DIR1="pet_packages-${DISTRO_DB_SUBNAME}" #121103
  80. ;;
  81. *)
  82. x_REPOS="`echo -n "$PET_REPOS" | tr ' ' '\n' | grep -v '/quirky'`"
  83. SFS_DIR0="${DISTRO_FILE_PREFIX}-${DOTVER}" #121103
  84. SFS_DIR1="pet_packages-${DISTRO_DB_SUBNAME}" #121103
  85. ;;
  86. esac
  87. SFS_REPOS0="`echo -n "$x_REPOS" | tr -s ' ' | tr ' ' '\n' | sort --key=1 --field-separator="|" --unique | cut -f 1,2 -d '|'`"
  88. #ex: ibiblio.org|http://distro.ibiblio.org//quirky
  89. SFS_REPOS="`echo -n "$SFS_REPOS0" | tr '\n' ' '`"
  90. echo "$SFS_REPOS0" > /tmp/petget_repos #used by /usr/local/pteget/testurls.sh
  91. #probe remote site...
  92. yaf-splash -placement center -bg yellow -close never -fontsize large -text "$(gettext 'Please wait, probing primary remote site...')" &
  93. YPID=$!
  94. echo -n '' > /tmp/sfsget-probe
  95. echo -n '' > /tmp/sfsget-probe1
  96. echo -n '' > /tmp/sfsget-probe2
  97. xSFS_FILE="$SFS_FILE"
  98. [ ! "$SFS_FILE" ] && xSFS_FILE='*.sfs'
  99. PRIMARYREPO="`echo "$SFS_REPOS0" | grep 'distro\.ibiblio\.org' | head -n 1 | cut -f 2 -d '|'`"
  100. if [ "$SFS_DIR" ];then
  101. SFS_DIR0="$SFS_DIR"
  102. wget -4 -t 2 -T 20 --waitretry=20 --spider --recursive --level=1 --accept "${xSFS_FILE}" -S ${PRIMARYREPO}/${SFS_DIR}/ 2>&1 | grep '\.sfs$' | rev | cut -f 1 -d '/' | rev > /tmp/sfsget-probe
  103. else
  104. wget -4 -t 2 -T 20 --waitretry=20 --spider --recursive --level=1 --accept "${xSFS_FILE}" -S ${PRIMARYREPO}/${SFS_DIR0}/ 2>&1 | grep '\.sfs$' | rev | cut -f 1 -d '/' | rev > /tmp/sfsget-probe
  105. [ "$SFS_DIR1" ] && wget -4 -t 2 -T 20 --waitretry=20 --spider --recursive --level=1 --accept "${xSFS_FILE}" -S ${PRIMARYREPO}/${SFS_DIR1}/ 2>&1 | grep '\.sfs$' | rev | cut -f 1 -d '/' | rev > /tmp/sfsget-probe1
  106. [ "$SFS_DIR2" ] && wget -4 -t 2 -T 20 --waitretry=20 --spider --recursive --level=1 --accept "${xSFS_FILE}" -S ${PRIMARYREPO}/${SFS_DIR2}/ 2>&1 | grep '\.sfs$' | rev | cut -f 1 -d '/' | rev > /tmp/sfsget-probe2
  107. fi
  108. sync
  109. kill $YPID
  110. if [ ! -s /tmp/sfsget-probe ];then
  111. if [ ! -s /tmp/sfsget-probe1 ];then
  112. if [ ! -s /tmp/sfsget-probe2 ];then
  113. yaf-splash -placement center -bg red -close box -fontsize large -text "$(gettext 'Either your Internet connection is not working, or the primary repository is down. Aborting SFS Downloader')"
  114. exit 1
  115. fi
  116. fi
  117. fi
  118. if [ ! "$SFS_FILE" ];then
  119. #ask which sfs to download...
  120. SFSBUTTONS=''
  121. for ONESFS in `cat /tmp/sfsget-probe /tmp/sfsget-probe1 /tmp/sfsget-probe2 | sort -u | tr '\n' ' '`
  122. do
  123. SFSBUTTONS="${SFSBUTTONS}<radiobutton><label>${ONESFS}</label><variable>RADIO_URL_${ONESFS}</variable></radiobutton>"
  124. done
  125. export SFS_DIALOG="<window title=\"$(gettext 'SFS Downloader: choose file')\" icon-name=\"gtk-about\" window_position=\"1\">
  126. <vbox>
  127. <text><label>$(gettext 'Please choose an SFS file that you would like to download:')</label></text>
  128. <frame>
  129. ${SFSBUTTONS}
  130. </frame>
  131. <hbox>
  132. <button ok></button>
  133. <button cancel></button>
  134. </hbox>
  135. </vbox>
  136. </window>"
  137. RETPARAMS="`gtkdialog3 --program=SFS_DIALOG`"
  138. [ "`echo "$RETPARAMS" | grep '^EXIT' | grep 'OK'`" = "" ] && exit 1
  139. SFS_FILE="`echo "$RETPARAMS" | grep 'RADIO_URL_' | grep '"true"' | cut -f 1 -d '=' | cut -f 3-9 -d '_'`" #110813 bug fix.
  140. fi
  141. [ "`grep "$SFS_FILE" /tmp/sfsget-probe`" != "" ] && SFS_DIR="$SFS_DIR0"
  142. [ ! "$SFS_DIR" ] && [ "$SFS_DIR1" ] && [ "`grep "$SFS_FILE" /tmp/sfsget-probe1`" != "" ] && SFS_DIR="$SFS_DIR1"
  143. [ ! "$SFS_DIR" ] && [ "$SFS_DIR2" ] && [ "`grep "$SFS_FILE" /tmp/sfsget-probe2`" != "" ] && SFS_DIR="$SFS_DIR2"
  144. #decide where to download to...
  145. #where the save-file is, or if PUPMODE=5 then ask...
  146. DLPART=''; RUNBOOTMGR=''
  147. if [ -L /mnt/home ];then
  148. DLMOUNT="/mnt/home"
  149. DLMOUNT1="`readlink /mnt/home`"
  150. REGEXd=" ${DLMOUNT1}$"
  151. DLPART="`df | grep "$REGEXd" | cut -f 1 -d ' ' | grep '/dev/' | cut -f 3 -d '/'`" #ex: sda1
  152. fi
  153. if [ "$DLPART" ];then
  154. RUNBOOTMGR='yes'
  155. cd $DLMOUNT
  156. else
  157. DLPARTS="`probepart -m | grep -v -E 'none|iso9660|swap|udf|audiocd' | tr '\n' ' '`" #130128 also exclude udf and audiocd.
  158. DLBUTTONS=""
  159. [ "$DLPARTS" = "" ] && DLBUTTONS="<text use-markup=\"true\"><label>\"<b>$(gettext 'NO PARTITIONS FOUND')</b>\"</label></text>"
  160. for ONEDLSPEC in $DLPARTS
  161. do
  162. DEVNODE="`echo -n "$ONEDLSPEC" | cut -f 1 -d '|' | cut -f 3 -d '/'`"
  163. DEVFS="`echo -n "$ONEDLSPEC" | cut -f 2 -d '|'`"
  164. DEVSIZEM="`echo -n "$ONEDLSPEC" | cut -f 3 -d '|'`"
  165. DLBUTTONS="${DLBUTTONS}<radiobutton><label>${DEVNODE} $(gettext 'filesystem:') ${DEVFS} $(gettext 'size:') ${DEVSIZEM}MB</label><variable>RADIO_URL_${DEVNODE}</variable></radiobutton>"
  166. done
  167. export DL_DIALOG="<window title=\"$(gettext 'SFS Downloader: destination')\" icon-name=\"gtk-about\" window_position=\"1\">
  168. <vbox>
  169. <text><label>$(gettext 'This is a first boot of Puppy and you have not yet saved a session. You want to download') ${SFS_FILE}, $(gettext "and this needs to be downloaded to the same partition in which you will be creating the session save-file. Then, at next boot, Puppy will load the session and will also see the SFS file and be able to load that also (a 'zdrv' will load automatically, others need to be manually selected in te BootManager -- see System menu)")</label></text>
  170. <text><label>$(gettext 'Here is a list of suitable partitions. Whichever one you choose, at shutdown you will be asked to save the session and be sure to choose the same partition. Well, even if you download it to the wrong place, you can move it afterward! Click the one you want:')</label></text>
  171. <frame>
  172. ${DLBUTTONS}
  173. </frame>
  174. <hbox>
  175. <button ok></button>
  176. <button cancel></button>
  177. </hbox>
  178. </vbox>
  179. </window>"
  180. RETPARAMS="`gtkdialog3 --program=DL_DIALOG`"
  181. [ "`echo "$RETPARAMS" | grep '^EXIT' | grep 'OK'`" = "" ] && exit 1
  182. DLPART="`echo "$RETPARAMS" | grep 'RADIO_URL_' | grep '"true"' | cut -f 1 -d '=' | cut -f 3 -d '_'`"
  183. REGEXd="/dev/${DLPART} "
  184. DLMOUNT="`mount | grep "$REGEXd" | cut -f 3 -d ' '`"
  185. if [ "$DLMOUNT" = "" ];then
  186. mkdir -p /mnt/${DEVNODE}
  187. REGEXe="/dev/${DLPART}|"
  188. DLFS="`echo "$DLPARTS" | grep "$REGEXe" | cut -f 2 -d '|'`"
  189. mount -t $DLFS /dev/$DEVNODE /mnt/$DEVNODE
  190. if [ $? -ne 0 ];then
  191. pupmessage -bg red -center "$(gettext 'ERROR: Could not mount') /dev/${DEVNODE}, $(gettext 'aborting')"
  192. exit 1
  193. fi
  194. DLMOUNT="/mnt/$DEVNODE"
  195. fi
  196. cd $DLMOUNT
  197. fi
  198. REPOBUTTONS=""
  199. for ONEREPOSPEC in $SFS_REPOS
  200. do
  201. URL_TEST="`echo -n "$ONEREPOSPEC" | cut -f 1 -d '|'`"
  202. URL_FULL="`echo -n "$ONEREPOSPEC" | cut -f 2 -d '|'`"
  203. REPOBUTTONS="${REPOBUTTONS}<radiobutton><label>${URL_TEST}</label><variable>RADIO_URL_${URL_TEST}</variable></radiobutton>"
  204. done
  205. DLRET=1
  206. while [ $DLRET -ne 0 ];do
  207. export DEPS_DIALOG="<window title=\"$(gettext 'SFS Downloader: host site')\" icon-name=\"gtk-about\" window_position=\"1\">
  208. <vbox>
  209. <text><label>$(gettext 'You have chosen to download this SFS file:')</label></text>
  210. <text use-markup=\"true\"><label>\"<b>${SFS_FILE}</b>\"</label></text>
  211. <text><label>$(gettext 'It will be downloaded to the top-level (/) in partition') /dev/${DLPART}.</label></text>
  212. <text><label>$(gettext 'Please choose which URL you would like to download it from:')</label></text>
  213. <frame>
  214. ${REPOBUTTONS}
  215. </frame>
  216. <hbox>
  217. <button>
  218. <label>$(gettext 'Test URLs')</label>
  219. <action>/usr/local/petget/testurls.sh</action>
  220. </button>
  221. <button>
  222. <label>$(gettext 'Download SFS file')</label>
  223. <action type=\"exit\">BUTTON_SFS_DOWNLOAD</action>
  224. </button>
  225. <button cancel></button>
  226. </hbox>
  227. </vbox>
  228. </window>
  229. "
  230. RETPARAMS="`gtkdialog3 --program=DEPS_DIALOG`"
  231. [ "`echo "$RETPARAMS" | grep 'BUTTON_SFS_DOWNLOAD'`" = "" ] && exit 1
  232. URL_BASIC="`echo "$RETPARAMS" | grep 'RADIO_URL_' | grep '"true"' | cut -f 1 -d '=' | cut -f 3 -d '_'`"
  233. DOWNLOADFROM="`cat /tmp/petget_repos | grep "$URL_BASIC" | head -n 1 | cut -f 2 -d '|'`"
  234. ####DOWNLOAD IT#####
  235. download_file ${DOWNLOADFROM}/${SFS_DIR}/${SFS_FILE}
  236. ####################
  237. DLRET=$?
  238. done #while loop
  239. if [ "$RUNBOOTMGR" = "yes" ];then
  240. yaf-splash -placement top -bg green -close box -fontsize large -timeout 20 -text "$(gettext "The SFS file has downloaded. You can now choose it in the BootManager (but not a 'zdrv' SFS, that will automatically load), then reboot for it to load")" &
  241. bootmanager extrasfs
  242. else
  243. yaf-splash -placement center -bg green -close box -fontsize large -text "$(gettext "The SFS file has been downloaded, however you have to save the session (at shutdown) then on next bootup the BootManager will run and offer the SFS file (a 'zdrv' SFS will automatically load).")" &
  244. fi
  245. exit 0
  246. ###END###