PageRenderTime 55ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/trkinitrd/bin/trkmenu

https://bitbucket.org/harakiri/trk
#! | 480 lines | 377 code | 103 blank | 0 comment | 0 complexity | 6f5ee247e3aec548ed0742c08ba4ed8b MD5 | raw file
Possible License(s): GPL-2.0, MIT, LGPL-3.0
  1. #!/bin/bash
  2. #set -x
  3. # Menu version 1.0 / 19 January 2010
  4. # This script creates a menu with submenus
  5. # The menu can be integrated in the script (example below), or loaded from an external file. In the first case run the script without parameter.
  6. # To load an external menu, give the path to the file as first (and only) parameter.
  7. # The external file must have a content similar to the menu definition below (between the =========== lines).
  8. #
  9. # To create the menu add your menu lines with the command "addmenu"
  10. # Each command takes four arguments (the fourth is optional) :
  11. # 1) The menu identifier
  12. # 2) The text of the menu
  13. # 3) The command itself (compound commands are allowed)
  14. # 4) An optional commentary.
  15. # In the commentary you can use the codes \n, \t and so on (see man echo for details).
  16. # You can use colors in the menus and commentaries (examples below; create the colors you need with similar code in the section delimited by +++++)
  17. # If you use the RESET command twice in a menu option the cursor will not be redrawned after the second occurence.
  18. # To suppress the "Press any key to continue" message, add :
  19. # eval NOSTOP=1;
  20. # at the beginning of your command
  21. # To change the menu, the function is : changeMenu with the menu identifier as first argument
  22. # Navigate the menu with up and down arrow keys
  23. # The left arrow key always go back to the main menu
  24. export TRKMENU=on
  25. BUILD=`cat /etc/build`
  26. # base color codes
  27. OPEN="\033[" # open color
  28. BLACKFG="${OPEN}30m" # black foreground
  29. REDFG="${OPEN}31m" # red foreground
  30. GREENFG="${OPEN}32m" # green foreground
  31. BROWNFG="${OPEN}33m" # brown foreground
  32. BLUEFG="${OPEN}34m" # blue foreground
  33. MAGNFG="${OPEN}35m" # magenta (purple) foreground
  34. CYANFG="${OPEN}36m" # cyan (light blue) foreground
  35. GRAYFG="${OPEN}37m" # gray foreground
  36. BLACKBG="${OPEN}40m" # black background
  37. REDBG="${OPEN}41m" # red background
  38. GREENBG="${OPEN}42m" # green background
  39. BROWNBG="${OPEN}43m" # brown background
  40. BLUEBG="${OPEN}44m" # blue background
  41. MAGNBG="${OPEN}45m" # magenta background
  42. CYANBG="${OPEN}46m" # cyan background
  43. WHITEBG="${OPEN}47m" # white background
  44. RESET="${OPEN}0m" # reset all attributes to their defaults
  45. BOLD="${OPEN}1m" # set bold
  46. BLINK="${OPEN}5m" # set blink
  47. REVID="${OPEN}7m" # set reverse video
  48. NORM="${OPEN}22m" # set normal intensity
  49. BLOFF="${OPEN}25m" # blink off
  50. REVOFF="${OPEN}27m" # reverse video off
  51. SEP=";" # color separator
  52. # ++++++++++++++++ Colors definitions +++++++++++++++++++++
  53. # Add the colors you need here
  54. # compound codes
  55. TITON="${BLUEFG}${BOLD}" # open title
  56. CURSAON="${BLUEBG}${GRAYFG}" # Main menu cursor color
  57. CURSBON="${BROWNBG}${GRAYFG}" # Other menus cursor color
  58. # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  59. #uparrow=$'\x1b[A'
  60. #downarrow=$'\x1b[B'
  61. #leftarrow=$'\x1b[D'
  62. #rightarrow=$'\x1b[C'
  63. firstcode=$'\x1b'
  64. uparrow='A'
  65. downarrow='B'
  66. leftarrow='D'
  67. rightarrow='C'
  68. LINE=0
  69. LINEA=0
  70. CURSON=$CURSAON
  71. function addmenu {
  72. a='[${#menu'
  73. b='[*]}]'
  74. eval "menu${1}${a}${1}${b}=\$2"
  75. eval "menu${1}1${a}${1}${b}=\$3"
  76. eval "menu${1}2${a}${1}${b}=\$4"
  77. }
  78. function changeMenu {
  79. a='( "${menu'
  80. b='[@]}" )'
  81. eval "menu=${a}${1}${b}"
  82. eval "menu1=${a}${1}1${b}"
  83. eval "menu2=${a}${1}2${b}"
  84. if [ $1 = $MAINMENU ]
  85. then
  86. LINE=$LINEA
  87. CURSON=$CURSAON
  88. else
  89. LINEA=$LINE
  90. LINE=0
  91. CURSON=$CURSBON
  92. fi
  93. if [ -z $NOSTOP ];
  94. then
  95. NOSTOP=0
  96. else
  97. NOSTOP=1
  98. fi;
  99. }
  100. #Get command line arguments
  101. if [ -e "$1" ]
  102. then
  103. source $1
  104. else
  105. # =========================== Create the Menu ======================================================================
  106. # Below are the menus
  107. # Long commentaries are easier to insert as variables. Let us define them first.
  108. C_partimage="${CURSAON}Easy partimage${RESET} ${TITON}is a script which allows you to quickly and easily
  109. \nset the parameters for partimage which will save an image of your partition
  110. \non a local or network drive.
  111. \n\tEasy partimage can be setup as a fully automatic partition saving tool
  112. \n\tPlease read the documentation for details${RESET}"
  113. C_TRKHELP="In this menu you will find options to online or offline TRK documentation. Please note that any i
  114. \ncommand has its own specific manpage. E.g. for help on winpass, type 'man winpass'"
  115. C_KEYBOARD="Select your keyboard language here"
  116. C_WINPASS="Use winpass to reset your password. Recommended is to just remove the password. This is the most
  117. \nsure method.
  118. \nYou can also restore your original password database here."
  119. C_MOUNTALLFS="Use this to search and mount all local filesystems on this computer. Filesystems will be mounted in the root according to their device id.
  120. \nE.g. /dev/sda1 will be mounted on /sda1
  121. \n(command: mountallfs)"
  122. C_UMOUNTALLFS="Unmounts all partitions mounted with the previous command. Make sure no other programs are opened on it anymore
  123. \n(command: umountallfs)"
  124. C_VIRUSSCAN="Scan your local computer for viruses with 5 different engines and clean them. See the help on
  125. \nvirusscan for more info"
  126. C_WINCLEAN="With 'winclean' you can tidy up your Windows PC by getting rid of all sorts of unused files.
  127. \nThis can clean up a considerable amount of disk space and speed up your computer."
  128. C_MCLONE="Mclone is a powerful utility that permits you to clone an entire computer over the network to i
  129. \nmultiple computers at the same time.
  130. \nIt uses multicast technology so cloning 1 or 100 computers at a time doesn't make a difference. "
  131. C_FILESERVER="This will run a Windows fileserver which will mount and share all of your local disks on your LAN"
  132. C_SSHSERVER="Remotely connect to your TRK by means of secure shell.
  133. \nA good windows ssh client would be the free Putty (just google it)
  134. \n(command: ssh-server)"
  135. C_SETIP="Set an ip address on your first ethernet adapter if you didn't get one from DHCP
  136. \n(command: setip eth0)"
  137. C_TRKBOOTNET="Run a TRK bootserver to boot other TRKs from your LAN.
  138. \nThis will only work if there are no other bootservers on your LAN and you have a working DHCP server
  139. \n(command: trkbootnet)"
  140. C_SNIFF="Monitor what's going on on your network.
  141. \nRecommend you split the network in 2, hang each side to 1 of 2 network cards on this computer,
  142. \nbridge them together and see what passes
  143. \nSo once you've done the physical part, descend into this menu, bring the bridge up and run tcpdump"
  144. C_SCRIPT="This uses the 'script' utility to record all output (stdout as well as stderr) of your console to a file.
  145. \nThis can be handy when you need to send a bugreport and record the output of the error
  146. \nTo return to this menu afterwards, just type 'exit'"
  147. C_WELCOME="${BLUEFG}${BOLD}Welcome to Trinity Rescue Kit 3.4 build $BUILD ${RESET}
  148. \nThis simple menu allows you to perform simple actions that don't require any Linux knowledge and
  149. \ngets things done in a quick and rather dirty way.
  150. \nIf you need a command line you can switch to the 5 other consoles by pressing ALT+<F2 to F6> or use 'Go to a shell' below"
  151. C_AVAST="For this particular AV engine you need a registered, free license key which is sent to you by mail.
  152. \n Get it at http://www.avast.com/registration-free-antivirus.php
  153. \n If you want to avoid entering the license key each time, it's recommened to run updatetrk
  154. \n(command: virusscan -a avs)"
  155. C_HALT="Power down the computer. At the end you will have a 10 second option to either immediately poweroff, restart or go to a shell
  156. \n(command: halt)"
  157. C_BACKUP="Several utilities that allow you to take a backup of your local disks"
  158. TITLE="${TITON} Trinity Rescue Kit easy menu ${RESET}" # Title of the menu
  159. test -e /etc/trkmotd && C_MOTD="$C_WELCOME
  160. \n${BOLD}`cat /etc/trkmotd`${RESET}"
  161. addmenu "A" "Welcome" "eval NOSTOP=1;" "$C_MOTD"
  162. addmenu "A" "TRK Help -->" "changeMenu B" "$C_TRKHELP"
  163. addmenu "A" "Keyboard layout selection -->" "eval NOSTOP=1; drakkeyboard" "$C_KEYBOARD"
  164. addmenu "A" "Windows password resetting -->" "changeMenu C" "$C_WINPASS"
  165. addmenu "A" "Mount all local filesystems" "mountallfs" "$C_MOUNTALLFS"
  166. addmenu "A" "Unmount all local filesystems" "eval echo \"Unmounting...\"; umountallfs" "$C_UMOUNTALLFS"
  167. addmenu "A" "Virus scanning -->" "changeMenu D" "$C_VIRUSSCAN"
  168. addmenu "A" "Windows junkfile cleaning -->" "changeMenu E" "$C_WINCLEAN"
  169. addmenu "A" "Mclone: computer replication over the network -->" "changeMenu G" "$C_MCLONE"
  170. addmenu "A" "Backup and restore utilities-->" "changeMenu I" "$C_BACKUP"
  171. addmenu "A" "Run a windows fileserver -->" "changeMenu F" "$C_FILESERVER"
  172. addmenu "A" "Run an ssh server" "ssh-server" "$C_SSHSERVER"
  173. addmenu "A" "Set an ip-address on the first adapter" "setip eth0" "$C_SETIP"
  174. addmenu "A" "TRK Network boot server" "trkbootnet" "$C_TRKBOOTNET"
  175. addmenu "A" "Trinity Remote Support (contact us first)" "eval NOSTOP=1; trinisup" "$C_TRINISUP"
  176. addmenu "A" "Ethernet packet sniffing -->" "changeMenu H" "$C_SNIFF"
  177. addmenu "A" "Try detecting more harddisk controllers" "tryscsi"
  178. addmenu "A" "Try detecting more USB and PCMCIA network adapters" "trypcmcia"
  179. addmenu "A" "Midnight Commander" "eval NOSTOP=1; mc" "MC is a well known file manager \n(command: mc)"
  180. addmenu "A" "Go to a shell" "eval NOSTOP=1; bash" "To return to this menu afterwards, just type 'exit'"
  181. addmenu "A" "Go to a shell and save all output to /tmp/terminal.out" "eval NOSTOP=1; script -a /tmp/terminal.out" "$C_SCRIPT"
  182. addmenu "A" "Quit this menu" "exit" "You can always quit with CTRL+C"
  183. addmenu "A" "Poweroff computer" "halt" "$C_HALT"
  184. addmenu "A" "Reboot without ejecting CD / usb stick" "reboot-no-eject"
  185. addmenu "B" "<-- Go back to main menu" "changeMenu A" # Menu B TRK Help
  186. addmenu "B" "Offline web help" "trkhelp -l" "(command: trkhelp -l)"
  187. addmenu "B" "Offline text help" "trkhelp -l -t" "(command: trkhelp -l -t)"
  188. addmenu "B" "Online web help" "trkhelp" "(command: trkhelp)"
  189. addmenu "C" "<-- Go back to main menu" "changeMenu A" # Menu C Winpass
  190. addmenu "C" "Reset password on built-in Administrator (default action)" "winpass" "(command: winpass)"
  191. addmenu "C" "Interactive winpass" "winpass -i" "(command: winpass -i)"
  192. addmenu "C" "Winpass with prompt for username first" "winpass-u"
  193. addmenu "C" "Restore original password database" "winpass --restore" "(command: winpass --restore)"
  194. addmenu "C" "Help on winpass" "man winpass"
  195. addmenu "D" "<-- Go back to main menu" "changeMenu A" # Menu D Virusscan
  196. addmenu "D" "Set the scan destination (if not set: all local drives)" "destination-prompt"
  197. addmenu "D" "Scan with Clam AV" "virusscan -a clam $destination" "(command: virusscan -a clam)"
  198. addmenu "D" "Scan with F-Prot" "virusscan -a fprot $destination" "(command: virusscan -a fprot)"
  199. addmenu "D" "Scan with BitDefender" "virusscan -a bde $destination" "(command: virusscan -a bde)"
  200. addmenu "D" "Scan with Vexira" "virusscan -a va $destination" "(command: virusscan -a va)"
  201. addmenu "D" "Scan with Avast (license key needed first)" "virusscan -a avs $destination" "$C_AVAST"
  202. addmenu "D" "Help on virusscan" "man virusscan"
  203. addmenu "E" "<-- Go back to main menu" "changeMenu A" # Menu E Winclean
  204. addmenu "E" "Set the clean destination (if not set: all local drives)" "destination-prompt"
  205. addmenu "E" "Safe clean tempfiles (any file older than 1 day in tempfolders" "winclean -s 1 $destination" "(command: winclean -s 1)"
  206. addmenu "E" "Clean up all tempfiles" "winclean -R -t $destination" "(command: winclean -R -t)"
  207. addmenu "E" "Clean all recycle bins" "winclean -R -r $destination" "(command: winclean -R -r)"
  208. addmenu "E" "Remove all uninstall folders from cumulative patches (only effective on XP)" "winclean -R -u $destination" "(command: winclean -R -u)"
  209. addmenu "E" "Empty Windows dllcache folder" "winclean -R -c $destination" "(command: winclean -R -c)"
  210. addmenu "E" "Remove hanging printerjobs (spoolfiles)" "winclean -R -p $destination" "(command: winclean -R -p)"
  211. addmenu "E" "Clean up javacache (Sun java)" "winclean -R -j $destination" "(command: winclean -R -j)"
  212. addmenu "E" "CLEAN IN ALL OF THE ABOVE CATEGORIES" "winclean -R -a $destination" "(command: winclean -R -a)"
  213. addmenu "E" "Help on winclean" "man winclean"
  214. addmenu "F" "<-- Go back to main menu" "changeMenu A"
  215. addmenu "F" "Run an unsecure fileserver in guest mode" "fileserver -g" "(command: fileserver -g)" # Menu F Fileserver
  216. addmenu "F" "Run a fileserver with a user and password" "fileserver -s" "(command: fileserver -s)"
  217. addmenu "F" "Stop fileserver" "fileserver stop" "(command: fileserver stop)"
  218. addmenu "G" "<-- Go back to main menu" "changeMenu A"
  219. addmenu "G" "Mclone in client mode (receiver)(!)" "mclone" "(command: mclone)"
  220. addmenu "G" "Mclone in server mode (sender)" "mclone -s" "(command: mclone -s)"
  221. addmenu "G" "Mclone in server mode (sender) with 80Mbit speed limit" "mclone -s -r 80m" "(command: mclone -s -r 80)"
  222. addmenu "G" "Get help on mclone" "man mclone"
  223. addmenu "H" "<-- Go back to main menu" "changeMenu A"
  224. addmenu "H" "Bring up the bridge" "bridge up" "(command: bridge up)"
  225. addmenu "H" "Bring down the bridge" "bridge down" "(command: bridge down)"
  226. addmenu "H" "Sniff the traffic" "tcpdump -i eth0" "If you have a lot of traffic, recommend you run tcpdump from the commandline with the appropriate filtersi \n(command: tcpdump -i eth0)"
  227. addmenu "I" "<-- Go back to main menu" "changeMenu A"
  228. addmenu "I" "Pi - an interactive image backup utility" "pi" "From the same contributors as the simple TRK menu"
  229. addmenu "I" "Help on pi" "man pi"
  230. addmenu "I" "Mondoarchive" "mondoarchive" "Backup to any medium using mondo \n(command: mondoarchive)"
  231. addmenu "I" "Mondorestore" "mondorestore" "Restore from a backup previously made with mondoarchive \n(command: mondorestore)"
  232. #
  233. # addmenu "A" "TRK Helpx" "changeMenu B" "" # Menu A definition
  234. # addmenu "A" "Partitions utilities" "changeMenu C" ""
  235. # addmenu "A" "ntfs utilities" "changeMenu D"
  236. # addmenu "A" "This menu ${BLUEFG}${BOLD}does nothing${RESET}, just to test colors on and off" "eval NOSTOP=1; ls -l /etc/|more" "testcomment"
  237. # addmenu "A" "This menu does nothing, ${REDBG}just to test colors on${RESET} and off" "eval NOSTOP=1" ""
  238. # addmenu "A" "Midnight Commander (=Explorer)" "mc"
  239. # addmenu "A" "testdisk" "eval 'NOSTOP=1' ; testdisk"
  240. # addmenu "A" "Recreer un secteur boot (mais pas ntfs)" "ms-sys"
  241. # addmenu "A" "Quit" "exit" "You can quit also with CTRL+C"
  242. #
  243. #
  244. # addmenu "B" "Go back to main menu" "changeMenu A" # Menu B definition
  245. # addmenu "B" "offline web help" "trkhelp -l"
  246. # addmenu "B" "offline text help" "trkhelp -l -t"
  247. # addmenu "B" "online web help" "trkhelp"
  248. #
  249. # addmenu "C" "Go back to main menu" "changeMenu A"
  250. # addmenu "C" "Easy Partimage" "pi" "$C_partimage"
  251. # addmenu "C" "Standard Partimage" "partimage"
  252. # addmenu "C" "Partitions info" "fdisk -l"
  253. # addmenu "C" "Editeur de partitions graphique ${RESET}(qtparted)" "umountallfs ; qtparted ; mountallfs"
  254. # addmenu "C" "Editeur de partitions en ligne de commande" "cfdisk"
  255. # addmenu "C" "Chercher les partitions" "run_gpart"
  256. #
  257. # addmenu "D" "Go back to main menu" "changeMenu A"
  258. # addmenu "D" "ntfsresize" "ntfsresize"
  259. # addmenu "D" "NTFS qui ne boote pas (Relocntfs)" "relocntfs"
  260. #
  261. MAINMENU="A" # Defines the base menu
  262. # ======================================= End of the menu definition ===========================================================
  263. fi
  264. changeMenu $MAINMENU
  265. # Special functions for menus
  266. function run_gpart {
  267. read -p "device : " toto
  268. gpart $toto
  269. }
  270. # Special fonction for TRK
  271. #if [ ! -e /etc/mountallfstab ]
  272. #then
  273. # mountallfs
  274. #fi
  275. # Winpass prompt for username
  276. function winpass-u {
  277. read -p "Username to reset password of: " username
  278. winpass -u $username
  279. }
  280. function destination-prompt {
  281. read -p "Enter destination(s)(comma separated, no spaces): " dest
  282. if [ r$dest == r ]; then
  283. unset destination
  284. echo "No destination given, unsetting..."
  285. else
  286. destination="-d $dest"
  287. fi;
  288. }
  289. function ssh-server {
  290. color ltwhite
  291. grep "12916" /etc/shadow |grep -q root
  292. if [ $? = 0 ]; then
  293. echo "TRK still has the default root password 'trk'."
  294. echo "Change it with passwd, run updatetrk and boot from the new TRK if you don't"
  295. echo "want to be prompted for this anymore"
  296. echo "For security reasons, before you can run a secure shell server and login remotely, "
  297. echo "you have to change your root password now"
  298. /usr/bin/passwd root
  299. else echo "Non-default root password found, no need to prompt for new one"
  300. fi;
  301. echo "These are the IP-addresses your ssh server will listen to:"
  302. color ltgreen
  303. ifconfig | grep "inet addr" | grep -v "127.0.0.1" | cut -d : -f 2 | cut -d " " -f 1
  304. color off
  305. echo -n "Starting ssh server..."
  306. /usr/sbin/sshd && echo "done"
  307. }
  308. # Main program
  309. # Now we are ready to display the menu
  310. while /bin/true # main loop
  311. do
  312. clear
  313. echo -e $TITLE
  314. echo
  315. # Display the menu itself
  316. LIMIT=${#menu[*]}
  317. for ((i=0; i < LIMIT ; i++)) # C style : double parenthesis and variable without $
  318. do
  319. if [ $LINE = $i ]
  320. then
  321. echo -ne "${CURSON}"
  322. REPEAT="$CURSON"
  323. else
  324. REPEAT=""
  325. fi
  326. #tput cup $(( $i + 3 )) 15 # too slow
  327. option=${menu[$i]/033\[0m/033\[0m${REPEAT}}
  328. echo -e " | $option ${RESET}"
  329. REP[$i]=${menu[$i]}
  330. done
  331. # Display the commentary, if any
  332. echo
  333. echo -e ${menu2[$LINE]}
  334. # Handle keyboard input
  335. read -s -n1
  336. if [ -z $REPLY ] # ENTER pressed, $REPLY is undefined
  337. then
  338. ${menu1[$LINE]} # The command itself
  339. if [ $NOSTOP = 1 ] # don't stop when changing menu
  340. then
  341. NOSTOP=0
  342. else
  343. read -p "Press any key to continue" -n1 pause
  344. fi
  345. else
  346. if [ $REPLY = $firstcode ]
  347. then
  348. read -s -n1 NUM2
  349. if [ $NUM2 = "[" ]
  350. then
  351. read -s -n1 NUM3
  352. case $NUM3 in
  353. $uparrow) LINE=$(($LINE - 1))
  354. if [ $LINE -lt 0 ]
  355. then
  356. LINE=0
  357. fi
  358. continue;; # Redisplay the menu with the new selection
  359. $downarrow) LINE=$(($LINE + 1))
  360. if [ $LINE -gt $(($i - 1)) ]
  361. then
  362. LINE=$(($i-1))
  363. fi
  364. continue;; # Redisplay the menu with the new selection
  365. $leftarrow) changeMenu "A"
  366. continue;; # Redisplay the main menu
  367. *)
  368. continue;; # Invalid key, redisplay the main menu
  369. esac
  370. else
  371. continue # Invalid key, redisplay the main menu
  372. fi
  373. else
  374. continue # Invalid key, redisplay the main menu
  375. fi
  376. fi
  377. done