service_pack.sh 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #!/bin/sh
  2. #(c) Copyright Barry Kauler November 2012, bkhome.org
  3. #License GPL v3 (/usr/share/doc/legal).
  4. #look online for a service-pack.
  5. #called by ppm (pkg_chooser.sh) at startup, as a separate process.
  6. #121128 first release.
  7. #121129 bug fix.
  8. #121206 faster internet check. remove window centralise.
  9. #121217 DISTRO_VERSION getting reset by 'init' in initrd, need workaround.
  10. #121206 speed this up...
  11. #exit if no internet connection...
  12. #check_internet
  13. #check_internet
  14. #if [ $? -ne 0 ];then
  15. # sleep 2
  16. # check_internet
  17. #fi
  18. IFCONFIG="`ifconfig | grep '^[pwe]' | grep -v 'wmaster'`"
  19. [ ! "$IFCONFIG" ] && exit 1 #no network connection.
  20. ping -4 -c 1 www.google.com
  21. if [ $? -ne 0 ];then
  22. sleep 1
  23. ping -4 -c 1 www.google.com
  24. [ $? -ne 0 ] && exit 1 #no internet.
  25. fi
  26. export TEXTDOMAIN=petget___service_pack.sh
  27. export OUTPUT_CHARSET=UTF-8
  28. #. gettext.sh
  29. . /etc/DISTRO_SPECS #has DISTRO_DB_SUBNAME
  30. . /root/.packages/DISTRO_PET_REPOS #has PET_REPOS, PKG_DOCS_PET_REPOS
  31. mkdir -p /tmp/petget
  32. DBFILE="Packages\-puppy\-${DISTRO_DB_SUBNAME}\-"
  33. URLSPEC0="$(echo "$PKG_DOCS_PET_REPOS" | tr ' ' '\n' | grep "$DBFILE" | head -n 1 | cut -f 2 -d '|' | rev | cut -f 2-9 -d '/' | rev)"
  34. [ "$URLSPEC0" = "" ] && exit 2
  35. URLSPEC="${URLSPEC0}/pet_packages-${DISTRO_DB_SUBNAME}/"
  36. #i think should test that repo is working...
  37. URLPING="$(echo "$PKG_DOCS_PET_REPOS" | tr ' ' '\n' | grep "$DBFILE" | head -n 1 | cut -f 1 -d '|')"
  38. ping -4 -c 1 $URLPING
  39. [ $? -ne 0 ] && exit 1
  40. #find all service packs...
  41. #note, can use wildcard to test if file exists, if need to look for alternate versions, ex:
  42. # wget -4 -t 2 -T 20 --waitretry=20 --spider -S --recursive --no-parent --no-directories -A 'avast-*.pet' 'http://distro.ibiblio.org/quirky/pet_packages-common/'
  43. wget -4 -t 2 -T 20 --waitretry=20 --spider -S --recursive --no-parent --no-directories -A 'service_pack*.pet' "$URLSPEC" > /tmp/petget/service_pack_probe 2>&1
  44. PTN1=" ${URLSPEC}service_pack.*\.pet$"
  45. #ex line in file: --2012-11-25 09:01:13-- http://distro.ibiblio.org/quirky/pet_packages-precise/service_pack-5.4.1_TO_5.4.1.1_precise.pet
  46. FNDPETURLS="$(grep -o "$PTN1" /tmp/petget/service_pack_probe | grep -v '\*' | tr '\n' ' ')"
  47. [ "$FNDPETURLS" = "" ] && exit 3
  48. [ "$FNDPETURLS" = " " ] && exit 3
  49. spPTN1="|service_pack.*\.pet|"
  50. #121217 precaution, check highest already installed...
  51. INSTBIGGEST='0.0'
  52. INSTALLEDVERS="$(grep "$spPTN1" /root/.packages/user-installed-packages /root/.packages/woof-installed-packages | cut -f 3 -d '|' | cut -f 3 -d '_' | cut -f 1 -d '-' | tr '\n' ' ')"
  53. for ONEIN in $INSTALLEDVERS
  54. do
  55. if vercmp $ONEIN ge $INSTBIGGEST;then
  56. INSTBIGGEST="$ONEIN"
  57. fi
  58. done
  59. CNT=0; RADIOXML=''; STARTVER=0.0; ENDVER='0.0'; ENDVERbiggest='0.0'; PETbest=''
  60. #echo -n "" > /tmp/petget/service_pack_hack
  61. for APETURL in $FNDPETURLS
  62. do
  63. ABASE="$(basename $APETURL)"
  64. STARTVER="$(echo -n "$ABASE" | cut -f 2 -d '-' | cut -f 1 -d '_')" #ex: extract 5.4.1 from service_pack-5.4.1_TO_5.4.1.1_precise.pet
  65. ENDVER="$(echo -n "$ABASE" | cut -f 2 -d '-' | cut -f 3 -d '_' | cut -f 1 -d '-' | sed -e 's%\.pet$%%')" #ex: extract 5.4.1.1 121217 fix.
  66. if vercmp $ENDVER gt $INSTBIGGEST;then #121217 precaution
  67. if vercmp $STARTVER le $DISTRO_VERSION;then
  68. if vercmp $ENDVER gt $DISTRO_VERSION;then #121129
  69. #check whether already installed...
  70. spPTN2="_TO_${ENDVER}"
  71. FNDINST="$(cat /root/.packages/user-installed-packages /root/.packages/woof-installed-packages | grep "$spPTN1" | grep "$spPTN2" | cut -f 1 -d '|')"
  72. [ "$FNDINST" != "" ] && continue
  73. CNT=`expr $CNT + 1`
  74. #find the size...
  75. PARAS="$(cat /tmp/petget/service_pack_probe | sed -e 's%^$%BLANKLINE%' | tr '\n' ' ' | tr -s ' ' | sed -e 's%BLANKLINE%\n%g')"
  76. LENB=`echo "$PARAS" | grep "/${ABASE}" | grep -o ' Length: [0-9]* ' | cut -f 3 -d ' '`
  77. [ ! $LENB ] && LENB=0
  78. LENK=`expr $LENB \/ 1024`
  79. RADIOXML="${RADIOXML}
  80. <radiobutton><label>${ABASE} SIZE:${LENK}K</label><variable>RADIOVAR_${CNT}_</variable></radiobutton>"
  81. #echo "PACKAGE: ${ABASE} SIZE: ${LENK}K" >> /tmp/petget/service_pack_hack
  82. if vercmp $ENDVER gt $ENDVERbiggest;then
  83. ENDVERbiggest="$ENDVER"
  84. PETbest="$ABASE"
  85. BESTXML="<radiobutton><label>${ABASE} SIZE:${LENK}K</label><variable>RADIOVAR_${CNT}_</variable></radiobutton>"
  86. fi
  87. fi
  88. fi
  89. fi
  90. done
  91. [ $CNT -eq 0 ] && exit 4
  92. WINTITLETXT="$(gettext 'Puppy Package Manager: Service Pack')" #no: decorated=\"false\"
  93. MSG0TXT="$(gettext 'Service Pack available!')"
  94. MSG1TXT="$(gettext 'The current version of Puppy:')"
  95. MSG2TXT="$(gettext 'The highest available upgrade version:')"
  96. MSG3TXT="$(gettext 'A Service Pack is a PET package that will upgrade your Puppy, and it is highly recommended to do this.')"
  97. case $CNT in
  98. 1) MSG4TXT=" " ;;
  99. *)
  100. RADIOXML="$(echo "$RADIOXML" | grep -v "$PETbest")"
  101. RADIOXML="${BESTXML}
  102. ${RADIOXML}"
  103. MSG4TXT="$(gettext 'The most appropriate Service Pack is already chosen below.') "
  104. ;;
  105. esac
  106. MSG5TXT="$(gettext 'Please click the <b>OK</b> button right now, to download and install the Service Pack.')"
  107. #121206 window_position=\"1\"
  108. export SP_DIALOG="<window title=\"${WINTITLETXT}\" icon-name=\"gtk-about\">
  109. <vbox>
  110. <pixmap><input file>/usr/local/lib/X11/pixmaps/question.xpm</input></pixmap>
  111. <text use-markup=\"true\"><label>\"<big><b>${MSG0TXT}</b></big>\"</label></text>
  112. <text use-markup=\"true\"><label>\"${MSG1TXT} <b>${DISTRO_VERSION}</b>\"</label></text>
  113. <text use-markup=\"true\"><label>\"${MSG2TXT} <b>${ENDVERbiggest}</b>\"</label></text>
  114. <text use-markup=\"true\"><label>\"${MSG3TXT} ${MSG4TXT}${MSG5TXT}\"</label></text>
  115. <frame>
  116. ${RADIOXML}
  117. </frame>
  118. <hbox>
  119. <button ok></button>
  120. <button cancel></button>
  121. </hbox>
  122. </vbox>
  123. </window>"
  124. RETVALS="$(gtkdialog4 --program=SP_DIALOG)"
  125. [ "`echo "$RETVALS" | grep '^EXIT="OK"'`" = "" ] && exit 5
  126. TAG="$(echo "$RETVALS" | grep '^RADIOVAR_' | grep '"true"' | cut -f 1 -d '=')" #ex: RADIOVAR_1_="true"
  127. DLPET="$(echo "$RADIOXML" | grep "$TAG" | sed -e 's%^<radiobutton><label>%%' -e 's%\.pet.*%.pet%')"
  128. #kill ppm...
  129. ALLPS="`ps`"
  130. PID1="$(echo "$ALLPS" | grep 'MAIN_DIALOG$' | sed -e 's%^ %%g' | cut -f 1 -d ' ')"
  131. PID2="$(echo "$ALLPS" | grep 'ppm$' | sed -e 's%^ %%g' | cut -f 1 -d ' ')"
  132. [ "$PID1" ] && kill $PID1
  133. [ "$PID2" ] && kill $PID2 2>/dev/null
  134. cd /root
  135. [ -f /root/$DLPET ] && rm -f /root/$DLPET
  136. download_file "${URLSPEC}${DLPET}"
  137. if [ $? -eq 0 ];then
  138. if [ -f /root/$DLPET ];then
  139. petget /root/$DLPET #install the PET
  140. rm -f /root/$DLPET
  141. else
  142. pupmessage -bg '#FF8080' -title "$(gettext 'Download failed')" "$(gettext 'Sorry, the PET did not download. Perhaps try later.')"
  143. exit 6
  144. fi
  145. fi
  146. exit 0
  147. ###END###