Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #set -x
- # Copyright (c) alphaOS
- # Written by simargl <archpup-at-gmail-dot-com> (modified for DebianDog by fredx181)
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
- # dec 06 2016 Fred: remove cache files, e.g. icon-theme.cache
- # e.g. update-icon-caches will recreate them
- # this prevents possible problems when deactivating a module
- [ "`whoami`" != "root" ] && exec gsu ${0} "$@"
- #. /etc/rc.d/rc.functions
- if [ "$1" = "" ] || [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
- 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"
- exit 0
- fi
- if [ -f /mnt/live/tmp/modules ]; then
- CHNGS=/mnt/live/memory/images
- NUM=`mount | grep /mnt/live/memory/images | wc -l`
- else
- CHNGS=/live
- NUM=`blkid -o list -c /dev/null | grep -P "squashfs" | grep "/live/\|(in use)" | wc -l`
- fi
- ext=`echo "${2##*.}"`
- echo $ext
- POSITION="$((${NUM} + 1))"
- check_bundle_defined()
- {
- if [ ! $BUNDLE ]; then
- echo -e $Red"ERROR:"$Color_Off" Please define bundle name to de/activate"
- exit 1
- fi
- }
- get_bundle_load_positon()
- {
- if [ ! $BUNDLE_POSITION ]; then
- POSITION="1"
- else
- POSITION=$(echo $BUNDLE_POSITION | sed 's|^--||g')
- fi
- }
- check_if_onaufs()
- {
- APPDIR=$(dirname "$BUNDLE")
- ALINE=$(df -m "$APPDIR"|tail -n1| tr -s ' ')
- MYPLACE=$(echo $ALINE| cut -d' ' -f1)
- APPDEV=$(echo $MYPLACE| grep '^/dev/')
- if [ -z "$APPDEV" ]; then
- yad --text " ERROR: Trying to activate on the virtual storage, \n but $BUNDLE must be placed on an actual storage. " --button="gtk-close:0"
- exit 1
- fi
- }
- check_if_exists()
- {
- if [ ! -f $BUNDLE ]; then
- echo -e $Red"ERROR:"$Color_Off" Module '$BUNDLE' does not exist"
- exit 1
- fi
- }
- check_if_deactivated()
- {
- if [ -d $CHNGS/$BUNDLE ]; then
- echo -e $Red"ERROR:"$Color_Off" Module '$BUNDLE' is already activated"
- 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"
- exit 1
- fi
- }
- check_if_activated()
- {
- if [ ! -d $CHNGS/$BUNDLE ]; then
- echo -e $Red"ERROR:"$Color_Off" Module '$BUNDLE' is not currently activated"
- yad --title="LoadModule" --center --width="400" --text=" Module '$BUNDLE' is not currently activated " --button="gtk-close:0"
- exit 1
- fi
- }
- post_actions_check_if_needed()
- {
- MODULES=$(ls $CHNGS/$BUNDLE/lib/modules 2>/dev/null)
- ICONS=$(ls $CHNGS/$BUNDLE/usr/share/icons/hicolor 2>/dev/null)
- DESKTOP=$(ls $CHNGS/$BUNDLE/usr/share/applications 2>/dev/null)
- DESKTOP1=$(ls $CHNGS/$BUNDLE/usr/local/share/applications 2>/dev/null)
- GSETTINGS=$(ls $CHNGS/$BUNDLE/usr/share/glib-2.0/schemas 2>/dev/null)
- FONTS=$(ls $CHNGS/$BUNDLE/usr/share/fonts/TTF 2>/dev/null)
- MIME=$(ls $CHNGS/$BUNDLE/usr/share/mime/ 2>/dev/null)
- }
- post_actions_run_list()
- {
- if [ "$MODULES" ]; then
- echo -e $Green"ACTION:"$Color_Off" updating loadable kernel modules list"
- depmod -a
- fi
- if [ "$MIME" ]; then
- echo -e $Green"ACTION:"$Color_Off" updating mime cache"
- update-mime-database /usr/share/mime &>/dev/null 2>&1
- fi
- if [ "$ICONS" ]; then
- echo -e $Green"ACTION:"$Color_Off" rebuilding the gtk+ icon cache"
- update-icon-caches /usr/share/icons/* &>/dev/null 2>&1
- gtk-update-icon-cache --force /usr/share/icons/hicolor &>/dev/null 2>&1
- fi
- if [ "$DESKTOP" ]; then
- echo -e $Green"ACTION:"$Color_Off" updating mimeinfo cache"
- update-desktop-database &>/dev/null 2>&1
- rm -r $HOME/.cache &>/dev/null 2>&1
- fi
- if [ "$DESKTOP1" ]; then
- echo -e $Green"ACTION:"$Color_Off" updating mimeinfo cache"
- update-desktop-database /usr/local/share/applications &>/dev/null 2>&1
- rm -r $HOME/.cache &>/dev/null 2>&1
- fi
- if [ "$GSETTINGS" ]; then
- echo -e $Green"ACTION:"$Color_Off" gsettings xml schema files"
- glib-compile-schemas /usr/share/glib-2.0/schemas &>/dev/null 2>&1
- fi
- if [ "$FONTS" ]; then
- echo -e $Green"ACTION:"$Color_Off" updating font cache"
- fc-cache -f -s > /dev/null
- mkfontscale /usr/share/fonts/TTF
- mkfontdir /usr/share/fonts/TTF
- fi
- }
- bundle_activate()
- {
- check_if_onaufs
- check_bundle_defined
- if [ "$ext" = "sfs" ]; then
- 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"
- ret=$?
- [[ $ret -eq 1 ]] && exit 0
- fi
- check_if_exists
- check_if_deactivated
- # get_bundle_load_positon
- mkdir $CHNGS/$BUNDLE
- ##mount -o loop $BUNDLE $CHNGS/$BUNDLE
- # FOLLOWING 2 LINES were added by trister
- losetup /dev/loop62 $BUNDLE
- mount /dev/loop62 $CHNGS/$BUNDLE
- mount -n -o remount,add:$POSITION:$CHNGS/$BUNDLE=rr+wh aufs /
- if [ $? -eq 0 ]; then
- echo -e $Green"SUCCESS:"$Color_Off" Module '$BUNDLE' activated"
- yad --title="LoadModule" --center --width="400" --text=" SUCCESS: Module '$BUNDLE' activated " --button="gtk-close:0" &
- post_actions_check_if_needed
- ### remove cache files, will be recreated further in script
- ICONCACHE=$(find $CHNGS/$BUNDLE/usr/share/icons -type f -name icon-theme.cache)
- RMCACHE=$(echo $ICONCACHE | sed "s|$CHNGS/$BUNDLE||g")
- rm -f $RMCACHE
- if [ "$MIME" ]; then
- [ -f $CHNGS/$BUNDLE/usr/share/mime/mime.cache ] && rm -f /usr/share/mime/mime.cache 2>/dev/null
- fi
- post_actions_run_list
- update-menus
- # Ugly workaround for OpenBox version to update the menu:
- # Create a .desktop in /usr/share/applications with random name and remove it directly
- FILE=$RANDOM
- touch /usr/share/applications/$FILE.desktop && rm -f /usr/share/applications/$FILE.desktop
- touch /usr/local/share/applications/$FILE.desktop && rm -f /usr/local/share/applications/$FILE.desktop
- exit 0
- else
- echo -e $Red"ERROR:"$Color_Off" Module '$BUNDLE' activate failed"
- yad --title="LoadModule" --center --width="400" --text=" ERROR: Module '$BUNDLE' activate failed " --button="gtk-close:0" &
- umount $CHNGS/$BUNDLE
- rmdir $CHNGS/$BUNDLE
- exit 1
- fi
- }
- bundle_deactivate()
- {
- set -x
- check_bundle_defined
- check_if_activated
- post_actions_check_if_needed
- mount -t squashfs -n -o remount,del:$CHNGS/$BUNDLE aufs /
- umount $CHNGS/$BUNDLE
- rmdir $CHNGS/$BUNDLE
- if [ $? -eq 0 ]; then
- yad --title="LoadModule" --center --width="400" --text=" SUCCESS: Module '$BUNDLE' deactivated " --button="gtk-close:0" &
- post_actions_run_list
- update-menus
- # Ugly workaround for OpenBox version to update the menu:
- # Create a .desktop in /usr/share/applications with random name and remove it directly
- FILE=$RANDOM
- touch /usr/share/applications/$FILE.desktop && rm -f /usr/share/applications/$FILE.desktop
- touch /usr/local/share/applications/$FILE.desktop && rm -f /usr/local/share/applications/$FILE.desktop
- exit 0
- else
- # Force unmount
- echo "Unmounting failed, so lets find out (by 'aubusy') which process is keeping it from unloading and kill it..."
- while read line; do
- PID=$(echo "$line" | awk '{ print $1 }' 2> /dev/null)
- PROCESS=$(ps -eo pid,cmd | grep $PID | grep -v "grep" | awk '{ print $2 }')
- # Do not kill X
- [ "$PROCESS" = "/usr/bin/X" ] && break
- kill $(echo "$line" | awk '{ print $1 }') 2> /dev/null
- echo "$line" | awk '{ print $1 }'
- sleep 1
- done <<< "$(aubusy -v / $CHNGS/$BUNDLE)"
- #fuser -mkv $CHNGS/$BUNDLE
- echo
- echo "Ok, let's try unloading again now..."
- mount -t squashfs -n -o remount,del:$CHNGS/$BUNDLE aufs /
- umount $CHNGS/$BUNDLE
- rmdir $CHNGS/$BUNDLE
- if [ $? -ne 0 ]; then
- echo -e $Red"ERROR:"$Color_Off" Module '$BUNDLE' deactivate failed"
- yad --title="LoadModule" --center --width="400" --text=" ERROR: Module '$BUNDLE' deactivate failed " --button="gtk-close:0" &
- exit 0
- else
- echo -e $Green"SUCCESS:"$Color_Off" Module '$BUNDLE' deactivated"
- yad --title="LoadModule" --center --width="400" --text=" SUCCESS: Module '$BUNDLE' deactivated " --button="gtk-close:0" &
- post_actions_run_list
- update-menus
- # Ugly workaround for OpenBox version to update the menu:
- # Create a .desktop in /usr/share/applications with random name and remove it directly
- FILE=$RANDOM
- touch /usr/share/applications/$FILE.desktop && rm -f /usr/share/applications/$FILE.desktop
- fi
- fi
- }
- case "$1" in
- -a)
- BUNDLE="$2"
- case $BUNDLE in
- *.xzm|*.squashfs|*.sfs|*.sb)
- cd "`dirname "$BUNDLE"`"
- BUNDLE="`basename "$2"`"
- POSITION=1
- bundle_activate
- ;;
- *)
- yad --center --title="LoadModule" --text=" Not a valid module file, \n Please run again." --button="gtk-close:0"
- exit 0
- ;;
- esac
- ;;
- -ano)
- BUNDLE="$2"
- case $BUNDLE in
- *.xzm|*.squashfs|*.sfs|*.sb)
- cd "`dirname "$BUNDLE"`"
- BUNDLE="`basename "$2"`"
- POSITION=$POSITION
- bundle_activate
- ;;
- *)
- yad --center --title="LoadModule" --text=" Not a valid module file, \n Please run again." --button="gtk-close:0"
- exit 0
- ;;
- esac
- ;;
- -d)
- BUNDLE="$2"
- case $BUNDLE in
- *.xzm|*.squashfs|*.sfs|*.sb)
- cd "`dirname "$BUNDLE"`"
- BUNDLE=`basename "$2"`
- cd "`dirname "$BUNDLE"`"
- bundle_deactivate
- ;;
- *)
- yad --center --title="LoadModule" --text=" Not a valid module file, \n Please run again." --button="gtk-close:0"
- exit 0
- ;;
- esac
- ;;
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement