Advertisement
s243a

remove_builtin.sh

Feb 14th, 2021
458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.08 KB | None | 0 0
  1. #!/bin/bash
  2. #Barry Kauler Dec. 2010, license GPL v3 /usr/share/doc/legal.
  3. #based on a script by technosaurus, Dec. 2010.
  4. #Modified by s243a to work with an alternative root and for better cli support.
  5.  
  6. #set -x
  7.  
  8. REMOVE_BUILTIN_fixmenus=no
  9. REMOVE_BUILTIN_prompt=no
  10. CHROOT_UPDATES=no
  11. REMOVE_BUILTIN_use_gui=no
  12. CHROOT_DIR="${CHROOT_DIR:-/mnt/+aufs+devsave+test_save+ext2/Kali/kalipup_CLI.tar.gz.extracted/kalipup/puppy_upupgg+d_20.10.sfs.extracted}"
  13.  
  14. [ "`whoami`" != "root" ] && exec sudo -A ${0} ${@} #110505
  15.  
  16. export TEXTDOMAIN=remove_builtin
  17. export OUTPUT_CHARSET=UTF-8
  18. eval_gettext () {
  19. local myMESSAGE=$(gettext "$1")
  20. eval echo \"$myMESSAGE\"
  21. }
  22.  
  23. Yes_lbl="$(gettext 'Yes')"
  24. No_lbl="$(gettext 'No')"
  25.  
  26. MSG1="`gettext \"Simple utility to 'delete' packages that are builtin\nto the read-only .sfs file (Squashfs filesystem)\"`"
  27. FIXMENU='no'
  28.  
  29. D=$CHROOT_DIR/root/.packages/builtin_files
  30. D="$(realpath "$D")"
  31. [ ! -d "$D" ] && D=$CHROOT_DIR/var/packages/builtin_files
  32.  
  33. #===========================================================
  34. process_remove_builtin_list() {
  35. # count
  36. #set -x
  37. local pkglist="$1" COUNT=$(wc -l < "$1") COUNTER=0
  38. mkdir -p /tmp/deb-build/
  39. exec 15<> /tmp/deb-build/fd_15
  40.  
  41.  
  42. # process
  43. while read -r -u15 p; do
  44. echo "Processing: $p"
  45. p=${p%%#*}; eval set -- $p; p="$1"
  46. [ -z $p ] && continue
  47.  
  48. # commands
  49. COUNTER=$((COUNTER+1))
  50. echo $COUNTER of $COUNT "$@"
  51. case $p in
  52. #%exit) break ;;
  53. #%dpkg)
  54. # echo Switching to dpkg
  55. # [ -z "$WITHOUT_DPKG" ] && do_install() { dpkg_install; } ||
  56. # do_install() { dpkgchroot_install; } ;;
  57. #%dpkgchroot)
  58. # echo Switching to dpkgchroot
  59. # do_install() { dpkgchroot_install; } ;;
  60. #%bootstrap)
  61. # echo Switching to bootstrap
  62. # do_install() { bootstrap_install; } ;;
  63. #%bblinks)
  64. # shift # $1-nousr
  65. # echo Installing busybox symlinks ...
  66. # install_bb_links "$@" ;;
  67. #%makesfs)
  68. # set -x
  69. # #unbind_ALL
  70. # wait_until_unmounted || exit
  71. # shift # $1-output $@-squashfs params
  72. # echo Creating $1 ...
  73. # make_sfs "$@" ;;
  74. #%remove)
  75. # shift # $1-pkgname, pkgname, ...
  76. # remove_pkg "$@" ;;
  77. #%addbase)
  78. # echo Installing base rootfs ...
  79. # [ "$BASE_ARCH_PATH" ] && install_from_dir $BASE_ARCH_PATH base-arch core
  80. # install_from_dir $BASE_CODE_PATH base core ;;
  81. #%addpkg)
  82. # set -x
  83. # shift # $1-pkgname, pkgname ...
  84. # forced=0
  85. # PKGSECTION="optional"
  86. # while [ "$1" ]; do
  87. # case "$1" in
  88. # --forced)
  89. # forced=1
  90. # ;;
  91. # --category=*)
  92. # PKGSECTION="${1#'--category='}";
  93. # ;;
  94. # *)
  95. # ! [ -d $EXTRAPKG_PATH/$1 ] && shift && continue
  96. # echo Installing extra package "$1" ...
  97. # if [ $forced -eq 1 ]; then
  98. # install_from_dir $EXTRAPKG_PATH/$1 $1 $PKGSECTION force
  99. # else
  100. # install_from_dir $EXTRAPKG_PATH/$1 $1 $PKGSECTION
  101. # fi
  102. # ;;
  103. # esac
  104. # shift
  105. # done
  106. # set +x
  107. # ;;
  108. #%importpkg)
  109. # shift
  110. # set -x
  111. # import_from_dir $EXTRAPKG_PATH/$1
  112. # set +x
  113. # ;;
  114. #%dummy)
  115. # set -x
  116. # shift # $1-pkgname, pkgname ...
  117. # install_dummy "$@"
  118. # set +x
  119. # ;;
  120. #%dpkg_configure)
  121. # shift # $@-configure flags
  122. # DEBIAN_FRONTEND=noninteractive chroot $CHROOT_DIR /usr/bin/dpkg --configure "$@" ;;
  123. #%lock)
  124. # shift # $1-pkgname, pkgname ...
  125. # lock_pkg "$@" ;;
  126. #%cutdown)
  127. # set -x
  128. # shift # $@ various cutdown options
  129. # cutdown "$@" ;;
  130. #%import)
  131. # shift # $@ dirs to import
  132. # import_dir "$@" ;;
  133. #
  134. #### filesystem operations
  135. #%symlink)
  136. # shift # $1 source $2 target
  137. # rm -f $CHROOT_DIR/$2
  138. # ln -s $1 $CHROOT_DIR/$2
  139. # ;;
  140. #%rm)
  141. # shift # $@ files to remove
  142. # while [ "$1" ]; do
  143. # rm -rf $CHROOT_DIR/$1
  144. # shift
  145. # done
  146. # ;;
  147. #%mkdir)
  148. # shift # $@ dirs to make
  149. # while [ "$1" ]; do
  150. # mkdir -p $CHROOT_DIR/$1
  151. # shift
  152. # done
  153. # ;;
  154. #%touch)
  155. # shift # $@ files to create
  156. # while [ "$1" ]; do
  157. # > $CHROOT_DIR/$1
  158. # shift
  159. # done
  160. # ;;
  161. #%chroot)
  162. # shift # $@ commands
  163. # chroot $CHROOT_DIR "$@"
  164. # ;;
  165. #
  166. # anything else - install package
  167. *)
  168. #get_pkg_info $p
  169. #[ -z "$PKG" ] && echo Cannot find ${p}. && continue
  170. #download_pkg || { echo Download $p failed. && exit 1; }
  171. #install_pkg "$2" || { echo Installation of $p failed. && exit 1; }
  172. remove_builtin_pkg "$p"
  173. ;;
  174. esac
  175. done 15< <( cat "$pkglist" ) #< $pkglist
  176. exec 15>&-
  177. #rm /tmp/deb-build/fd_14
  178. return 0
  179. }
  180.  
  181. function remove_builtin_pkg() {
  182. PKG="$1"
  183. local NO_PKG=false
  184. if [ -z "$PKG" ] ; then
  185. return 1
  186. fi
  187. if [ ! -f $D/$PKG ] ; then
  188. echo "$PKG does not exist.." >&2
  189. #return 1 #TODO: we need alternative to "return 1" here
  190. NO_PKG=true
  191. else
  192. echo "Removing $PKG"
  193. if grep -q '\.desktop$' ${D}/${PKG}; then
  194. [ "$REMOVE_BUILTIN_fixmenus" = yes ] && FIXMENU='yes' #101222
  195. fi
  196. (
  197. while read file
  198. do
  199. rm "$CHROOT_DIR$file" 1>&2
  200. echo "${file%/*}" >&2 #get dir
  201. done < $D/$PKG
  202. ) > /tmp/remove_builtin_dirs$$
  203. #-- remove empty directories
  204. sort -ur /tmp/remove_builtin_dirs$$ | \
  205. while read dir
  206. do
  207. while [ 1 ] ; do
  208. rmdir "$dir" 2>/dev/null
  209. dir=${dir%/*} #dirname $dir
  210. if [ -z "$dir" ] ; then
  211. break
  212. fi
  213. done
  214. done
  215. #--
  216. fi
  217. PKGFILES="$D/$PKG"
  218.  
  219. if [ "$CHROOT_UPDATES" = yes ] && [ "$NO_PKG" = false ]; then
  220. if [ "`grep '/usr/share/glib-2.0/schemas' $PKGFILES`" != "" ];then
  221. [ -e /usr/bin/glib-compile-schemas ] && glib-compile-schemas /usr/share/glib-2.0/schemas
  222. fi
  223.  
  224. if [ "`grep '/usr/lib/gio/modules' $PKGFILES`" != "" ];then
  225. [ -e /usr/bin/gio-querymodules ] && gio-querymodules /usr/lib/gio/modules
  226. fi
  227.  
  228. if [ "`grep ''\.desktop$'' $PKGFILES`" != "" ];then
  229. rm -f "$CHROOT_DIR/usr/share/applications/mimeinfo.cache"
  230. [ -e /usr/bin/update-desktop-database ] && update-desktop-database /usr/share/applications
  231. fi
  232.  
  233. if [ "`grep '/usr/share/mime' $PKGFILES`" != "" ];then
  234. [ -e /usr/bin/update-mime-database ] && update-mime-database /usr/share/mime
  235. fi
  236.  
  237. if [ "`grep '/usr/share/icons/hicolor' $PKGFILES`" != "" ];then
  238. [ -e /usr/bin/gtk-update-icon-cache ] && gtk-update-icon-cache /usr/share/icons/hicolor
  239. fi
  240.  
  241. if [ "`grep '/usr/lib/gdk-pixbuf' $PKGFILES`" != "" ];then
  242. gdk-pixbuf-query-loaders --update-cache
  243. fi
  244.  
  245. if [ "`grep '/usr/lib/gconv' $PKGFILES`" != "" ];then
  246. iconvconfig
  247. fi
  248.  
  249. if [ "`grep '/usr/lib/pango' $PKGFILES`" != "" ];then
  250. pango-querymodules --update-cache
  251. fi
  252.  
  253.  
  254. for gtkver in '1.0' '2.0' '3.0'
  255. do
  256. if [ "`grep "/usr/lib/gtk-$gtkver" $PKGFILES | grep "/immodules"`" != "" ];then
  257. [ -e /usr/bin/gtk-query-immodules-$gtkver ] && gtk-query-immodules-$gtkver --update-cache
  258. fi
  259. done
  260.  
  261. if [ "`grep '/usr/share/fonts' $PKGFILES`" != "" ];then
  262. fc-cache -f
  263. fi
  264.  
  265. KERNVER="$(uname -r)"
  266.  
  267. if [ "`grep "/lib/modules/$KERNVER" $PKGFILES`" != "" ];then
  268. depmod -a
  269. fi
  270. fi
  271.  
  272. [ -f $D/$PKG ] && rm $D/$PKG
  273. [ "$NO_PKG" = false ] && rm /tmp/remove_builtin_dirs$$
  274. sed -i "\%|${PKG}|%d" "$CHROOT_DIR/root/.packages/woof-installed-packages"
  275. line="$(cat "$CHROOT_DIR/root/.packages/DISTRO_PKGS_SPECS" | grep "^yes|${PKG}|")"
  276. pkgs_str=$(echo $line | cut -d'|' -f3)
  277. pkgs=(${pkgs_str//,/" "})
  278. for a_pkg in "${pkgs[@]}"; do
  279. sed -i "\%|${a_pkg}|%d" "$CHROOT_DIR/root/.packages/woof-installed-packages"
  280. done
  281. return 0
  282. }
  283.  
  284. fix_menus() {
  285. if [ "$FIXMENU" = "yes" ];then #101222
  286. fixmenus
  287. if [ "$DISPLAY" ] ; then
  288. if [ "`pidof jwm`" != "" ] ; then
  289. jwm -reload || jwm -restart
  290. sleep 1
  291. fi
  292. fi
  293. fi
  294. }
  295.  
  296. #===========================================================
  297. # COMMAND LINE
  298. #============================================================
  299.  
  300. case $1 in
  301. -l|-list|--list)
  302. ls -1 $D
  303. exit ;;
  304. --pkg-list)
  305. shift
  306. process_remove_builtin_list "$@"
  307. exit ;;
  308. esac
  309.  
  310. if [ "$1" ] ; then
  311. for i in $@
  312. do
  313. remove_builtin_pkg $i
  314. done
  315. [ "$REMOVE_BUILTIN_fixmenus" = yes ] && fix_menus
  316. exit $?
  317. fi
  318.  
  319. #===========================================================
  320. # GUI
  321. #============================================================
  322.  
  323.  
  324. if [ REMOVE_BUILTIN_use_gui = yes ]; then
  325. PKGS=`ls -1 $D`
  326. DIALOG="dialog --aspect 10"
  327. MENUOPT="--checklist"
  328. REP=/tmp/$(basename $0).txt
  329.  
  330. if [ "$DISPLAY" ] ; then
  331. DIALOG=Xdialog
  332. fi
  333.  
  334. for i in $PKGS ; do
  335. CHOICES="$CHOICES $i . off"
  336. done
  337.  
  338. PKG=`$DIALOG --stdout --backtitle "${MSG1}" --title "$(gettext 'Remove builtin packages')" --help "$(gettext "In all modes of running Puppy, other than a full hard-drive installation,\n
  339. all of the Puppy files are in a compressed read-only file named 'puppy.sfs'\n
  340. or 'wary_500.sfs' (or some similar name). So you can't actually delete these\n
  341. files. However, if you want to remaster the live-CD to create your own custom\n
  342. Puppy (see Setup menu), you can use this little program to 'pretend' to delete\n
  343. them -- and they will really be gone in the remastered CD. So, for example if\n
  344. you remove SeaMonkey, it will be gone in the remastered CD thus reducing the\n
  345. size of the .iso live-CD file.\n\n
  346. Technical note: the lists of builtin files is at /root/.packages/builtin_files,\n
  347. the list of builtin pkgs is in /root/.packages/woof-installed-packages.")" \
  348. $MENUOPT "$(gettext 'Select packages to remove (be careful):')" 0 0 0 $CHOICES`
  349. if [ ! "$PKG" ];then
  350. exit
  351. fi
  352.  
  353. PKG=$(echo "$PKG" | sed 's%/% %g')
  354. /usr/lib/gtkdialog/box_yesno --warning "Remove builtin pkg(s)" \
  355. "Please confirm that you want to delete the following pkg(s):" "" \
  356. "<b>$PKG</b>" "" "This can be a dangerous operation if you don't know what you're doing. However some more confirmation dialogs may appear..."
  357. if [ $? -ne 0 ] ; then
  358. exit
  359. fi
  360.  
  361. #--
  362. REMOVED_PKGS=''
  363. #--
  364.  
  365. for i in $PKG
  366. do
  367. DEP_OF=`grep "+${i}" "$CHROOT_DIR/root/.packages/woof-installed-packages" |cut -d "|" -f 2 |tr "\n" " "`
  368. if [ "$DEP_OF" ] ; then
  369. DESCR="`grep "|${i}|" "$CHROOT_DIR/root/.packages/woof-installed-packages" |cut -d "|" -f 10`"
  370. Xdialog --left --screen-center --backtitle "$(gettext 'Confirm that you want to delete') '${i}'" --title "$(gettext 'Remove builtin packages')" --ok-label "$Yes_lbl" --cancel-label "$No_lbl" --yesno "$(gettext 'Description of package:')\n
  371. ${DESCR}\n
  372. $(gettext 'For information only, these are dependencies of') '${i}':\n
  373. `grep "|${i}|" "$CHROOT_DIR/root/.packages/woof-installed-packages" |cut -d "|" -f 9 | sed -e 's%^+%%' -e 's%,+% %g'`
  374. \n
  375. `eval_gettext \"Warning, removing '\\\${i}' _may_ break the following packages:\"`
  376. $DEP_OF
  377. \n
  378. $(gettext 'Continue?')" 0 0
  379. if ! [ $? -eq 0 ];then
  380. continue
  381. fi
  382. fi
  383. remove_builtin_pkg $i || continue
  384. REMOVED_PKGS="$REMOVED_PKGS $i"
  385. done
  386. fi
  387.  
  388. [ "$REMOVE_BUILTIN_fixmenus" = yes ] && fix_menus
  389.  
  390. if [ "$REMOVE_BUILTIN_use_gui" = yes ]; then
  391. if [ "${REMOVED_PKGS}" ] ; then
  392. /usr/lib/gtkdialog/box_ok "Remove builtin pkg(s)" info \
  393. "The following packages were removed:" "" "<b>${REMOVED_PKGS}</b>"
  394. fi
  395. fi
  396. ### END ###
  397.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement