service_pack.sh 6.1 KB

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