Advertisement
Guest User

StratchDog64 v02 modified loadmodule STATIC

a guest
Aug 3rd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.05 KB | None | 0 0
  1. #!/bin/bash
  2. #set -x
  3. # Copyright (c) alphaOS
  4. # Written by simargl <archpup-at-gmail-dot-com> (modified for DebianDog by fredx181)
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18.  
  19. # dec 06 2016 Fred: remove cache files, e.g. icon-theme.cache
  20. # e.g. update-icon-caches will recreate them
  21. # this prevents possible problems when deactivating a module
  22.  
  23. [ "`whoami`" != "root" ] && exec gsu ${0} "$@"
  24.  
  25. #. /etc/rc.d/rc.functions
  26.  
  27. if [ "$1" = "" ] || [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
  28. echo -en "This script will (de)activate a module 'On the Fly', e.g. *.squashfs, *.xzm or *.sfs.\nUsage:\n`basename ${0}` -a </path/to/module> to activate or: \n`basename ${0}` -ano </path/to/module> for activating in 'not overwrite' mode or:\n`basename ${0}` -d </path/to/module> to deactivate \n"
  29. exit 0
  30. fi
  31.  
  32. if [ -f /mnt/live/tmp/modules ]; then
  33. CHNGS=/mnt/live/memory/images
  34. NUM=`mount | grep /mnt/live/memory/images | wc -l`
  35. else
  36. CHNGS=/live
  37. NUM=`blkid -o list -c /dev/null | grep -P "squashfs" | grep "/live/\|(in use)" | wc -l`
  38. fi
  39.  
  40. ext=`echo "${2##*.}"`
  41. echo $ext
  42.  
  43. POSITION="$((${NUM} + 1))"
  44.  
  45. check_bundle_defined()
  46. {
  47. if [ ! $BUNDLE ]; then
  48. echo -e $Red"ERROR:"$Color_Off" Please define bundle name to de/activate"
  49. exit 1
  50. fi
  51. }
  52.  
  53. get_bundle_load_positon()
  54. {
  55. if [ ! $BUNDLE_POSITION ]; then
  56. POSITION="1"
  57. else
  58. POSITION=$(echo $BUNDLE_POSITION | sed 's|^--||g')
  59. fi
  60. }
  61.  
  62. check_if_onaufs()
  63. {
  64. APPDIR=$(dirname "$BUNDLE")
  65. ALINE=$(df -m "$APPDIR"|tail -n1| tr -s ' ')
  66. MYPLACE=$(echo $ALINE| cut -d' ' -f1)
  67. APPDEV=$(echo $MYPLACE| grep '^/dev/')
  68.  
  69. if [ -z "$APPDEV" ]; then
  70. yad --text " ERROR: Trying to activate on the virtual storage, \n but $BUNDLE must be placed on an actual storage. " --button="gtk-close:0"
  71. exit 1
  72. fi
  73. }
  74.  
  75. check_if_exists()
  76. {
  77. if [ ! -f $BUNDLE ]; then
  78. echo -e $Red"ERROR:"$Color_Off" Module '$BUNDLE' does not exist"
  79. exit 1
  80. fi
  81. }
  82.  
  83. check_if_deactivated()
  84. {
  85. if [ -d $CHNGS/$BUNDLE ]; then
  86. echo -e $Red"ERROR:"$Color_Off" Module '$BUNDLE' is already activated"
  87. yad --title="LoadModule" --center --width="400" --text=" Module '$BUNDLE' is already activated \n To activate in another mode (e.g. 'not overwrite' mode): \n Deactivate the module first. " --button="gtk-close:0"
  88. exit 1
  89. fi
  90. }
  91.  
  92. check_if_activated()
  93. {
  94. if [ ! -d $CHNGS/$BUNDLE ]; then
  95. echo -e $Red"ERROR:"$Color_Off" Module '$BUNDLE' is not currently activated"
  96. yad --title="LoadModule" --center --width="400" --text=" Module '$BUNDLE' is not currently activated " --button="gtk-close:0"
  97. exit 1
  98. fi
  99. }
  100.  
  101. post_actions_check_if_needed()
  102. {
  103. MODULES=$(ls $CHNGS/$BUNDLE/lib/modules 2>/dev/null)
  104. ICONS=$(ls $CHNGS/$BUNDLE/usr/share/icons/hicolor 2>/dev/null)
  105. DESKTOP=$(ls $CHNGS/$BUNDLE/usr/share/applications 2>/dev/null)
  106. DESKTOP1=$(ls $CHNGS/$BUNDLE/usr/local/share/applications 2>/dev/null)
  107. GSETTINGS=$(ls $CHNGS/$BUNDLE/usr/share/glib-2.0/schemas 2>/dev/null)
  108. FONTS=$(ls $CHNGS/$BUNDLE/usr/share/fonts/TTF 2>/dev/null)
  109. MIME=$(ls $CHNGS/$BUNDLE/usr/share/mime/ 2>/dev/null)
  110. }
  111.  
  112. post_actions_run_list()
  113. {
  114. if [ "$MODULES" ]; then
  115. echo -e $Green"ACTION:"$Color_Off" updating loadable kernel modules list"
  116. depmod -a
  117. fi
  118. if [ "$MIME" ]; then
  119. echo -e $Green"ACTION:"$Color_Off" updating mime cache"
  120. update-mime-database /usr/share/mime &>/dev/null 2>&1
  121. fi
  122. if [ "$ICONS" ]; then
  123. echo -e $Green"ACTION:"$Color_Off" rebuilding the gtk+ icon cache"
  124. update-icon-caches /usr/share/icons/* &>/dev/null 2>&1
  125. gtk-update-icon-cache --force /usr/share/icons/hicolor &>/dev/null 2>&1
  126. fi
  127. if [ "$DESKTOP" ]; then
  128. echo -e $Green"ACTION:"$Color_Off" updating mimeinfo cache"
  129. update-desktop-database &>/dev/null 2>&1
  130. rm -r $HOME/.cache &>/dev/null 2>&1
  131. fi
  132. if [ "$DESKTOP1" ]; then
  133. echo -e $Green"ACTION:"$Color_Off" updating mimeinfo cache"
  134. update-desktop-database /usr/local/share/applications &>/dev/null 2>&1
  135. rm -r $HOME/.cache &>/dev/null 2>&1
  136. fi
  137. if [ "$GSETTINGS" ]; then
  138. echo -e $Green"ACTION:"$Color_Off" gsettings xml schema files"
  139. glib-compile-schemas /usr/share/glib-2.0/schemas &>/dev/null 2>&1
  140. fi
  141. if [ "$FONTS" ]; then
  142. echo -e $Green"ACTION:"$Color_Off" updating font cache"
  143. fc-cache -f -s > /dev/null
  144. mkfontscale /usr/share/fonts/TTF
  145. mkfontdir /usr/share/fonts/TTF
  146. fi
  147. }
  148.  
  149. bundle_activate()
  150. {
  151. check_if_onaufs
  152. check_bundle_defined
  153. if [ "$ext" = "sfs" ]; then
  154. yad --title="LoadModule" --center --width="400" --text=" This module has .sfs extension (possibly made for puppy linux) \n There's a chance it will work but it could also break the system \n Continue? " --button="gtk-yes:0" --button="gtk-no:1"
  155. ret=$?
  156. [[ $ret -eq 1 ]] && exit 0
  157. fi
  158. check_if_exists
  159. check_if_deactivated
  160.  
  161. # get_bundle_load_positon
  162. mkdir $CHNGS/$BUNDLE
  163. ##mount -o loop $BUNDLE $CHNGS/$BUNDLE
  164. # FOLLOWING 2 LINES were added by trister
  165. losetup /dev/loop62 $BUNDLE
  166. mount /dev/loop62 $CHNGS/$BUNDLE
  167.  
  168. mount -n -o remount,add:$POSITION:$CHNGS/$BUNDLE=rr+wh aufs /
  169. if [ $? -eq 0 ]; then
  170. echo -e $Green"SUCCESS:"$Color_Off" Module '$BUNDLE' activated"
  171. yad --title="LoadModule" --center --width="400" --text=" SUCCESS: Module '$BUNDLE' activated " --button="gtk-close:0" &
  172. post_actions_check_if_needed
  173. ### remove cache files, will be recreated further in script
  174. ICONCACHE=$(find $CHNGS/$BUNDLE/usr/share/icons -type f -name icon-theme.cache)
  175. RMCACHE=$(echo $ICONCACHE | sed "s|$CHNGS/$BUNDLE||g")
  176. rm -f $RMCACHE
  177. if [ "$MIME" ]; then
  178. [ -f $CHNGS/$BUNDLE/usr/share/mime/mime.cache ] && rm -f /usr/share/mime/mime.cache 2>/dev/null
  179. fi
  180.  
  181. post_actions_run_list
  182. update-menus
  183. # Ugly workaround for OpenBox version to update the menu:
  184. # Create a .desktop in /usr/share/applications with random name and remove it directly
  185. FILE=$RANDOM
  186. touch /usr/share/applications/$FILE.desktop && rm -f /usr/share/applications/$FILE.desktop
  187. touch /usr/local/share/applications/$FILE.desktop && rm -f /usr/local/share/applications/$FILE.desktop
  188. exit 0
  189. else
  190. echo -e $Red"ERROR:"$Color_Off" Module '$BUNDLE' activate failed"
  191. yad --title="LoadModule" --center --width="400" --text=" ERROR: Module '$BUNDLE' activate failed " --button="gtk-close:0" &
  192. umount $CHNGS/$BUNDLE
  193. rmdir $CHNGS/$BUNDLE
  194. exit 1
  195. fi
  196. }
  197.  
  198. bundle_deactivate()
  199. {
  200. set -x
  201. check_bundle_defined
  202. check_if_activated
  203. post_actions_check_if_needed
  204. mount -t squashfs -n -o remount,del:$CHNGS/$BUNDLE aufs /
  205. umount $CHNGS/$BUNDLE
  206. rmdir $CHNGS/$BUNDLE
  207. if [ $? -eq 0 ]; then
  208. yad --title="LoadModule" --center --width="400" --text=" SUCCESS: Module '$BUNDLE' deactivated " --button="gtk-close:0" &
  209. post_actions_run_list
  210. update-menus
  211. # Ugly workaround for OpenBox version to update the menu:
  212. # Create a .desktop in /usr/share/applications with random name and remove it directly
  213. FILE=$RANDOM
  214. touch /usr/share/applications/$FILE.desktop && rm -f /usr/share/applications/$FILE.desktop
  215. touch /usr/local/share/applications/$FILE.desktop && rm -f /usr/local/share/applications/$FILE.desktop
  216. exit 0
  217. else
  218. # Force unmount
  219. echo "Unmounting failed, so lets find out (by 'aubusy') which process is keeping it from unloading and kill it..."
  220. while read line; do
  221. PID=$(echo "$line" | awk '{ print $1 }' 2> /dev/null)
  222. PROCESS=$(ps -eo pid,cmd | grep $PID | grep -v "grep" | awk '{ print $2 }')
  223. # Do not kill X
  224. [ "$PROCESS" = "/usr/bin/X" ] && break
  225. kill $(echo "$line" | awk '{ print $1 }') 2> /dev/null
  226. echo "$line" | awk '{ print $1 }'
  227. sleep 1
  228. done <<< "$(aubusy -v / $CHNGS/$BUNDLE)"
  229. #fuser -mkv $CHNGS/$BUNDLE
  230. echo
  231. echo "Ok, let's try unloading again now..."
  232. mount -t squashfs -n -o remount,del:$CHNGS/$BUNDLE aufs /
  233. umount $CHNGS/$BUNDLE
  234. rmdir $CHNGS/$BUNDLE
  235. if [ $? -ne 0 ]; then
  236. echo -e $Red"ERROR:"$Color_Off" Module '$BUNDLE' deactivate failed"
  237. yad --title="LoadModule" --center --width="400" --text=" ERROR: Module '$BUNDLE' deactivate failed " --button="gtk-close:0" &
  238. exit 0
  239. else
  240. echo -e $Green"SUCCESS:"$Color_Off" Module '$BUNDLE' deactivated"
  241. yad --title="LoadModule" --center --width="400" --text=" SUCCESS: Module '$BUNDLE' deactivated " --button="gtk-close:0" &
  242. post_actions_run_list
  243. update-menus
  244. # Ugly workaround for OpenBox version to update the menu:
  245. # Create a .desktop in /usr/share/applications with random name and remove it directly
  246. FILE=$RANDOM
  247. touch /usr/share/applications/$FILE.desktop && rm -f /usr/share/applications/$FILE.desktop
  248. fi
  249. fi
  250. }
  251.  
  252. case "$1" in
  253.  
  254. -a)
  255. BUNDLE="$2"
  256. case $BUNDLE in
  257.  
  258. *.xzm|*.squashfs|*.sfs|*.sb)
  259. cd "`dirname "$BUNDLE"`"
  260. BUNDLE="`basename "$2"`"
  261. POSITION=1
  262. bundle_activate
  263. ;;
  264. *)
  265. yad --center --title="LoadModule" --text=" Not a valid module file, \n Please run again." --button="gtk-close:0"
  266. exit 0
  267. ;;
  268. esac
  269. ;;
  270. -ano)
  271. BUNDLE="$2"
  272. case $BUNDLE in
  273.  
  274. *.xzm|*.squashfs|*.sfs|*.sb)
  275. cd "`dirname "$BUNDLE"`"
  276. BUNDLE="`basename "$2"`"
  277. POSITION=$POSITION
  278. bundle_activate
  279. ;;
  280. *)
  281. yad --center --title="LoadModule" --text=" Not a valid module file, \n Please run again." --button="gtk-close:0"
  282. exit 0
  283. ;;
  284. esac
  285. ;;
  286. -d)
  287. BUNDLE="$2"
  288. case $BUNDLE in
  289.  
  290. *.xzm|*.squashfs|*.sfs|*.sb)
  291. cd "`dirname "$BUNDLE"`"
  292. BUNDLE=`basename "$2"`
  293. cd "`dirname "$BUNDLE"`"
  294. bundle_deactivate
  295. ;;
  296. *)
  297. yad --center --title="LoadModule" --text=" Not a valid module file, \n Please run again." --button="gtk-close:0"
  298. exit 0
  299. ;;
  300. esac
  301. ;;
  302. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement