WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Extension Profile Tool - testing  (Read 3970 times)

Offline dentonlt

  • Sr. Member
  • ****
  • Posts: 318
    • the trombone analog
Extension Profile Tool - testing
« on: December 05, 2009, 07:13:31 PM »
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

Code: [Select]
#!/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
« Last Edit: December 23, 2009, 02:35:30 AM by dentonlt »

Offline dentonlt

  • Sr. Member
  • ****
  • Posts: 318
    • the trombone analog
Re: Extension Profile Tool - testing
« Reply #1 on: December 06, 2009, 07:03:53 AM »
Now ver 0.4 ...
  • changed config directory to /home/tc/.config/profiler-0.4
  • created installer. Just reboot to base, install profiler.tcz, then run profiler -i
  • profiler now records your current settings (TCE directory) into a profile called 'default'
  • checks for base, norestore
  • self-installs to bootlocal.sh for auto-updating of 'current profile' log
  • corrected various smaller errata

Code is still quite ugly, but refining. Looking for input as available.

Code: [Select]

profiler is the Extension Profiler multi-tool.

USAGE: profiler [abcdhilnrstz] [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.
-h help view help instructions for use and installation
-i install create ~/.config/profiler-0.4 config directories and files
-l list    list existing profiles
-n next output name & list content next boot profile
-r remove remove EXTENSION from next boot profile
-s set set PROFILE as active
-t tce list contents of tce/optional
-z boot    use in bootlocal.sh to record current boot profile

Call -h for detailed help.

dentonlt, December 2009 - no warranty, typical not my fault, etc.

EDIT: removed TCZ form of script (no posting TCZ's in the forum)
« Last Edit: December 18, 2009, 09:11:58 AM by dentonlt »

Offline dentonlt

  • Sr. Member
  • ****
  • Posts: 318
    • the trombone analog
Re: Extension Profile Tool - testing
« Reply #2 on: December 18, 2009, 09:15:00 AM »
Now on to version 0.6 (still testing ...)

* some help details available
* rewritten addextension ()
* rewritting removeextension () (still under construction...)

Currently working to add a fxn that creates a tcz from the script, and puts it in the right place ...

Offline dentonlt

  • Sr. Member
  • ****
  • Posts: 318
    • the trombone analog
Re: Extension Profile Tool - testing
« Reply #3 on: December 23, 2009, 02:38:15 AM »
[log in for attachment]

Ver 0.7 - tested & running on TC 2.7

Changes:
* added confirmation on profiles backup
* stop using profiler-0.?.dep file
* update setnext(), popextension() to support links
* now checks for Tiny Core 2.7
* update deleteprofile() to replace base profile, confirm deletions
* added -m to move/rename profiles

Still updating the 'install' function.

Place the script somewhere it will get backed up, but also in the shell $PATH.