EDIT:
For the script, see the most recent version at bottom of the thread.I have just finished it out, and it needs a bit [much] more testing. Seems to work, though.
Extension Profiler is a tool that modifies its own dep file to include/remove other extensions. This lets the user create individual 'profiles,' collections of extensions which load under a particular name.
Profiler
To set up:
- reboot base
- put all extensions into optional directory
- put profiler-0.3.tcz into tce directory
- run profiler -R
- run profiler -s [yournewprofile] to create a new profile
- run profiler -a [extension] to add extensions to the new profile
Extension profile is loaded on next boot. Supports:
"profiler" is the Extension Profiler multi-tool.
USAGE: profiler [abcdlnrst] [EXTENSION] [PROFILE]
-a add add EXTENSION to next boot profile
-b backup make a backup all profiles to /tmp/profiles.tar.gz
-c current output name & list content of current profile
-d delete remove PROFILE. If needed, set base as next boot.
-l list list existing profiles
-n next output name & list content next boot profile
-R reset create ~/.profiler-0.3 config directories and files
-r remove remove EXTENSION from next boot profile
-s set set PROFILE as active
-t tce list contents of tce/optional
At first, run with -R to set up.
no warranty, typical not my fault, etc.
EDIT: Now working on v0.4 - adding installer, moving config files to /home/tc/.config/ sudirectory, etc.
EDIT: Removed 0.3 files - 0.4 posted below.
profiler#!/bin/sh
[ -z "$1" ] && echo -e "\n`basename $0` is the Extension Profiler multi-tool.
\nUSAGE: `basename $0` [abcdlnrst] [EXTENSION] [PROFILE]
-a add add EXTENSION to next boot profile
-b backup make a backup all profiles to /tmp/profiles.tar.gz
-c current output name & list content of current profile
-d delete remove PROFILE. If needed, set base as next boot.
-l list list existing profiles
-n next output name & list content next boot profile
-R reset create ~/.profiler-0.3 config directories and files
-r remove remove EXTENSION from next boot profile
-s set set PROFILE as active
-t tce list contents of tce/optional
At first, run with -R to set up.
dentonlt, December 2009 - no warranty, typical not my fault, etc.
\n" && exit 1
### USEFUL VARIABLES
CONFIGDIR=/home/tc/.profiler-0.3
PROFILESDIR="$CONFIGDIR"/profiles
CURRENT=`cat "$CONFIGDIR"/current`
NEXT=`cat "$CONFIGDIR"/next`
TCEDIR=`cat /opt/.tce_dir`
OPTDIR="$TCEDIR"/optional
VERSION="profiler-0.3"
### FUNCTIONS
addextension () {
[ ! -f "$OPTDIR"/"$1" ] && echo "Could not find extension "$1" in "$OPTDIR". " && exit 1
[ "$NEXT" == "base" ] && echo "Do not add extensions to the base profile." && exit 1
if [ ! -f "$PROFILESDIR"/"$NEXT" ]; then
read -p "Could not find next boot profile ("$NEXT"). Create it? " ANS
[ "$ANS" == "n" ] || [ "$ANS" == "N" ] && echo "Exiting." && exit 1
fi
#pop dependencies:
if [ -f ""$OPTDIR"/"$1".dep" ]; then
for FILE in `cat "$OPTDIR"/"$1".dep`
do
popextension "$FILE"
done
fi
#pop the main extension file:
popextension "$1"
}
deleteprofile () {
[ ! -f "$PROFILESDIR"/"$1" ] && echo "Profile "$1" does not exist - nothing to do." && exit 1
read -p "Are you sure you want to delete profile "$1"? " ANS
if [ "$ANS" == "y" ] || [ "$ANS" == "Y" ]; then
rm "$PROFILESDIR"/"$1"
[ "$NEXT" == "$1" ] && echo "Setting profile base for next boot." && setnext "base"
exit 1
fi
echo "Exiting."
exit 1
}
popextension () {
#popextension actually pushes a filename into $NEXT
FIND=`grep "$1" "$PROFILESDIR"/"$NEXT"`
[ "$FIND" == "$NULL" ] && echo -e "`cat "$PROFILESDIR"/"$NEXT"`\noptional/"$1"" > "$PROFILESDIR"/"$NEXT"
}
setnext () {
if [ ! -f "$PROFILESDIR"/"$1" ]; then
read -p "Could not find profile "$1". Create it? " ANS
if [ "$ANS" == "y" ] || [ "$ANS" == "Y" ]; then
touch "$PROFILESDIR"/"$1"
echo "$1" > "$CONFIGDIR"/next
cp "$PROFILESDIR"/"$1" "$TCEDIR"/"$VERSION".tcz.dep
echo "Profile "$1" will be used at next boot."
else
echo "Exiting."
exit 1
fi
else
cp "$PROFILESDIR"/"$1" "$TCEDIR"/"$VERSION".tcz.dep
echo "$1" > "$CONFIGDIR"/next
NEXT="$1"
fi
}
removeextension () {
#rather than being complicated, we'll
#1. copy the old file to a temp
#2. set the temp as bootable/next
#3. read and re-pop every extension except the one we don't want
#4. mv the tmp over the old file
#5. set the remaining file as next
[ ! -f "$PROFILESDIR"/"$NEXT" ] && echo "Could not find next boot profile ("$NEXT"). Exiting." && exit 1
#catch some file names:
OLDPROFILE="$NEXT"
TMP="temporaryprofile"
#create a temp file
touch "$PROFILESDIR"/"$TMP"
#set tmp as the next boot file:
setnext "$TMP"
#loop through the old profile, adding all but the one we're removing.
for E in `cat "$PROFILESDIR"/"$OLDPROFILE"`
do
F=`basename $E`
if [ "$F" != "$1" ]; then
if [ -f ""$OPTDIR"/"$F".dep" ]; then
for FILE in `cat "$OPTDIR"/"$F".dep`
do
[ "$FILE" == "$1" ] && echo "$1 is a dependency for "$F"."
popextension "$FILE"
done
fi
popextension "$F"
fi
done
#overwrite the old file with the temp file
mv "$PROFILESDIR"/"$TMP" "$PROFILESDIR"/"$OLDPROFILE"
#res-set the "new" file as bootable
setnext "$OLDPROFILE"
}
setup () {
[ ! -d /home/tc/."$VERSION" ] && mkdir /home/tc/."$VERSION"
[ ! -d /home/tc/."$VERSION"/profiles ] && mkdir /home/tc/."VERSION"/profiles
[ ! -f /home/tc/."$VERSION"/current ] && touch /home/tc/."VERSION"/current
[ ! -f /home/tc/."$VERSION"/next ] && touch /home/tc/."VERSION"/next
[ ! -f /home/tc/."$VERSION"/profiles/base ] && touch /home/tc/."$VERSION"/profiles/base
echo "All set."
}
sortprofile () {
#put profile content into traditional, alphabetical order:
echo "`cat "$PROFILESDIR"/"$NEXT" | sort`" > "$PROFILESDIR"/"$NEXT"
}
### MAIN: just parse arguments
while getopts ":a:bcd:lnr:Rs:t" ARG; do
case $ARG in
a) addextension "$OPTARG"
sortprofile "$NEXT"
setnext "$NEXT"
;;
b) tar -czf /tmp/profiles.tar.gz "$PROFILESDIR"/*
;;
c) [ ! -f "$PROFILESDIR"/"$CURRENT" ] && echo "Error reading profile "$CURRENT". Set (-s) one before reboot!" && exit 1
echo -e "Current: $CURRENT \n `cat "$PROFILESDIR"/"$CURRENT"`" | more
;;
d) deleteprofile "$OPTARG";;
l) ls -1 "$PROFILESDIR";;
n) [ ! -f "$PROFILESDIR"/"$NEXT" ] && echo "Error reading profile "$NEXT"." && exit 1
echo -e "Next boot: $NEXT \n `cat "$PROFILESDIR"/"$NEXT"`" | more
;;
r) removeextension "$OPTARG"
sortprofile "$NEXT"
setnext "$NEXT"
;;
R) setup ;;
s) sortprofile "$NEXT"
setnext "$OPTARG"
echo "Set "$OPTARG" as next boot profile."
;;
t) ls "$OPTDIR" | more;;
*) echo "I am not smart enough to know what you meant. Send no arguments to get a help listing.";;
esac
done