installpkg.sh 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868
  1. #!/bin/sh
  2. #(c) Copyright Barry Kauler 2009, puppylinux.com
  3. #2009 Lesser GPL licence v2 (http://www.fsf.org/licensing/licenses/lgpl.html).
  4. #called from /usr/local/petget/downloadpkgs.sh and petget.
  5. #passed param is the path and name of the downloaded package.
  6. #/tmp/petget_missing_dbentries-Packages-* has database entries for the set of pkgs being downloaded.
  7. #w456 warning: petget may write to /tmp/petget_missing_dbentries-Packages-alien with missing fields.
  8. #w478, w482 fix for pkg menu categories.
  9. #w482 detect zero-byte pet.specs, fix typo.
  10. #100110 add support for T2 .tar.bz2 binary packages.
  11. #100426 aufs can now write direct to save layer.
  12. #100616 add support for .txz slackware pkgs.
  13. # 20aug10 shinobar: excute pinstall.sh under original LANG environment
  14. # 6sep10 shinobar: warning to install on /mnt/home # 16sep10 remove test code
  15. # 17sep10 shinobar; fix typo was double '|' at reading DESCRIPTION
  16. # 22sep10 shinobar clean up probable old files for precaution
  17. # 22sep10 shinobar: bugfix was not working clean out whiteout files
  18. #110503 change ownership of some files if non-root.
  19. #110523 support for rpm pkgs.
  20. #110705 fix rpm install.
  21. #110817 rcrsn51: fix find syntax, looking for icons. 110821 improve.
  22. #111013 shinobar: aufs direct-write to layer not working, bypass for now.
  23. #111013 revert above. it works for me, except if file already on top -- that is another problem, needs to be addressed.
  24. #111207 improve search for menu icon.
  25. #111229 /usr/local/petget/removepreview.sh when uninstalling a pkg, may have copied a file from sfs-layer to top, check.
  26. #120102 install may have overwritten a symlink-to-dir.
  27. #120107 rerwin: need quotes around some paths in case of space chars. remove '--unlink-first' from tar (was introduced 120102, don't think necessary).
  28. #120126 noryb009: fix typo.
  29. #120219 was not properly internationalized (there was no TEXTDOMAIN).
  30. #120523 may need to run gio-query-modules and/or glib-compile-schemas. (refer also rc.update and 3builddistro)
  31. #120628 fix Categories= assignment in .desktop files. see also 2createpackages in woof.
  32. #120818 Categories management improved. pkg db now has category[;subcategory] (see 0setup), xdg enhanced (see /etc/xdg and /usr/share/desktop-directories), and generic icons for all subcategories (see /usr/local/lib/X11/mini-icons).
  33. #120901 .desktop files, get rid of param on end of Exec, ex: Exec=gimp-2.8 %U
  34. #120907 post-install hacks.
  35. #120926 apply translation for .desktop file if langpack installed.
  36. #121015 01micko: alternative code to delete %-param off end of Exec line in .desktop file.
  37. #121109 fixing Categories field in .desktop may fail, as DB_category field may not match that in .desktop file, so leave out that $tPATTERN match in $PUPHIERARCHY.
  38. #121109 menu category was not reported correctly in post-install window.
  39. #121119 change in layout of /etc/xdg/menus/hierarchy caused regex pattern bug.
  40. #121119 if only one .desktop file, first check if a match in /usr/local/petget/categories.dat.
  41. #121120 bugfix of 121119.
  42. #121123 having a problem with multiarch symlinks in full-installation, getting replaced by a directory.
  43. #121206 default icon needs .xpm extension. note puppy uses older xdg-utilities, Icon field needs image ext.
  44. #121217 still getting reports multiarch symlinks getting overwritten.
  45. #130112 some deb's have a post-install script (ex: some python debs).
  46. #130112 multiarch symlinks now optional. see also 2createpackages, 3builddistro.
  47. #130114 revert 130112 "multiarch symlinks now optional".
  48. #130126 'categories.dat' format changed.
  49. #130219 grep, ignore case.
  50. #130305 rerwin: ensure tmp directory has all permissions after package expansion.
  51. #130314 install arch linux pkgs. run arch linux pkg post-install script.
  52. #131122 support xz compressed pets (see dir2pet, pet2tgz), changed file test
  53. [ "$(cat /var/local/petget/nt_category 2>/dev/null)" != "true" ] && \
  54. [ -f /tmp/install_quietly ] && set -x
  55. #; mkdir -p /tmp/PPM_LOGs ; NAME=$(basename "$0"); exec 1>> /tmp/PPM_LOGs/"$NAME".log 2>&1
  56. export TEXTDOMAIN=petget___installpkg.sh
  57. export OUTPUT_CHARSET=UTF-8
  58. APPDIR=$(dirname $0)
  59. [ -f "$APPDIR/i18n_head" ] && source "$APPDIR/i18n_head"
  60. LANG_USER=$LANG
  61. export LANG=C
  62. . /etc/rc.d/PUPSTATE #this has PUPMODE and SAVE_LAYER.
  63. . /etc/DISTRO_SPECS #has DISTRO_BINARY_COMPAT, DISTRO_COMPAT_VERSION
  64. . /etc/xdg/menus/hierarchy #w478 has PUPHIERARCHY variable.
  65. [ "$PUPMODE" = "2" ] && [ ! -d /audit ] && mkdir -p /audit
  66. DLPKG="$1"
  67. DLPKG_BASE="`basename "$DLPKG"`" #ex: scite-1.77-i686-2as.tgz
  68. DLPKG_PATH="`dirname "$DLPKG"`" #ex: /root
  69. DL_SAVE_FLAG=$(cat /var/local/petget/nd_category 2>/dev/null)
  70. clean_and_die () {
  71. rm -f /root/.packages/${DLPKG_NAME}.files
  72. exit 1
  73. }
  74. # 6sep10 shinobar: installing files under /mnt is danger
  75. install_path_check() {
  76. FILELIST="/root/.packages/${DLPKG_NAME}.files"
  77. [ -s "$FILELIST" ] || return 0 #120126 noryb009: typo
  78. grep -q '^/mnt' "$FILELIST" || return 0
  79. MNTDIRS=$(cat "$FILELIST" | grep '^/mnt/.*/$' | cut -d'/' -f1-3 | tail -n 1)
  80. LANG=$LANG_USER
  81. MSG1=$(gettext "This package will install files under")
  82. MSG2=$(gettext "It can be dangerous to install files under '/mnt' because it depends on the profile of installation.")
  83. MSG3=""
  84. if grep -q '^/mnt/home' "$FILELIST"; then
  85. if [ $PUPMODE -eq 5 ]; then
  86. MSG3=$(gettext "You are running Puppy without 'pupsave', and '/mnt/home' does not exist. In this case, you can use the RAM for this space, but strongly recommended to shutdown now to create 'pupsave' BEFORE installing these packages.")
  87. MSG3="$MSG3\\n$(gettext "NOTE: You can install this package for a tentative use, then do NOT make 'pupsave' with this package installed.")"
  88. fi
  89. DIRECTSAVEPATH=""
  90. fi
  91. # dialog
  92. export DIALOG="<window title=\"$T_title\" icon-name=\"gtk-dialog-warning\">
  93. <vbox>
  94. <text use-markup=\"true\"><label>\"$MSG1: <b>$MNTDIRS</b>\"</label></text>
  95. <text><input>echo -en \"$MSG2 $MSG3\"</input></text>
  96. <text><label>$(gettext "Click 'Cancel' not to install(recommended). Or click 'Install' if you like to proceed.")</label></text>
  97. <hbox>
  98. <button cancel></button>
  99. <button><input file stock=\"gtk-apply\"></input><label>$(gettext 'Install')</label><action type=\"exit\">INSTALL</action></button>
  100. </hbox>
  101. </vbox>
  102. </window>"
  103. RETPARAMS=`gtkdialog -p DIALOG` || echo "$DIALOG" >&2
  104. eval "$RETPARAMS"
  105. LANG=C
  106. [ "$EXIT" = "INSTALL" ] && return 0
  107. rm -f "$FILELIST"
  108. exit 1
  109. }
  110. # 22sep10 shinobar clean up probable old files for precaution
  111. rm -f /pet.specs /pinstall.sh /puninstall.sh /install/doinst.sh
  112. #get the pkg name ex: scite-1.77 ...
  113. dbPATTERN='|'"$DLPKG_BASE"'|'
  114. DLPKG_NAME="`cat /tmp/petget_missing_dbentries-Packages-* | grep "$dbPATTERN" | head -n 1 | cut -f 1 -d '|'`"
  115. #131222 do not allow duplicate installs...
  116. PTN1='^'"$DLPKG_NAME"'|'
  117. if [ "`grep "$PTN1" /root/.packages/user-installed-packages`" != "" ];then
  118. if [ ! $DISPLAY ];then
  119. [ -f /tmp/install_quietly ] && DISPTIME1="--timeout 3" || DISPTIME1=''
  120. LANG=$LANG_USER
  121. dialog ${DISPTIME1} --msgbox "$(gettext 'This package is already installed. Cannot install it twice:') ${DLPKG_NAME}" 0 0
  122. else
  123. LANG=$LANG_USER
  124. if [ "$(</var/local/petget/ui_choice)" = "Classic" -o -f /tmp/install_classic ]; then
  125. /usr/lib/gtkdialog/box_ok "$(gettext 'Puppy package manager')" error "$(gettext 'This package is already installed. Cannot install it twice:')" "<i>${DLPKG_NAME}</i>"
  126. [ -f /tmp/install_classic ] && echo ${DLPKG_NAME} >> /tmp/pgks_failed_to_install_forced
  127. else
  128. /usr/lib/gtkdialog/box_ok "$(gettext 'Puppy package manager')" error "$(gettext 'This package is already installed. Cannot install it twice:')" "<i>${DLPKG_NAME}</i>" &
  129. XPID=$!
  130. sleep 3
  131. pkill -P $XPID
  132. echo ${DLPKG_NAME} >> /tmp/pgks_failed_to_install_forced
  133. fi
  134. fi
  135. exit 1
  136. fi
  137. #boot from flash: bypass tmpfs top layer, install direct to pup_save file...
  138. DIRECTSAVEPATH=""
  139. if [ "$PUPMODE" = "2" ]; then # from BK's quirky6.1
  140. #131220 131229 detect if not enough room in /tmp...
  141. DIRECTSAVEPATH="/tmp/petget/directsavepath"
  142. SIZEB=`stat --format=%s "${DLPKG_PATH}"/${DLPKG_BASE}`
  143. SIZEK=`expr $SIZEB \/ 1024`
  144. EXPK=`expr $SIZEK \* 5` #estimated worst-case expanded size.
  145. NEEDK=$EXPK
  146. TMPK=`df -k /tmp | grep '^tmpfs' | tr -s ' ' | cut -f 4 -d ' '` #free space in /tmp
  147. if [ $EXPK -ge $TMPK ];then
  148. DIRECTSAVEPATH="/audit/directsavepath"
  149. NEEDK=`expr $NEEDK \* 2`
  150. fi
  151. if [ "$DIRECTSAVEPATH" ];then
  152. rm -rf $DIRECTSAVEPATH
  153. mkdir -p $DIRECTSAVEPATH
  154. fi
  155. # check enough space to install pkg...
  156. #as the pkg gets expanded to an intermediate dir, maybe in main f.s...
  157. PARTK=`df -k / | grep '/$' | tr -s ' ' | cut -f 4 -d ' '` #free space in partition.
  158. if [ $NEEDK -gt $PARTK ];then
  159. LANG=$LANG_USER
  160. if [ $DISPLAY ];then
  161. /usr/lib/gtkdialog/box_ok "$(gettext 'Puppy package manager')" error "$(gettext 'Not enough free space in the partition to install this package'):" "<i>${DLPKG_BASE}</i>"
  162. else
  163. echo -e "$(gettext 'Not enough free space in the partition to install this package'):\n${DLPKG_BASE}"
  164. fi
  165. [ "$DLPKG_PATH" != "" ] && rm -f "${DLPKG_PATH}"/${DLPKG_BASE}
  166. exit 1
  167. fi
  168. #111013 shinobar: this currently not working, bypass for now... 111013 revert...
  169. #elif [ "ABC" = "DEF" ];then #111013
  170. elif [ $PUPMODE -eq 3 -o $PUPMODE -eq 7 -o $PUPMODE -eq 13 ];then
  171. # SFR: let user chose...
  172. [ -f /var/local/petget/install_mode ] && IMODE="`cat /var/local/petget/install_mode`" || IMODE="savefile"
  173. if [ "$IMODE" != "tmpfs" ]; then
  174. FLAGNODIRECT=1
  175. #100426 aufs can now write direct to save layer...
  176. #note: fsnotify now preferred not inotify, udba=notify uses whichever is enabled in module...
  177. busybox mount -t aufs -o remount,udba=notify unionfs / #remount aufs with best evaluation mode.
  178. FLAGNODIRECT=$?
  179. [ $FLAGNODIRECT -ne 0 ] && logger -s -t "installpkg.sh" "Failed to remount aufs / with udba=notify"
  180. if [ $FLAGNODIRECT -eq 0 ];then
  181. #note that /sbin/pup_event_frontend_d will not run snapmergepuppy if installpkg.sh or downloadpkgs.sh are running.
  182. while [ "`pidof snapmergepuppy`" != "" ];do
  183. sleep 1
  184. done
  185. DIRECTSAVEPATH="/initrd${SAVE_LAYER}" #SAVE_LAYER is in /etc/rc.d/PUPSTATE.
  186. rm -f $DIRECTSAVEPATH/pet.specs $DIRECTSAVEPATH/pinstall.sh $DIRECTSAVEPATH/puninstall.sh $DIRECTSAVEPATH/install/doinst.sh
  187. fi
  188. fi
  189. fi
  190. if [ $DISPLAY -a ! -f /tmp/install_quietly ];then #131222
  191. LANG=$LANG_USER
  192. . /usr/lib/gtkdialog/box_splash -close never -fontsize large -text "$(gettext 'Please wait, processing...')" &
  193. YAFPID1=$!
  194. trap 'pupkill $YAFPID1' EXIT #140318
  195. fi
  196. cd "$DLPKG_PATH"
  197. case $DLPKG_BASE in
  198. *.pet)
  199. # determine compression
  200. file -b "$DLPKG_BASE" | grep -i -q "^xz" && EXT=xz || EXT=gz #131122 #140109 add -i, eg: "XZ"
  201. case $EXT in
  202. xz)OPT=-J ;;
  203. gz)OPT=-z ;;
  204. esac
  205. DLPKG_MAIN="`basename $DLPKG_BASE .pet`"
  206. pet2tgz $DLPKG_BASE
  207. [ $? -ne 0 ] && exit 1
  208. PETFILES="`tar --list ${OPT} -f ${DLPKG_MAIN}.tar.${EXT}`"
  209. #slackware pkg, got a case where passed the above test but failed here...
  210. [ $? -ne 0 ] && exit 1
  211. #check for renamed pets. Will produce an empty ${DLPKG_NAME}.files file
  212. PETFOLDER=$(echo "${PETFILES}" | cut -f 2 -d '/' | head -n 1)
  213. [ "$PETFOLDER" = "" ] && PETFOLDER=$(echo "${PETFILES}" | cut -f 1 -d '/' | head -n 1)
  214. if [ "${DLPKG_MAIN}" != "${PETFOLDER}" ]; then
  215. pupkill $YAFPID1
  216. LANG=$LANG_USER
  217. if [ "$DISPLAY" ]; then
  218. . /usr/lib/gtkdialog/box_ok "$(gettext 'Puppy Package Manager')" error "<b>${DLPKG_MAIN}.pet</b> $(gettext 'is named') <b>${PETFOLDER}</b> $(gettext 'inside the pet file. Will not install it!')"
  219. else
  220. . dialog --msgbox "$DLPKG_MAIN.pet $(gettext 'is named') $PETFOLDER $(gettext 'inside the pet file. Will not install it!')" 0 0
  221. fi
  222. exit 1
  223. fi
  224. if [ "`echo "$PETFILES" | grep '^\\./'`" != "" ];then
  225. #ttuuxx has created some pets with './' prefix...
  226. pPATTERN="s%^\\./${DLPKG_NAME}%%"
  227. echo "$PETFILES" | sed -e "$pPATTERN" > /root/.packages/${DLPKG_NAME}.files
  228. install_path_check
  229. tar ${OPT} -x --strip=2 --directory=${DIRECTSAVEPATH}/ -f ${DLPKG_MAIN}.tar.${EXT} #120102. 120107 remove --unlink-first
  230. else
  231. #new2dir and tgz2pet creates them this way...
  232. pPATTERN="s%^${DLPKG_NAME}%%"
  233. echo "$PETFILES" | sed -e "$pPATTERN" > /root/.packages/${DLPKG_NAME}.files
  234. install_path_check
  235. tar ${OPT} -x --strip=1 --directory=${DIRECTSAVEPATH}/ -f ${DLPKG_MAIN}.tar.${EXT} #120102. 120107. 131122
  236. fi
  237. [ $? -ne 0 ] && clean_and_die
  238. ;;
  239. *.deb)
  240. DLPKG_MAIN="`basename $DLPKG_BASE .deb`"
  241. PFILES="`dpkg-deb --contents $DLPKG_BASE | tr -s ' ' | cut -f 6 -d ' '`"
  242. [ $? -ne 0 ] && exit 1
  243. echo "$PFILES" > /root/.packages/${DLPKG_NAME}.files
  244. install_path_check
  245. dpkg-deb -x $DLPKG_BASE ${DIRECTSAVEPATH}/
  246. [ $? -ne 0 ] && clean_and_die
  247. [ -d /DEBIAN ] && rm -rf /DEBIAN #130112 precaution.
  248. dpkg-deb -e $DLPKG_BASE /DEBIAN #130112 extracts deb control files to dir /DEBIAN. may have a post-install script, see below.
  249. ;;
  250. *.tgz)
  251. DLPKG_MAIN="`basename $DLPKG_BASE .tgz`" #ex: scite-1.77-i686-2as
  252. gzip --test $DLPKG_BASE > /dev/null 2>&1
  253. [ $? -ne 0 ] && exit 1
  254. PFILES="`tar --list -z -f $DLPKG_BASE`"
  255. #hmmm, got a case where passed the above test but failed here...
  256. [ $? -ne 0 ] && exit 1
  257. echo "$PFILES" > /root/.packages/${DLPKG_NAME}.files
  258. install_path_check
  259. tar -z -x --directory=${DIRECTSAVEPATH}/ -f $DLPKG_BASE #120102. 120107
  260. [ $? -ne 0 ] && clean_and_die
  261. ;;
  262. *.txz) #100616
  263. DLPKG_MAIN="`basename $DLPKG_BASE .txz`" #ex: scite-1.77-i686-2as
  264. xz --test $DLPKG_BASE > /dev/null 2>&1
  265. [ $? -ne 0 ] && exit 1
  266. PFILES="`tar --list -J -f $DLPKG_BASE`"
  267. #hmmm, got a case where passed the above test but failed here...
  268. [ $? -ne 0 ] && exit 1
  269. echo "$PFILES" > /root/.packages/${DLPKG_NAME}.files
  270. install_path_check
  271. tar -J -x --directory=${DIRECTSAVEPATH}/ -f $DLPKG_BASE #120102. 120107
  272. [ $? -ne 0 ] && clean_and_die
  273. ;;
  274. *.tar.gz)
  275. DLPKG_MAIN="`basename $DLPKG_BASE .tar.gz`" #ex: acl-2.2.47-1-i686.pkg
  276. gzip --test $DLPKG_BASE > /dev/null 2>&1
  277. [ $? -ne 0 ] && exit 1
  278. PFILES="`tar --list -z -f $DLPKG_BASE`"
  279. [ $? -ne 0 ] && exit 1
  280. echo "$PFILES" > /root/.packages/${DLPKG_NAME}.files
  281. install_path_check
  282. tar -z -x --directory=${DIRECTSAVEPATH}/ -f $DLPKG_BASE #120102. 120107
  283. [ $? -ne 0 ] && clean_and_die
  284. ;;
  285. *.tar.bz2) #100110
  286. DLPKG_MAIN="`basename $DLPKG_BASE .tar.bz2`"
  287. bzip2 --test $DLPKG_BASE > /dev/null 2>&1
  288. [ $? -ne 0 ] && exit 1
  289. PFILES="`tar --list -j -f $DLPKG_BASE`"
  290. [ $? -ne 0 ] && exit 1
  291. echo "$PFILES" > /root/.packages/${DLPKG_NAME}.files
  292. install_path_check
  293. tar -j -x --directory=${DIRECTSAVEPATH}/ -f $DLPKG_BASE #120102. 120107
  294. [ $? -ne 0 ] && clean_and_die
  295. ;;
  296. *.pkg.tar.zx) #130314 arch pkgs.
  297. DLPKG_MAIN="`basename $DLPKG_BASE .pkg.tar.xz`" #ex: acl-2.2.51-3-i686
  298. xz --test $DLPKG_BASE > /dev/null 2>&1
  299. [ $? -ne 0 ] && exit 1
  300. PFILES="`tar --list -J -f $DLPKG_BASE`"
  301. #hmmm, got a case where passed the above test but failed here...
  302. [ $? -ne 0 ] && exit 1
  303. echo "$PFILES" > /root/.packages/${DLPKG_NAME}.files
  304. install_path_check
  305. tar -J -x --directory=${DIRECTSAVEPATH}/ -f $DLPKG_BASE
  306. [ $? -ne 0 ] && clean_and_die
  307. ;;
  308. *.rpm) #110523
  309. DLPKG_MAIN="`basename $DLPKG_BASE .rpm`"
  310. busybox rpm -qp $DLPKG_BASE > /dev/null 2>&1
  311. [ $? -ne 0 ] && exit 1
  312. PFILES="`busybox rpm -qpl $DLPKG_BASE`"
  313. [ $? -ne 0 ] && exit 1
  314. echo "$PFILES" > /root/.packages/${DLPKG_NAME}.files
  315. install_path_check
  316. #110705 rpm -i does not work for mageia pkgs...
  317. exploderpm -i $DLPKG_BASE
  318. [ $? -ne 0 ] && clean_and_die
  319. ;;
  320. esac
  321. if [ "$PUPMODE" = "2" ]; then #from BK's quirky6.1
  322. mkdir /audit/${DLPKG_NAME}DEPOSED
  323. echo -n '' > /tmp/petget/FLAGFND
  324. find ${DIRECTSAVEPATH}/ -mindepth 1 | sed -e "s%${DIRECTSAVEPATH}%%" |
  325. while read AFILESPEC
  326. do
  327. if [ -f "$AFILESPEC" ];then
  328. ADIR="$(dirname "$AFILESPEC")"
  329. mkdir -p /audit/${DLPKG_NAME}DEPOSED/${ADIR}
  330. cp -a -f "$AFILESPEC" /audit/${DLPKG_NAME}DEPOSED/${ADIR}/
  331. echo -n '1' > /tmp/petget/FLAGFND
  332. fi
  333. done
  334. sync
  335. if [ -s /tmp/petget/FLAGFND ];then
  336. [ -f /audit/${DLPKG_NAME}DEPOSED.sfs ] && rm -f /audit/${DLPKG_NAME}DEPOSED.sfs #precaution, should not happen, as not allowing duplicate installs of same pkg.
  337. mksquashfs /audit/${DLPKG_NAME}DEPOSED /audit/${DLPKG_NAME}DEPOSED.sfs
  338. fi
  339. sync
  340. rm -rf /audit/${DLPKG_NAME}DEPOSED
  341. #now write temp-location to final destination...
  342. cp -a -f --remove-destination ${DIRECTSAVEPATH}/* / 2> /tmp/petget/install-cp-errlog
  343. sync
  344. #can have a problem if want to replace a folder with a symlink. for example, got this error:
  345. # cp: cannot overwrite directory '/usr/share/mplayer/skins' with non-directory
  346. #3builddistro has this fix... which is a vice-versa situation...
  347. #firstly, the vice-versa, source is a directory, target is a symlink...
  348. CNT=0
  349. while [ -s /tmp/petget/install-cp-errlog ];do
  350. echo -n '' > /tmp/petget/install-cp-errlog2
  351. echo -n '' > /tmp/petget/install-cp-errlog3
  352. cat /tmp/petget/install-cp-errlog | grep 'cannot overwrite non-directory' | grep 'with directory' | tr '[`‘’]' "'" | cut -f 2 -d "'" |
  353. while read ONEDIRSYMLINK #ex: /usr/share/mplayer/skins
  354. do
  355. if [ -h "${ONEDIRSYMLINK}" ];then #source is a directory, target is a symlink...
  356. #adding that extra trailing / does the trick...
  357. cp -a -f --remove-destination ${DIRECTSAVEPATH}"${ONEDIRSYMLINK}"/* "${ONEDIRSYMLINK}"/ 2>> /tmp/petget/install-cp-errlog2
  358. else #source is a directory, target is a file...
  359. rm -f "${ONEDIRSYMLINK}" #delete the file!
  360. DIRPATH="$(dirname "${ONEDIRSYMLINK}")"
  361. cp -a -f ${DIRECTSAVEPATH}"${ONEDIRSYMLINK}" "${DIRPATH}"/ 2>> /tmp/petget/install-cp-errlog2 #copy directory (and contents).
  362. fi
  363. done
  364. #secondly, which is our mplayer example, source is a symlink, target is a folder...
  365. cat /tmp/petget/install-cp-errlog | grep 'cannot overwrite directory' | grep 'with non-directory' | tr '[`‘’]' "'" | cut -f 2 -d "'" |
  366. while read ONEDIRSYMLINK #ex: /usr/share/mplayer/skins
  367. do
  368. #difficult situation, whether to impose the symlink of package, or not. if not...
  369. #cp -a -f --remove-destination ${DIRECTSAVEPATH}"${ONEDIRSYMLINK}"/* "${ONEDIRSYMLINK}"/ 2> /tmp/petget/install-cp-errlog3
  370. #or, if we have chosen to follow link...
  371. DIRPATH="$(dirname "${ONEDIRSYMLINK}")"
  372. if [ -h ${DIRECTSAVEPATH}"${ONEDIRSYMLINK}" ];then #source is a symlink, trying to overwrite a directory...
  373. ALINK="$(readlink ${DIRECTSAVEPATH}"${ONEDIRSYMLINK}")"
  374. if [ "${ALINK:0:1}" = "/" ];then #test 1st char
  375. xALINK="$ALINK" #absolute
  376. else
  377. xALINK="${DIRPATH}/${ALINK}"
  378. fi
  379. if [ -d "$xALINK" ];then
  380. cp -a -f --remove-destination "${ONEDIRSYMLINK}"/* "$xALINK"/ 2>> /tmp/petget/install-cp-errlog3 #relocates target files.
  381. rm -rf "${ONEDIRSYMLINK}"
  382. cp -a -f ${DIRECTSAVEPATH}"${ONEDIRSYMLINK}" "${DIRPATH}"/ #creates symlink only.
  383. fi
  384. else #source is a file, trying to overwrite a directory...
  385. rm -rf "${ONEDIRSYMLINK}" #deleting directory!!!
  386. cp -a -f ${DIRECTSAVEPATH}"${ONEDIRSYMLINK}" "${DIRPATH}"/ #creates file only.
  387. fi
  388. done
  389. cat /tmp/petget/install-cp-errlog2 >> /tmp/petget/install-cp-errlog3
  390. cat /tmp/petget/install-cp-errlog3 > /tmp/petget/install-cp-errlog
  391. sync
  392. CNT=`expr $CNT + 1`
  393. [ $CNT -gt 10 ] && break #something wrong, get out.
  394. done
  395. #end 131220
  396. rm -rf ${DIRECTSAVEPATH} #131229 131230
  397. [ "$DL_SAVE_FLAG" != "true" ] && rm -f $DLPKG_BASE 2>/dev/null
  398. rm -f $DLPKG_MAIN.tar.gz 2>/dev/null
  399. #pkgname.files may need to be fixed...
  400. FIXEDFILES="`cat /root/.packages/${DLPKG_NAME}.files | grep -v '^\\./$'| grep -v '^/$' | sed -e 's%^\\.%%' -e 's%^%/%' -e 's%^//%/%'`"
  401. echo "$FIXEDFILES" > /root/.packages/${DLPKG_NAME}.files
  402. else
  403. [ "$DL_SAVE_FLAG" != "true" ] && rm -f $DLPKG_BASE 2>/dev/null
  404. rm -f $DLPKG_MAIN.tar.${EXT} 2>/dev/null #131122
  405. #pkgname.files may need to be fixed...
  406. FIXEDFILES="`cat /root/.packages/${DLPKG_NAME}.files | grep -v '^\\./$'| grep -v '^/$' | sed -e 's%^\\.%%' -e 's%^%/%' -e 's%^//%/%'`"
  407. echo "$FIXEDFILES" > /root/.packages/${DLPKG_NAME}.files
  408. #120102 install may have overwritten a symlink-to-dir...
  409. #tar defaults to not following symlinks, for both dirs and files, but i want to follow symlinks
  410. #for dirs but not for files. so, fix here... (note, dir entries in .files have / on end)
  411. cat /root/.packages/${DLPKG_NAME}.files | grep '[a-zA-Z0-9]/$' | sed -e 's%/$%%' | grep -v '^/mnt' |
  412. while read ONESPEC
  413. do
  414. if [ -d "${DIRECTSAVEPATH}${ONESPEC}" ];then
  415. if [ ! -h "${DIRECTSAVEPATH}${ONESPEC}" ];then
  416. DIRLINK=""
  417. if [ -h "/initrd${PUP_LAYER}${ONESPEC}" ];then #120107
  418. DIRLINK="`readlink -m "/initrd${PUP_LAYER}${ONESPEC}" | sed -e "s%/initrd${PUP_LAYER}%%"`" #PUP_LAYER: see /etc/rc.d/PUPSTATE. 120107
  419. xDIRLINK="`readlink "/initrd${PUP_LAYER}${ONESPEC}"`" #120107
  420. fi
  421. if [ ! "$DIRLINK" ];then
  422. if [ -h "/initrd${SAVE_LAYER}${ONESPEC}" ];then #120107
  423. DIRLINK="`readlink -m "/initrd${SAVE_LAYER}${ONESPEC}" | sed -e "s%/initrd${SAVE_LAYER}%%"`" #SAVE_LAYER: see /etc/rc.d/PUPSTATE. 120107
  424. xDIRLINK="`readlink "/initrd${SAVE_LAYER}${ONESPEC}"`" #120107
  425. fi
  426. fi
  427. if [ "$DIRLINK" ];then
  428. if [ -d "$DIRLINK" ];then
  429. if [ "$DIRLINK" != "${ONESPEC}" ];then #precaution.
  430. mkdir -p "${DIRECTSAVEPATH}${DIRLINK}" #120107
  431. cp -a -f --remove-destination ${DIRECTSAVEPATH}"${ONESPEC}"/* "${DIRECTSAVEPATH}${DIRLINK}/" #ha! fails if put double-quotes around entire expression.
  432. rm -rf "${DIRECTSAVEPATH}${ONESPEC}"
  433. if [ "$DIRECTSAVEPATH" = "" ];then
  434. ln -s "$xDIRLINK" "${ONESPEC}"
  435. else
  436. DSOPATH="`dirname "${DIRECTSAVEPATH}${ONESPEC}"`"
  437. DSOBASE="`basename "${DIRECTSAVEPATH}${ONESPEC}"`"
  438. rm -f "${DSOPATH}/.wh.${DSOBASE}" #allow underlying symlink to become visible on top.
  439. fi
  440. fi
  441. fi
  442. fi
  443. fi
  444. fi
  445. done
  446. #121217 it seems that this problem is occurring in other modes (13 reported)...
  447. #121123 having a problem with multiarch symlinks in full-installation...
  448. #it seems that the symlink is getting replaced by a directory.
  449. if [ "$DISTRO_ARCHDIR" ];then #in /etc/rc.d/DISTRO_SPECS. 130112 change test from DISTRO_ARCHDIR. 130114 revert DISTRO_ARCHDIR_SYMLINKS==yes.
  450. if [ -d /usr/lib/${DISTRO_ARCHDIR} ];then
  451. if [ ! -h /usr/lib/${DISTRO_ARCHDIR} ];then
  452. cp -a -f --remove-destination /usr/lib/${DISTRO_ARCHDIR}/* /usr/lib/
  453. sync
  454. rm -r -f /usr/lib/${DISTRO_ARCHDIR}
  455. ln -s ./ /usr/lib/${DISTRO_ARCHDIR}
  456. fi
  457. fi
  458. if [ -d /lib/${DISTRO_ARCHDIR} ];then
  459. if [ ! -h /lib/${DISTRO_ARCHDIR} ];then
  460. cp -a -f --remove-destination /lib/${DISTRO_ARCHDIR}/* /lib/
  461. sync
  462. rm -r -f /lib/${DISTRO_ARCHDIR}
  463. ln -s ./ /lib/${DISTRO_ARCHDIR}
  464. fi
  465. fi
  466. if [ -d /usr/bin/${DISTRO_ARCHDIR} ];then
  467. if [ ! -h /usr/bin/${DISTRO_ARCHDIR} ];then
  468. cp -a -f --remove-destination /usr/bin/${DISTRO_ARCHDIR}/* /usr/bin/
  469. sync
  470. rm -r -f /usr/bin/${DISTRO_ARCHDIR}
  471. ln -s ./ /usr/bin/${DISTRO_ARCHDIR}
  472. fi
  473. fi
  474. fi
  475. #flush unionfs cache, so files in pup_save layer will appear "on top"...
  476. if [ "$DIRECTSAVEPATH" != "" ];then
  477. #but first, clean out any bad whiteout files...
  478. # 22sep10 shinobar: bugfix was not working clean out whiteout files
  479. find /initrd/pup_rw -mount -type f -name .wh.\* -printf '/%P\n'|
  480. while read ONEWHITEOUT
  481. do
  482. ONEWHITEOUTFILE="`basename "$ONEWHITEOUT"`"
  483. ONEWHITEOUTPATH="`dirname "$ONEWHITEOUT"`"
  484. if [ "$ONEWHITEOUTFILE" = ".wh.__dir_opaque" ];then
  485. [ "`grep "$ONEWHITEOUTPATH" /root/.packages/${DLPKG_NAME}.files`" != "" ] && rm -f "/initrd/pup_rw/$ONEWHITEOUT"
  486. continue
  487. fi
  488. ONEPATTERN="`echo -n "$ONEWHITEOUT" | sed -e 's%/\\.wh\\.%/%'`"'/*' ;#echo "$ONEPATTERN" >&2
  489. [ "`grep -x "$ONEPATTERN" /root/.packages/${DLPKG_NAME}.files`" != "" ] && rm -f "/initrd/pup_rw/$ONEWHITEOUT"
  490. done
  491. #111229 /usr/local/petget/removepreview.sh when uninstalling a pkg, may have copied a file from sfs-layer to top, check...
  492. cat /root/.packages/${DLPKG_NAME}.files |
  493. while read ONESPEC
  494. do
  495. [ "$ONESPEC" = "" ] && continue #precaution.
  496. if [ ! -d "$ONESPEC" ];then
  497. [ -e "/initrd/pup_rw${ONESPEC}" ] && rm -f "/initrd/pup_rw${ONESPEC}"
  498. fi
  499. done
  500. #now re-evaluate all the layers...
  501. busybox mount -t aufs -o remount,udba=reval unionfs / #remount with faster evaluation mode.
  502. [ $? -ne 0 ] && logger -s -t "installpkg.sh" "Failed to remount aufs / with udba=reval"
  503. sync
  504. fi
  505. fi
  506. #some .pet pkgs have images at '/'...
  507. mv /*24.xpm /usr/local/lib/X11/pixmaps/ 2>/dev/null
  508. mv /*32.xpm /usr/local/lib/X11/pixmaps/ 2>/dev/null
  509. mv /*32.png /usr/local/lib/X11/pixmaps/ 2>/dev/null
  510. mv /*48.xpm /usr/local/lib/X11/pixmaps/ 2>/dev/null
  511. mv /*48.png /usr/local/lib/X11/pixmaps/ 2>/dev/null
  512. mv /*.xpm /usr/local/lib/X11/mini-icons/ 2>/dev/null
  513. mv /*.png /usr/local/lib/X11/mini-icons/ 2>/dev/null
  514. ls -dl /tmp | grep -q '^drwxrwxrwt' || chmod 1777 /tmp #130305 rerwin.
  515. #post-install script?...
  516. if [ -f /pinstall.sh ];then #pet pkgs.
  517. chmod +x /pinstall.sh
  518. cd /
  519. LANG=$LANG_USER nohup sh /pinstall.sh &
  520. sleep 0.2
  521. rm -f /pinstall.sh
  522. fi
  523. if [ -f /install/doinst.sh ];then #slackware pkgs.
  524. chmod +x /install/doinst.sh
  525. cd /
  526. LANG=$LANG_USER nohup sh /install/doinst.sh &
  527. sleep 0.2
  528. rm -rf /install
  529. fi
  530. if [ -e /DEBIAN/postinst ];then #130112 deb post-install script.
  531. cd /
  532. LANG=$LANG_USER nohup sh DEBIAN/postinst &
  533. sleep 0.2
  534. rm -rf /DEBIAN
  535. fi
  536. #130314 run arch linux pkg post-install script...
  537. if [ -f /.INSTALL ];then #arch post-install script.
  538. if [ -f /usr/local/petget/ArchRunDotInstalls ];then #precaution. see 3builddistro, script created by noryb009.
  539. #this code is taken from below...
  540. dlPATTERN='|'"`echo -n "$DLPKG_BASE" | sed -e 's%\\-%\\\\-%'`"'|'
  541. archVER="`cat /tmp/petget_missing_dbentries-Packages-* | grep "$dlPATTERN" | head -n 1 | cut -f 3 -d '|'`"
  542. if [ "$archVER" ];then #precaution.
  543. cd /
  544. mv -f .INSTALL .INSTALL1-${archVER}
  545. cp -a /usr/local/petget/ArchRunDotInstalls /ArchRunDotInstalls
  546. LANG=$LANG_USER /ArchRunDotInstalls
  547. rm -f ArchRunDotInstalls
  548. rm -f .INSTALL*
  549. fi
  550. fi
  551. fi
  552. #v424 .pet pkgs may have a post-uninstall script...
  553. if [ -f /puninstall.sh ];then
  554. mv -f /puninstall.sh /root/.packages/${DLPKG_NAME}.remove
  555. fi
  556. #w465 <pkgname>.pet.specs is in older pet pkgs, just dump it...
  557. #maybe a '$APKGNAME.pet.specs' file created by dir2pet script...
  558. rm -f /*.pet.specs 2>/dev/null
  559. #...note, this has a setting to prevent .files and entry in user-installed-packages, so install not registered.
  560. #add entry to /root/.packages/user-installed-packages...
  561. #w465 a pet pkg may have /pet.specs which has a db entry...
  562. if [ -f /pet.specs -a -s /pet.specs ];then #w482 ignore zero-byte file.
  563. DB_ENTRY="`cat /pet.specs | head -n 1`"
  564. rm -f /pet.specs
  565. else
  566. [ -f /pet.specs ] && rm -f /pet.specs #w482 remove zero-byte file.
  567. dlPATTERN='|'"`echo -n "$DLPKG_BASE" | sed -e 's%\\-%\\\\-%'`"'|'
  568. DB_ENTRY="`cat /tmp/petget_missing_dbentries-Packages-* | grep "$dlPATTERN" | head -n 1`"
  569. fi
  570. ##+++2011-12-27 KRG check if $DLPKG_BASE matches DB_ENTRY 1 so uninstallation works :Ooops:
  571. db_pkg_name=`echo "$DB_ENTRY" |cut -f 1 -d '|'`
  572. if [ "$db_pkg_name" != "$DLPKG_NAME" ];then
  573. DB_ENTRY=`echo "$DB_ENTRY" |sed "s#$db_pkg_name#$DLPKG_NAME#"`
  574. fi
  575. ##+++2011-12-27 KRG
  576. #see if a .desktop file was installed, fix category... 120628 improve...
  577. #120818 overhauled. Pkg db now has category[;subcategory] (see 0setup), xdg enhanced (see /etc/xdg and /usr/share/desktop-directories), and generic icons for all subcategories (see /usr/local/lib/X11/mini-icons).
  578. #note, similar code also in Woof 2createpackages.
  579. ONEDOT=""
  580. CATEGORY="`echo -n "$DB_ENTRY" | cut -f 5 -d '|'`" #exs: Document, Document;edit
  581. [ "$CATEGORY" = "" ] && CATEGORY='BuildingBlock' #paranoid precaution.
  582. #xCATEGORY and DEFICON will be the fallbacks if Categories entry in .desktop is invalid...
  583. xCATEGORY="`echo -n "$CATEGORY" | sed -e 's%^%X-%' -e 's%;%-%'`" #ex: X-Document-edit (refer /etc/xdg/menu/*.menu)
  584. DEFICON="`echo -n "$CATEGORY" | sed -e 's%^%mini-%' -e 's%;%-%'`"'.xpm' #ex: mini-Document-edit (refer /usr/local/lib/X11/mini-icons -- these are in jwm search path) 121206 need .xpm extention.
  585. case $CATEGORY in
  586. Calculate) CATEGORY='Business' ; xCATEGORY='X-Business' ; DEFICON='mini-Business.xpm' ;; #Calculate is old name, now Business.
  587. Develop) CATEGORY='Utility;development' ; xCATEGORY='X-Utility-development' ; DEFICON='mini-Utility-development.xpm' ;; #maybe an old pkg has this.
  588. Help) CATEGORY='Utility;help' ; xCATEGORY='X-Utility-help' ; DEFICON='mini-Help.xpm' ;; #maybe an old pkg has this.
  589. BuildingBlock) CATEGORY='Utility' ; xCATEGORY='Utility' ; DEFICON='mini-BuildingBlock.xpm' ;; #unlikely to have a .desktop file.
  590. esac
  591. topCATEGORY="`echo -n "$CATEGORY" | cut -f 1 -d ';'`"
  592. tPATTERN="^${topCATEGORY} "
  593. cPATTERN="s%^Categories=.*%Categories=${xCATEGORY}%"
  594. iPATTERN="s%^Icon=.*%Icon=${DEFICON}%"
  595. #121119 if only one .desktop file, first check if a match in /usr/local/petget/categories.dat...
  596. CATDONE='no'
  597. if [ -f /usr/local/petget/categories.dat ];then #precaution, but it will be there.
  598. NUMDESKFILE="$(grep 'share/applications/.*\.desktop$' /root/.packages/${DLPKG_NAME}.files | wc -l)"
  599. if [ "$NUMDESKFILE" = "1" ];then
  600. #to lookup categories.dat, we need to know the generic name of the package, which may be different from pkg name...
  601. #db entry format: pkgname|nameonly|version|pkgrelease|category|size|path|fullfilename|dependencies|description|compileddistro|compiledrelease|repo|
  602. DBNAMEONLY="$(echo -n "$DB_ENTRY" | cut -f 2 -d '|')"
  603. DBPATH="$(echo -n "$DB_ENTRY" | cut -f 7 -d '|')"
  604. DBCOMPILEDDISTRO="$(echo -n "$DB_ENTRY" | cut -f 11 -d '|')"
  605. [ ! "$DBCOMPILEDDISTRO" ] && DBCOMPILEDDISTRO='puppy' #any name will do here.
  606. case $DBCOMPILEDDISTRO in
  607. debian|devuan|ubuntu|raspbian)
  608. if [ "$DBPATH" ];then #precaution
  609. xNAMEONLY="$(basename ${DBPATH})"
  610. else
  611. xNAMEONLY="$DBNAMEONLY"
  612. fi
  613. ;;
  614. *) xNAMEONLY="$DBNAMEONLY" ;;
  615. esac
  616. xnPTN=" ${xNAMEONLY} "
  617. #130126 categories.dat format changed slightly... 130219 ignore case...
  618. CATVARIABLE="$(grep -i "$xnPTN" /usr/local/petget/categories.dat | grep '^PKGCAT' | head -n 1 | cut -f 1 -d '=' | cut -f 2,3 -d '_' | tr '_' '-')" #ex: PKGCAT_Graphic_camera=" gphoto2 gtkam "
  619. if [ "$CATVARIABLE" ];then #ex: Graphic-camera
  620. xCATEGORY="X-${CATVARIABLE}"
  621. cPATTERN="s%^Categories=.*%Categories=${xCATEGORY}%" #121120
  622. CATFOUND="yes"
  623. CATDONE='yes'
  624. fi
  625. fi
  626. fi
  627. for ONEDOT in `grep 'share/applications/.*\.desktop$' /root/.packages/${DLPKG_NAME}.files | tr '\n' ' '` #121119 exclude other strange .desktop files.
  628. do
  629. #120901 get rid of param on end of Exec, ex: Exec=gimp-2.8 %U
  630. #sed -i -e 's/\(^Exec=[^%]*\).*/\1/' -e 's/ *$//' $ONEDOT #'s/\(^Exec=[^ ]*\).*/\1/'
  631. #121015 01micko: alternative that may work better...
  632. for PARMATER in u U f F #refer: http://standards.freedesktop.org/desktop-entry-spec/latest/ar01s06.html
  633. do
  634. sed -i "s/ %${PARMATER}//" $ONEDOT
  635. done
  636. #w478 find if category is already valid (see also 2createpackages)..
  637. if [ "$CATDONE" = "no" ];then #121119
  638. CATFOUND="no"
  639. for ONEORIGCAT in `cat $ONEDOT | grep '^Categories=' | head -n 1 | cut -f 2 -d '=' | tr ';' ' ' | rev` #search in reverse order.
  640. do
  641. ONEORIGCAT="`echo -n "$ONEORIGCAT" | rev`" #restore rev of one word.
  642. oocPATTERN=' '"$ONEORIGCAT"' '
  643. [ "`echo "$PUPHIERARCHY" | tr -s ' ' | grep "$tPATTERN" | cut -f 3 -d ' ' | tr ',' ' ' | sed -e 's%^% %' -e 's%$% %' | grep "$oocPATTERN"`" != "" ] && CATFOUND="yes"
  644. #got a problem with sylpheed, "Categories=GTK;Network;Email;News;" this displays in both Network and Internet menus...
  645. if [ "$CATFOUND" = "yes" ];then
  646. cPATTERN="s%^Categories=.*%Categories=${ONEORIGCAT}%"
  647. break
  648. fi
  649. done
  650. #121109 above may fail, as DB_category field may not match that in .desktop file, so leave out that $tPATTERN match in $PUPHIERARCHY...
  651. if [ "$CATFOUND" = "no" ];then
  652. for ONEORIGCAT in `cat $ONEDOT | grep '^Categories=' | head -n 1 | cut -f 2 -d '=' | tr ';' ' ' | rev` #search in reverse order.
  653. do
  654. ONEORIGCAT="`echo -n "$ONEORIGCAT" | rev`" #restore rev of one word.
  655. oocPATTERN=' '"$ONEORIGCAT"' '
  656. [ "`echo "$PUPHIERARCHY" | tr -s ' ' | cut -f 3 -d ' ' | tr ',' ' ' | sed -e 's%^% %' -e 's%$% %' | grep "$oocPATTERN"`" != "" ] && CATFOUND="yes"
  657. #got a problem with sylpheed, "Categories=GTK;Network;Email;News;" this displays in both Network and Internet menus...
  658. if [ "$CATFOUND" = "yes" ];then
  659. cPATTERN="s%^Categories=.*%Categories=${ONEORIGCAT}%"
  660. break
  661. fi
  662. done
  663. fi
  664. fi
  665. sed -i -e "$cPATTERN" $ONEDOT #fix Categories= entry.
  666. #w019 does the icon exist?...
  667. ICON="`grep '^Icon=' $ONEDOT | cut -f 2 -d '='`"
  668. if [ "$ICON" != "" ];then
  669. [ -e "$ICON" ] && continue #it may have a hardcoded path.
  670. ICONBASE="`basename "$ICON"`"
  671. #110706 fix icon entry in .desktop... 110821 improve...
  672. #first search where jwm looks for icons... 111207...
  673. FNDICON="`find /usr/local/lib/X11/mini-icons /usr/share/pixmaps -maxdepth 1 -name $ICONBASE -o -name $ICONBASE.png -o -name $ICONBASE.xpm -o -name $ICONBASE.jpg -o -name $ICONBASE.jpeg -o -name $ICONBASE.gif -o -name $ICONBASE.svg | grep -i -E 'png$|xpm$|jpg$|jpeg$|gif$|svg$' | head -n 1`"
  674. if [ "$FNDICON" ];then
  675. ICONNAMEONLY="`basename $FNDICON`"
  676. iPTN="s%^Icon=.*%Icon=${ICONNAMEONLY}%"
  677. sed -i -e "$iPTN" $ONEDOT
  678. continue
  679. else
  680. #look elsewhere... 111207...
  681. FNDICON="`find /usr/share/icons /usr/local/share/pixmaps -name $ICONBASE -o -name $ICONBASE.png -o -name $ICONBASE.xpm -o -name $ICONBASE.jpg -o -name $ICONBASE.jpeg -o -name $ICONBASE.gif -o -name $ICONBASE.svg | grep -i -E 'png$|xpm$|jpg$|jpeg$|gif$|svg$' | head -n 1`"
  682. #111207 look further afield, ex parole pkg has /usr/share/parole/pixmaps/parole.png...
  683. [ ! "$FNDICON" ] && [ -d /usr/share/$ICONBASE ] && FNDICON="`find /usr/share/${ICONBASE} -name $ICONBASE -o -name $ICONBASE.png -o -name $ICONBASE.xpm -o -name $ICONBASE.jpg -o -name $ICONBASE.jpeg -o -name $ICONBASE.gif -o -name $ICONBASE.svg | grep -i -E 'png$|xpm$|jpg$|jpeg$|gif$|svg$' | head -n 1`"
  684. #111207 getting desperate...
  685. [ ! "$FNDICON" ] && FNDICON="`find /usr/share -name $ICONBASE -o -name $ICONBASE.png -o -name $ICONBASE.xpm -o -name $ICONBASE.jpg -o -name $ICONBASE.jpeg -o -name $ICONBASE.gif -o -name $ICONBASE.svg | grep -i -E 'png$|xpm$|jpg$|jpeg$|gif$|svg$' | head -n 1`"
  686. if [ "$FNDICON" ];then
  687. ICONNAMEONLY="`basename "$FNDICON"`"
  688. ln -snf "$FNDICON" /usr/share/pixmaps/${ICONNAMEONLY}
  689. iPTN="s%^Icon=.*%Icon=${ICONNAMEONLY}%"
  690. sed -i -e "$iPTN" $ONEDOT
  691. continue
  692. fi
  693. fi
  694. #substitute a default icon...
  695. sed -i -e "$iPATTERN" $ONEDOT #note, ONEDOT is name of .desktop file.
  696. fi
  697. #120926 if a langpack installed, it will have /usr/share/applications.in (see /usr/sbin/momanager, /usr/share/doc/langpack-template/pinstall.sh).
  698. ABASEDESKTOP="`basename $ONEDOT`"
  699. ADIRDESKTOP="`dirname $ONEDOT`"
  700. if [ -f /usr/share/applications.in/${ABASEDESKTOP} ];then
  701. TARGETLANG="`echo -n $LANG_USER | cut -f 1 -d '_'`" #ex: de
  702. tlPTN="^Name\[${TARGETLANG}\]"
  703. if [ "$(grep "$tlPTN" ${ADIRDESKTOP}/${ABASEDESKTOP})" = "" ];then
  704. if [ "$(grep "$tlPTN" /usr/share/applications.in/${ABASEDESKTOP})" != "" ];then
  705. #aaargh, these accursed back-slashes! ....
  706. INSERTALINE="`grep "$tlPTN" /usr/share/applications.in/${ABASEDESKTOP} | sed -e 's%\[%\\\\[%' -e 's%\]%\\\\]%'`"
  707. sed -i -e "s%^Name=%${INSERTALINE}\\nName=%" ${ADIRDESKTOP}/${ABASEDESKTOP}
  708. fi
  709. fi
  710. #do same for Comment field...
  711. tlPTN="^Comment\[${TARGETLANG}\]"
  712. if [ "$(grep "$tlPTN" ${ADIRDESKTOP}/${ABASEDESKTOP})" = "" ];then
  713. if [ "$(grep "$tlPTN" /usr/share/applications.in/${ABASEDESKTOP})" != "" ];then
  714. #aaargh, these accursed back-slashes! ....
  715. INSERTALINE="`grep "$tlPTN" /usr/share/applications.in/${ABASEDESKTOP} | sed -e 's%\[%\\\\[%' -e 's%\]%\\\\]%'`"
  716. sed -i -e "s%^Comment=%${INSERTALINE}\\nComment=%" ${ADIRDESKTOP}/${ABASEDESKTOP}
  717. fi
  718. fi
  719. #well, i suppose need this too...
  720. TARGETLANG="`echo -n $LANG_USER | cut -f 1 -d '.'`" #ex: de_DE
  721. tlPTN="^Name\[${TARGETLANG}\]"
  722. if [ "$(grep "$tlPTN" ${ADIRDESKTOP}/${ABASEDESKTOP})" = "" ];then
  723. if [ "$(grep "$tlPTN" /usr/share/applications.in/${ABASEDESKTOP})" != "" ];then
  724. #aaargh, these accursed back-slashes! ....
  725. INSERTALINE="`grep "$tlPTN" /usr/share/applications.in/${ABASEDESKTOP} | sed -e 's%\[%\\\\[%' -e 's%\]%\\\\]%'`"
  726. sed -i -e "s%^Name=%${INSERTALINE}\\nName=%" ${ADIRDESKTOP}/${ABASEDESKTOP}
  727. fi
  728. fi
  729. #do same for Comment field...
  730. tlPTN="^Comment\[${TARGETLANG}\]"
  731. if [ "$(grep "$tlPTN" ${ADIRDESKTOP}/${ABASEDESKTOP})" = "" ];then
  732. if [ "$(grep "$tlPTN" /usr/share/applications.in/${ABASEDESKTOP})" != "" ];then
  733. #aaargh, these accursed back-slashes! ....
  734. INSERTALINE="`grep "$tlPTN" /usr/share/applications.in/${ABASEDESKTOP} | sed -e 's%\[%\\\\[%' -e 's%\]%\\\\]%'`"
  735. sed -i -e "s%^Comment=%${INSERTALINE}\\nComment=%" ${ADIRDESKTOP}/${ABASEDESKTOP}
  736. fi
  737. fi
  738. fi
  739. done
  740. #due to images at / in .pet and post-install script, .files may have some invalid entries...
  741. INSTFILES="`cat /root/.packages/${DLPKG_NAME}.files`"
  742. echo "$INSTFILES" |
  743. while read ONEFILE
  744. do
  745. if [ ! -e "$ONEFILE" ];then
  746. ofPATTERN='^'"$ONEFILE"'$'
  747. grep -v "$ofPATTERN" /root/.packages/${DLPKG_NAME}.files > /tmp/petget_instfiles
  748. mv -f /tmp/petget_instfiles /root/.packages/${DLPKG_NAME}.files
  749. fi
  750. done
  751. #w482 DB_ENTRY may be missing DB_category and DB_description fields...
  752. #pkgname|nameonly|version|pkgrelease|category|size|path|fullfilename|dependencies|description|
  753. #optionally on the end: compileddistro|compiledrelease|repo| (fields 11,12,13)
  754. DESKTOPFILE="`grep '\.desktop$' /root/.packages/${DLPKG_NAME}.files | head -n 1`"
  755. if [ "$DESKTOPFILE" != "" ];then
  756. DB_category="`echo -n "$DB_ENTRY" | cut -f 5 -d '|'`"
  757. DB_description="`echo -n "$DB_ENTRY" | cut -f 10 -d '|'`"
  758. CATEGORY="$DB_category"
  759. DESCRIPTION="$DB_description"
  760. zCATEGORY="`cat $DESKTOPFILE | grep '^Categories=' | sed -e 's%;$%%' | cut -f 2 -d '=' | rev | cut -f 1 -d ';' | rev`" #121109
  761. if [ "$zCATEGORY" != "" ];then #121109
  762. #v424 but want the top-level menu category...
  763. catPATTERN="[ ,]${zCATEGORY},|[ ,]${zCATEGORY} |[ ,]${zCATEGORY}"'$' #121119 fix bug in pattern.
  764. CATEGORY="`echo "$PUPHIERARCHY" | cut -f 1 -d '#' | grep -E "$catPATTERN" | grep ':' | cut -f 1 -d ' ' | head -n 1`" #121119 /etc/xdg/menus/hierarchy
  765. fi
  766. if [ "$DB_description" = "" ];then
  767. DESCRIPTION="`cat $DESKTOPFILE | grep '^Comment=' | cut -f 2 -d '='`"
  768. [ "$DESCRIPTION" = "" ] && DESCRIPTION="`cat $DESKTOPFILE | grep '^Name=' | cut -f 2 -d '='`" # shinobar
  769. fi
  770. if [ "$DB_category" = "" -o "$DB_description" = "" ];then
  771. newDB_ENTRY="`echo -n "$DB_ENTRY" | cut -f 1-4 -d '|'`"
  772. newDB_ENTRY="$newDB_ENTRY"'|'"$CATEGORY"'|'
  773. newDB_ENTRY="$newDB_ENTRY""`echo -n "$DB_ENTRY" | cut -f 6-9 -d '|'`"
  774. newDB_ENTRY="$newDB_ENTRY"'|'"$DESCRIPTION"'|'
  775. newDB_ENTRY="$newDB_ENTRY""`echo -n "$DB_ENTRY" | cut -f 11-14 -d '|'`"
  776. DB_ENTRY="$newDB_ENTRY"
  777. fi
  778. fi
  779. echo "$DB_ENTRY" >> /root/.packages/user-installed-packages
  780. #110706 fix 'Exec filename %u' line...
  781. DESKTOPFILES="`grep '\.desktop$' /root/.packages/${DLPKG_NAME}.files | tr '\n' ' '`"
  782. for ONEDESKTOP in $DESKTOPFILES
  783. do
  784. sed -i -e 's/ %u$//' $ONEDESKTOP
  785. done
  786. #120907 post-install hacks...
  787. /usr/local/petget/hacks-postinstall.sh $DLPKG_MAIN
  788. #announcement of successful install...
  789. #announcement is done after all downloads, in downloadpkgs.sh...
  790. CATEGORY="`echo -n "$CATEGORY" | cut -f 1 -d ';'`"
  791. [ "$CATEGORY" = "" ] && CATEGORY="none"
  792. [ "$CATEGORY" = "BuildingBlock" ] && CATEGORY="none"
  793. echo "PACKAGE: $DLPKG_NAME CATEGORY: $CATEGORY" >> /tmp/petget-installed-pkgs-log
  794. #110503 change ownership of some files if non-root...
  795. #hmmm, i think this will only work if running this script as root...
  796. # (the entry script pkg_chooser.sh has sudo to switch to root)
  797. HOMEUSER="`grep '^tty1' /etc/inittab | tr -s ' ' | cut -f 3 -d ' '`" #root or fido.
  798. if [ "$HOMEUSER" != "root" ];then
  799. grep -E '^/var|^/root|^/etc' /root/.packages/${DLPKG_NAME}.files |
  800. while read FILELINE
  801. do
  802. busybox chown ${HOMEUSER}:users "${FILELINE}"
  803. done
  804. fi
  805. #120523 precise puppy needs this... (refer also rc.update and 3builddistro)
  806. if [ "`grep '/usr/share/glib-2.0/schemas' /root/.packages/${DLPKG_NAME}.files`" != "" ];then
  807. [ -e /usr/bin/glib-compile-schemas ] && /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas
  808. fi
  809. if [ "`grep '/usr/lib/gio/modules' /root/.packages/${DLPKG_NAME}.files`" != "" ];then
  810. [ -e /usr/bin/gio-querymodules ] && /usr/bin/gio-querymodules /usr/lib/gio/modules
  811. fi
  812. rm -f $HOME/nohup.out
  813. ###END###