Hello!!
i have made a script that allows to have several menues with different
configuration, and you can change to a new menu during blackbox is
playing.
it's very usefull be able to work with a specific menu.If you are to
use internet you can change to your own internet menu, if you want to
draw, you can change to the graphic menu...
I hope you like it.
What's up
Changemenu is a very simple script make in bash.
How use it
---------------
The only function is to do envairoment blackbox better.
Blackbox use .blackboxrc for take info about users menu. User menu is
make middly TAG. "Changemenu" include a new TAG into menu that do appear a new
folder whit all menues. You can configure the menu to your prefer menu in real
time.
It's more usefull to can work with a specialicity menu. With
"changemenu" you can work with internet menu if you are useing internet,
graphic menu if you are working in graphic aplication...
Contents
---------
"Changemenu"is in "Chinstall" script. This script create and change some files.
If you execute "Chinstall", you can see this:
-h : Display this help.
-v : Display the version
-u : Uninstall
-z : Delete uninstall information
-i : Install
Installation:
--------------
During installation the script do this:
1. Modify the session.menuFile line in .blackboxrc, addresing this line to a
link file named "link".
2. The "chinstall" program extracts itself sources in order to generate
"changemenu" script. This script is been installed in /bin/ if you are
UID=0, else in $HOME. If this file already exists in the handable path for
user then no install "changemenu" file.
This script is used to find the path where are the menues and to change the
link for pointing to $1 parameter.
The reason that makes necesarilly find the path each time is :
a) The program this way can be played for different users.
b) There are programs that change the path of menues.
c) Anyway this proccess is quite fast
3. The "chinstall" script make two menues examples: internet and graphic
and change the standart menu, including at the same time, a new folder with
all menues.
4. The "chinstall" script open a menu-of-menu file. (see bellow how to
include menues).
5. The "chinstall" script change itself to keep the uninstall information.
6. Creates in $HOME a Log file with all install changes.
* Onces the program has been installed you have to click on reestart in
Blackbox.
* The script can be install as many time as you want but it only keeps
the uninstall information the first time.
WARNED: If you want change or delete the uninstall insformation, you have to
play "chinstall -z" and the script will be reseted.
Uninstall:
----------
The uninstallation undo all said above. The uninstall information is deleted
too.
Only if you are UID=0 you can delete "changemenu" script of /bin/, but it
will warn you that could be another users playing it.
* The uninstall information ( -z ) will be deleted automatically if the
script doesn't find a previous installation ( The chinstall script was
modificated before with uninstall information)
Add/Delete Menues
-----------------
To add a new menu file you only have to follow :
1. It creates the new menu file into the menues folder. ( You can see the
path in .blackboxrc ).
It's important that the following line be included into the new menu:
[include] (path_of_menues/menu-of-menu)
2. Edit menu-of-menu and include in the follow:
[exec] (NewMenuName) {path_of_menues/NameOfNewMenuFile}
3. Restart Blackbox.
Anyway it's easier to see the example menues.
BUG REPORT:
When it changes to a new menu you have to click restart in Blackbox. That's
make it cool-less.
The only way I find to change the menu automatically is modificating the
Blackbox sourcer but it's not a clean way.
Although same times when you change to new menu it change automatically ¿?
Can anyone explain me it ?
The reason to make the program in bash is to learning it.
I'm not programer expert so any constructing critique will make me feel
better.
Any problems, ideas or help:
[EMAIL PROTECTED] Spain(Malaga)01
Read it whit attention:
############################################################################
# Chinstall and changemenu 2001
# [EMAIL PROTECTED] Spain(Malaga)
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#!/bin/bash
VERSION="0.5"
LOG="$HOME/Log_of_Changemenu"
PROGNAME="changemenu"
NEW="link" #The name of ln -s
NAME="menu-of-menu" #Name of new submenu that is include in menu
INSTALLPATH="/bin/" #It can chage if the user don't have UID=0
#In this case INSTALLPATH is $HOME and
#PROGNAME is the same name but hide.
#If exists PROGNAME in INSTALLPATH or in
#All user's path then no install PROGNAME
#only configure the blackbox file's
UNINFO=`grep -c "#UNINSTALL-" $0`
function version
{
echo
echo "Changemenu $VERSION"
echo " by [EMAIL PROTECTED] 2001 Spain(Malaga)"
echo "It's too easy if you try :-)"
}
function help
{
echo "PLEASE READ THE README FILE BEFORE INSTALL IT"
echo "Hothelp of Install"
echo "Create and modific the sourcer enaugh for execute Changemenu"
echo "Changemenu can dinamic change of menu in Blackbox "
echo "command: "
echo " -h, --help : display this help and exit"
echo " -v, --version : display script version"
echo " -u, --uninstall : unistall all the change"
echo " -z, --zero : delete in $0 the unistall information"
echo " you have to do it if you wont restart unistall"
echo " configuration."
echo " If you never execute this script and it has unistall"
echo " information, -z active alone."
echo " -i : Install this script"
echo
version;
}
function deluninstall
{
if [ $UNINFO = 4 ]; then
p=`grep -n "#UNINSTALL-" $0 | cut -c0-3 | tail -n1`
let p=$p-1
head -n$p $0 > tmpt
chmod 771 tmpt
mv -f tmpt $0
fi
}
#This is a Changemenu script, the install script copy it in a new file
#If you delete lines or add lines then you have to change who much line
#have grep in -ANN now NN is 19
function Changemenu
{
#Change the menu in Blackbox
new="link"
if [ -f $HOME/.blackboxrc ]; then
line=`grep session.menuFile $HOME/.blackboxrc | cut -c18-100`
longline=`expr length $line`
actualmenu=`basename $line`
longmenu=`expr length $actualmenu`
n=`expr $longline - $longmenu`
pathmenu=`echo $line | cut -c0-$n`
else
echo "Sorry but I can't find .blackboxrc in your path"
exit
fi
if ! [ $# = 0 ]; then
if [ -f $pathmenu$1 ]; then
new="$pathmenu$new"
rm -f $new
\ln -s $pathmenu$1 $new
fi
fi
}
function intromenu
{
if ! [ $# = 0 ]; then
newline="session.menuFile: ";
newline=$newline$pathmenu$1
grep -v session.menuFile $HOME/.blackboxrc > $HOME/tmpt
echo $newline >> $HOME/tmpt
mv -f $HOME/tmpt $HOME/.blackboxrc
fi
}
function noinstall
{
if [ $UNINFO = 4 ]; then
echo "$PROGNAME is goint to uninstall..."
pathmenu=`tail -n6 $0 | cut -c2-100 | head -n1`
actualmenu=`tail -n5 $0 | cut -c2-100 | head -n1`
arch=`tail -n4 $0 | cut -c2-100 | head -n1`
rm -f $pathmenu$arch
arch=`tail -n3 $0 | cut -c2-100 | head -n1`
rm -f $pathmenu$arch
arch=`tail -n2 $0 | cut -c2-100 | head -n1`
rm -f $pathmenu$arch
rm -f $pathmenu$NEW
progname=`tail -n1 $0 | cut -c2-100`
intromenu $actualmenu
p=`grep -n "#Change by Changemenu" $pathmenu$actualmenu | cut -c1-2`
let p=$p-1
head -n$p $pathmenu$actualmenu > $HOME/tmpt
let p=$p+2
p2=`cat -n $pathmenu$actualmenu | tail -n1 | cut -c0-6`
p2=`echo $p2`
let p=$p2-$p
tail -n$p $pathmenu$actualmenu>> $HOME/tmpt
mv -f $HOME/tmpt $pathmenu$actualmenu
rm -f $LOG
if [ $UID = 0 ]; then
echo "Can be that other users need $progname."
echo -n "Do you won't delete it ? (y/n):"
read arch
if [ $arch = "y" ] || [ $arch = "Y" ]; then
rm -f $progname
fi
else
rm -f $progname
fi
deluninstall
echo "All change have been uninstalling."
else
echo "Sorry, you can't uninstall the changes becouse the uninstall info
don't exists."
fi
}
function Installpath
{
if ! [ $UID = 0 ]; then
if [ -f "$INSTALLPATH$PROGNAME" ]; then
OK="TRUE"
else
if [ -f $HOME/.$PROGNAME ]; then
OK="TRUE" #No install the PROGNAME
else
OK=""
fi
INSTALLPATH="$HOME/" #Only for user
PROGNAME=".$PROGNAME" #Make hide the file
fi
fi
}
function Installing
{
Changemenu
Changemenu $actualmenu
intromenu link #Now the vble are update's
Installpath
echo "CHANGE MENU INSTALLATION">$LOG
UNIST=""
if [ $UNINFO = 3 ] || [ -z $OK ]; then
if [ -z $OK ]; then
echo "The old uninstall information there was delete">>$LOG
deluninstall
fi
UNIST="TRUE"
fi
if [ -f $pathmenu$actualmenu ]; then
if [ $UNIST ]; then
echo "It's the first time that you execute $0">>$LOG
echo "$0 is autochanging for keep the unistall information">>$LOG
echo "#UNINSTALL- INFORMATION #############################">>$0;
echo "#$pathmenu">>$0;
echo "#$actualmenu">>$0;
else
echo "You had executed $0 more times">$LOG
echo "The unistall information was keeped jet">>$LOG
fi
n=`grep -c "#Change by Changemenu" $pathmenu/$actualmenu`
if [ $n = 0 ]; then
Num=`grep -n "begin" $pathmenu/$actualmenu | cut -c1-2 | sort -r | head -n1`
let Num=$Num+1
head -n$Num $pathmenu$actualmenu > tmpt
echo "#Change by Changemenu" >> tmpt
echo "[include] ($pathmenu$NAME)" >> tmpt
Num2=`cat -n $pathmenu$actualmenu | tail -n1 | cut -c0-6`
Num=`expr $Num2 - $Num`
tail -n$Num $pathmenu$actualmenu >> tmpt
mv -f tmpt $pathmenu$actualmenu
echo "Insert a new line in $pathmenu$actualmenu (Your menu)">>$LOG
else
echo "!!No chage in $pathmenu$actualmenu, it is update yet" >>$LOG
fi
else
echo "!!ERROR : Don't exixst the file named $actualmenu in $pathmenu"
echo " But is like defult in your .blackboxrc"
echo " Create this file or change in .blackboxrc a Good menu file"
exit
fi
#Install example menu
##########################################################################
g="graphic"
echo "[begin] (Graphic)" >$pathmenu$g
echo "[exec] (xterm) {xterm -ls}" >>$pathmenu$g
echo "#Change by Changemenu" >>$pathmenu$g
echo "[include] ($pathmenu$NAME)" >>$pathmenu$g
echo "[exec] (XV) {xv}" >>$pathmenu$g
echo "[exec] (The Gimp) {gimp}" >>$pathmenu$g
echo "[exec] (Image Magick) {display}" >>$pathmenu$g
echo "[exit] (Exit)" >>$pathmenu$g
echo "[end]" >>$pathmenu$g
echo "Install $g menu file in $pathmenu">> $LOG
if [ $UNIST ]; then
echo "#$g">>$0
fi
########################################################
g="internet"
echo "[begin] (Internet)" >$pathmenu$g
echo "[exec] (xterm) {xterm -ls}" >>$pathmenu$g
echo "#Change by Changemenu" >>$pathmenu$g
echo "[include] ($pathmenu$NAME)">>$pathmenu$g
echo "[exec] (Netscape) {netscape}" >>$pathmenu$g
echo "[submenu] (more...)" >>$pathmenu$g
echo " [exec] (Netscape Mail) {netscape -mail}" >>$pathmenu$g
echo " [exec] (Netscape News) {netscape -news" >>$pathmenu$g
echo " [exec] (Netscape Composer) {netscape -edit}" >>$pathmenu$g
echo "[end]" >>$pathmenu$g
echo "[exec] (pppd) {pppd}" >>$pathmenu$g
echo "[exit] (Exit)" >>$pathmenu$g
echo "[end]" >>$pathmenu$g
echo "Install $g menu file in $pathmenu">> $LOG
if [ $UNIST ]; then
echo "#$g">>$0
fi
#######################################################
#Generando NAME
echo "[submenu] (Menu)">$pathmenu$NAME
echo " [exec] (Standart) {$INSTALLPATH$PROGNAME $actualmenu}">>$pathmenu$NAME
echo " [exec] (Graphic) {$INSTALLPATH$PROGNAME graphic}">>$pathmenu$NAME
echo " [exec] (Internet) {$INSTALLPATH$PROGNAME internet}">>$pathmenu$NAME
echo " [restart] (ReStart)">>$pathmenu$NAME
echo "[end]">>$pathmenu$NAME
echo "Install $NAME file in $pathmenu">> $LOG
echo "This file have to be like a [include] in all menu source">>$LOG
if [ $UNIST ]; then
echo "#$NAME">>$0
fi
##########################################################################
if [ $OK ]; then
echo "Exists $PROGNAME in $INSTALLPATH jet" >> $LOG
if [ $UNIST ]; then
echo "#noname" >>$0
fi
else
#Insert the function Changemenu like a new file
echo "Install $PROGNAME in $INSTALLPATH and change attributes to +x" >> $LOG
echo "#!/bin/bash" > $INSTALLPATH$PROGNAME
grep -A19 ^#Change $0 >> $INSTALLPATH$PROGNAME
chmod +x $INSTALLPATH$PROGNAME
if [ $UNIST ]; then
echo "#$INSTALLPATH$PROGNAME">>$0
fi
fi
echo >> $LOG
echo "The script is install now. Restart BlackBox and you can see a new">> $LOG
echo "file named menu in your standart menu.">> $LOG
echo "Choose your mode menu and then press restart." >> $LOG
echo "In $pathmenu you can find tree example of menu.">> $LOG
echo "For add menues edit $pathmenu$NAME">> $LOG
echo >>$LOG
echo "It has opened a new file named $LOG in your path that has this text">> $LOG
echo>> $LOG
echo "It's too esasy if you try.... :)">> $LOG
echo " [EMAIL PROTECTED] Spain(Malaga)01">> $LOG
echo "Sorry for my english but i speak badly :-)">> $LOG
cat $LOG
}
#Option's
if [ $# = 0 ]; then
help;
else
case $1 in
"-v" | "--version" )version ;;
"-h" | "--help" )help ;;
"-i" )Installing ;;
"-z" | "--zero" )deluninstall ;;
"-u" | "--uninstall" )noinstall ;;
esac
fi