[SCRIPT] Easy module activation

Post tutorials, HOWTO's and other useful resources here.
Post Reply
User avatar
brokenman
Site Admin
Site Admin
Posts: 5436
Joined: 27 Dec 2010, 03:50
Distribution: Porteus v3.2rcX all desktops
Location: Brazil
Contact:

[SCRIPT] Easy module activation

Post#1 by brokenman » 29 Dec 2010, 02:49

This is a very simple script i wrote to make activating modules an easy task for me. I store all of my modules in the optional folder like my own personal repo. Sometimes i pre-pend the modules with the subject of their use. For example office-gcalc.lzm office-kwrite.lzm etc.

I can activate all of my office modules with one simple command:

Code: Select all

act office
Another method is to keep all the required modules in one folder. For example a folder called filezilla would contain filezilla.lzm and libtasn.lzm.

With this script i just need to open a terminal and enter

Code: Select all

act filezill
The script will look into my optional folder (and all subfolders) for a close match to whatever i enter and activate what is found. It uses a wild card so i don't need to remember the exact name of the module, i only have to get the first couple of characters correct. E.g act filezi

USAGE:
--------------------
act filezilla

SETUP:
--------------------
Copy the script into a file and save the file to your /usr/bin/ directory (call it act)
Make the script executable: chmod +x /usr/bin/act
Now it is ready to use.

EDITS:
--------------------
If you don't use the optional folder to store your modules then edit the path to your modules in the script. It is well commented so you shouldn't have any problem finding the place to edit.

Code: Select all

#!/bin/bash
# Script by jayflood
# Script to activate modules in the slax optional folder and sub folders.
# You can prepend all your OFFICE apps with 'office' (e.g office-gcalc.lzm)
# and activate them with <script> <office>
# or you can put all your office apps in a folder called 'office'
# and they will all be activated with <script> <office>

script=${0##*/}
USER=`whoami`
CONFIG="/$USER/.kde/share/config/slxscriptsrc"
CONFPATH="/$USER/.kde/share/config"

usage()
{
cat <<EOF

-------------
USAGE:
$script <module>
$script <folder>
$script remove
-------------

If the module exists in specified directory then module
will be activated.

If the folder exists in specified path then all modules
within folder will be activated.

If the 'remove' switch is used your config file is deleted

The script uses a wildcard. 
$script bluetoo = $script bluetooth

In this case any folder called bluetooth will have modules
inside activated, or modules called bluetooth.lzm found
anywhere within the specified folder (or sub folders) will
be activated.

EOF
}

# if nothing is entered after script then show usage
if [ $# -eq 0 ]; then
	usage
	exit 1
fi

if [ -f $CONFIG -a $1 == "remove" ]; then
	rm -f $CONFIG
	echo "$CONFIG file has been removed"
	exit 1
fi

# Check if config file exists
if [ -f $CONFIG ]; then
	MODULES=$(grep -A1 "[modfolder]" $CONFIG | tail -1)
		else
			touch $CONFIG
			echo "[modfolder]" > $CONFIG
			echo
			echo ---------------------------------------
			echo "Please enter the full path to the folder"
			echo "where your optional modules are stored."
			echo "For example: /mnt/hda1/slax/optional"
			echo 
			echo "You will only need to enter this this once "
			echo "and a config file will be created. To remove"
			echo "The config file use: $script remove"
			read optf
			echo "$optf" >> $CONFIG
		MODULES=$(grep -A1 '[modfolder]' $CONFIG | tail -1)
fi

# If the input matches a directory then activate all within
if [ -d $MODULES/$1* ]; then

for fold in $( find $MODULES/$1* -name "*.lzm");
	do activate $fold;
		NUM=$( find $MODULES/$1* -name "*.lzm" | wc -l)
			done
		echo 
	echo "$NUM modules were activated"
exit
fi

# If the input matches a module then activate
if [ -f $MODULES/$1*.lzm ]; then

for mod in $( find $MODULES -name $1*.lzm);
	do activate $mod;
done
exit
fi

# If this point is reached then the input entered did not match
# a module or a folder and the script will exit gracefully.
echo
echo "Nothing matching your input ($1) was found !!"
echo
exit
How do i become super user?
Wear your underpants on the outside and put on a cape.

User avatar
francois
Contributor
Contributor
Posts: 4901
Joined: 28 Dec 2010, 14:25
Distribution: kde xfce porteus manjaro kubun
Location: Enfin l'été, le changement climatique attendu: le soleil.

Re: [SCRIPT] Easy module activation

Post#2 by francois » 02 May 2011, 03:15

A great tool so to prevent the loading of less often used packages.

Good tool.
Thanks.

P.S. Bump
Voltaire: Le mieux est l'ennemi du bien.

Post Reply