Shellmen/old-bash-version/shellMen

198 lines
6.1 KiB
Plaintext
Raw Normal View History

2015-04-09 21:30:24 +00:00
#!/bin/bash
#
# By Maxim F. Stewart
2019-05-31 00:01:53 +00:00
# Contact: [1itdominator@gmail.com]
2015-04-09 21:30:24 +00:00
#
# Copyright 2013 Maxim F. Stewart
# 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 2 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/>.
#---------------------------------------------------------------------------------------#
2019-05-30 23:51:01 +00:00
declare -a menu=("Accessories" "Utility" "Multimedia" "Video" "Audio"
"Development" "Game" "Internet" "Network" "Graphics"
"Office" "System" "Settings" "Wine")
2015-12-10 08:20:28 +00:00
2019-05-30 23:51:01 +00:00
mainMENU() {
exec 3>&1; # Custom stream to set variable from dialog
2019-05-30 23:51:01 +00:00
INPUT=$(dialog --clear --backtitle "Shellmen" \
--title "[ M A I N - M E N U ]" \
--menu "Please Select An Option" 16 50 15 \
Accessories "General Programs" \
System "Main System Programs" \
Settings "Main System Settings" \
Multimedia "Audio & Video Programs" \
Graphics "Image Programs" \
Games "Gaming Programs" \
Office "Wordprocess & Documents Programs" \
Development "Programing Programs" \
Internet "Various Internet Related Programs" \
Wine "Windows Exe & Program Support" 2>&1 1>&3 )
2015-07-26 03:03:49 +00:00
2019-05-30 23:51:01 +00:00
case $INPUT in
Accessories) bash /tmp/sysMENU/Accessories.sh ;;
System) bash /tmp/sysMENU/System.sh ;;
Settings) bash /tmp/sysMENU/Settings.sh ;;
Multimedia) bash /tmp/sysMENU/Multimedia.sh ;;
Graphics) bash /tmp/sysMENU/Graphics.sh ;;
Games) bash /tmp/sysMENU/Game.sh ;;
Office) bash /tmp/sysMENU/Office.sh ;;
Development) bash /tmp/sysMENU/Development.sh ;;
Internet) bash /tmp/sysMENU/Internet.sh ;;
Wine) bash /tmp/sysMENU/Wine.sh ;;
Exit) echo "Bye!"; break ;;
esac
2015-04-09 21:30:24 +00:00
}
2019-05-30 23:51:01 +00:00
commandInsert() {
x=$(cat /tmp/sysMENU/menu.list | wc -l) >> /dev/null ;
2015-04-09 21:30:24 +00:00
i="1"
2015-07-26 03:03:49 +00:00
2019-05-30 23:51:01 +00:00
while [ $i -le $x ]; do
line1=$(sed -n "${i}p" /tmp/sysMENU/menu.list);
2015-07-26 03:03:49 +00:00
filename="${line1%.*}"
execMethod=$(grep -A 0 "Exec=" /usr/share/applications/"$line1")
catagory=$(grep -A 0 "Categories=" /usr/share/applications/"$line1")
preComment=$(grep -A 0 "Comment=" /usr/share/applications/"$line1")
2019-05-30 23:51:01 +00:00
execCMD=$(echo "${filename}) exec ${filename} ;;")
2019-05-31 01:34:10 +00:00
writeToPath "$catagory" "$execCMD"
2019-05-30 23:51:01 +00:00
i=$[$i++1];
2015-04-09 21:30:24 +00:00
done
2019-05-30 23:51:01 +00:00
for opt in "${menu[@]}"; do
2019-05-31 01:34:10 +00:00
if [[ $opt == "${menu[8]}" ]]; then
opt=${menu[7]}
2019-05-30 23:51:01 +00:00
fi
2019-05-31 01:34:10 +00:00
if [[ $opt == "${menu[3]}" || $opt == "${menu[4]}" ]]; then
opt=${menu[2]}
2019-05-30 23:51:01 +00:00
fi
echo "esac" >> /tmp/sysMENU/"${opt}".sh
done
2019-05-30 23:51:01 +00:00
chmod +x /tmp/sysMENU/*.sh
mainMENU;
2015-04-09 21:30:24 +00:00
}
2019-05-30 23:51:01 +00:00
menuHeaderInsert() {
x=$(cat /tmp/sysMENU/menu.list | wc -l) >> /dev/null ; # Variable set to number of lines filled in list.txt
i="1"
2015-07-26 03:03:49 +00:00
2019-05-30 23:51:01 +00:00
while [ $i -le $x ]; do
line1=$(sed -n "${i}p" /tmp/sysMENU/menu.list); # Reads the number of lines in list.txt then sets as a variable counting up to variable x
2015-07-26 03:03:49 +00:00
filename="${line1%.*}"
2019-05-30 23:51:01 +00:00
execMethod=$(grep -A 0 "Exec=" /usr/share/applications/"$line1")
2015-07-26 03:03:49 +00:00
catagory=$(grep -A 0 "Categories=" /usr/share/applications/"$line1")
preComment=$(grep -A 0 "Comment=" /usr/share/applications/"$line1")
2019-05-30 23:51:01 +00:00
comment=$(sed s/"Comment="//g <<< ${preComment})
inputer=$(echo "$filename "\"$comment"\" \\")
2019-05-31 01:34:10 +00:00
writeToPath "$catagory" "$inputer"
i=$[$i++1];
done
endMenuInsert=$(echo "2>"\"'${INPUT}'"\"")
menuitmVar=$(echo 'menuitem=$(<"${INPUT}")')
preCMD=$(echo "case \$menuitem in")
menuCall=$(echo "Main_Menu) bash /bin/shellMen ;;")
for opt in "${menu[@]}"; do
if [[ $opt == "${menu[8]}" ]]; then
opt=${menu[7]}
fi
if [[ $opt == "${menu[3]}" || $opt == "${menu[4]}" ]]; then
opt=${menu[2]}
fi
echo "$endMenuInsert" >> /tmp/sysMENU/"${opt}".sh
echo "$menuitmVar" >> /tmp/sysMENU/"${opt}".sh
echo "$preCMD" >> /tmp/sysMENU/"${opt}".sh
echo "$menuCall" >> /tmp/sysMENU/"${opt}".sh
done
commandInsert;
}
function writeToPath() {
catagory=$1
inputer=$2
2019-05-30 23:51:01 +00:00
if [[ "$catagory" == *"${menu[0]}"* ]] || [[ "$catagory" == *"${menu[1]}"* ]]; then
2019-05-31 00:01:53 +00:00
echo "$inputer" >> /tmp/sysMENU/"${menu[0]}".sh
elif [[ "$catagory" == *"${menu[2]}*" ]] \
|| [[ "$catagory" == *"${menu[3]}"* ]] \
|| [[ "$catagory" == *"${menu[4]}"* ]]; then
echo "$inputer" >> /tmp/sysMENU/"${menu[2]}".sh
2019-05-30 23:51:01 +00:00
elif [[ "$catagory" == *"${menu[5]}"* ]]; then
2019-05-31 00:01:53 +00:00
echo "$inputer" >> /tmp/sysMENU/"${menu[5]}".sh
elif [[ "$catagory" == *"${menu[6]}"* ]]; then
echo "$inputer" >> /tmp/sysMENU/"${menu[6]}".sh
2019-05-30 23:51:01 +00:00
elif [[ "$catagory" == *"${menu[7]}"* ]] || [[ "$catagory" == *"${menu[8]}"* ]] ; then
2019-05-31 00:01:53 +00:00
echo "$inputer" >> /tmp/sysMENU/"${menu[7]}".sh
2019-05-30 23:51:01 +00:00
elif [[ "$catagory" == *"${menu[9]}"* ]]; then
2019-05-31 00:01:53 +00:00
echo "$inputer" >> /tmp/sysMENU/"${menu[9]}".sh
2019-05-30 23:51:01 +00:00
elif [[ "$catagory" == *"${menu[10]}"* ]]; then
2019-05-31 00:01:53 +00:00
echo "$inputer" >> /tmp/sysMENU/"${menu[10]}".sh
elif [[ "$catagory" == *"${menu[11]}"* ]]; then
echo "$inputer" >> /tmp/sysMENU/"${menu[11]}".sh
elif [[ "$catagory" == *"${menu[12]}"* ]]; then
echo "$inputer" >> /tmp/sysMENU/"${menu[12]}".sh
elif [[ "$catagory" == *"${menu[13]}"* ]]; then
echo "$inputer" >> /tmp/sysMENU/"${menu[13]}".sh
2015-07-26 03:03:49 +00:00
fi
2015-04-09 21:30:24 +00:00
}
2019-05-31 01:34:10 +00:00
2019-05-30 23:51:01 +00:00
startScan() {
clear
mkdir /tmp/sysMENU
touch /tmp/sysMENU/menu.list ;
sed -i "d" /tmp/sysMENU/menu.list ;
ls -p /usr/share/applications/ | grep -v / >> /tmp/sysMENU/menu.list ;
header='''#!/bin/bash
INPUT=/tmp/menu.txt
2019-05-30 23:51:01 +00:00
dialog --clear --backtitle "Shellmen" \
--title "[ S U B - M E N U ]" \
--menu "Please Select An Option" 15 50 10 \
Main_Menu "Goes To Main Menu" \'''
for opt in "${menu[@]}"; do
2019-05-31 01:34:10 +00:00
if [[ $opt == "${menu[8]}" ]]; then
opt=${menu[7]}
2019-05-30 23:51:01 +00:00
fi
2019-05-31 01:34:10 +00:00
if [[ $opt == "${menu[3]}" || $opt == "${menu[4]}" ]]; then
opt=${menu[2]}
2019-05-30 23:51:01 +00:00
fi
echo "$header" > /tmp/sysMENU/"${opt}".sh
done
menuHeaderInsert;
}
pre() {
if [ -d /tmp/sysMENU/ ]; then
mainMENU;
else
startScan;
fi
}
pre;