#!/bin/bash # author sudodus alias nio-wiklund at launchpad # # date editor comment # 2013-11-08 sudodus upgraded starter (for the obi) # 2013-11-08 sudodus added dltbl (download tarball) # 2014-05-17 sudodus version for 9w without 'myself - 123456' # 2014-05-19 sudodus version for 9w without 'Download tarball' # 2014-06-18 sudodus version for 9w focused on OBI level # 2014-07-10 sudodus dynamic focus: tarball, OBI level, install # 2014-07-11 sudodus dynamic focus: defitem d, s, o, i # line 130 echoout(){ echo "[OBI] $@" echo "$@" >> "${HOME}"/obi-installer.log } LC_ALL=C;LANG=C #psw=torios obitxt="obi.txt" #hlptxt="/tmp/help-mkusb.txt" tiptxt="tips.txt" selected="selected" obilevel="obilevel" # check for tarballs if [ -d "/tarballs" ] then tarpath="/tarballs" elif [ -d "${HOME}/tarballs" ] then tarpath="${HOME}/tarballs" elif [ -d "${PWD}/tarballs" ] then tarpath="${PWD}/tarballs" else tarpath="${PWD}" echoout "Error finding the tarball path using: ${PWD}" fi echoout "Tarball path: $tarpath" if [ -f "/home/$USER/obi.txt" ] then dpath="/home/$USER" elif [ -f "${HOME}/obi.txt" ] then dpath="${HOME}" elif [ -f "${PWD}/obi.txt" ] then dpath="${PWD}" elif [ -f /usr/share/OBI/obi.txt ] then dpath="/usr/share/OBI/" else echoout "Text not found. Change directory!" exit 1 fi source "$dpath/functions" if [ "obi$DISPLAY" == "obi" ] then mktar="mktbl" quit_msg="exit to the bash shell" else quit_msg="close window" mktar="zmktbl" fi echoout "Using $mktar to make the tarballs" if [ -x "/usr/bin/$mktar" ] then mktblpath="/usr/bin" else mktblpath="${dpath}" fi echoout "OBI path: $dpath" obitxt="$dpath/$obitxt" prgnam="One Button Installer" ## Ubuntu ONLY version number APTCACHE=$(which apt-cache) if [ ! -z "${APTCACHE}" ] then ver_no=$(apt-cache policy one-button-installer | grep Installed: | sed 's/Installed://' | sed 's/ubuntu.*//') version="$prgnam $ver_no" else ## if we can't find apt-cache to grep the version just display the program name version="$prgnam" fi dialog --backtitle "$version - Splash" \ --timeout 3 --exit-label "OK" --textbox "$obitxt" 0 0 ##Took this out for OEM install #User and password for installed system\n # User: \Z4$psw\Zn\n # Password: \Z4$psw\Zn\n dialog --colors --no-shadow \ --backtitle "$version - Welcome and Warning" --msgbox \ "Welcome,\n Installing an operating system is a \Z1risky\Zn operation.\n \n WARNING \Z1Copy the data you want to keep to another device\Zn, for example\n WARNING an external hard disk drive or a cloud service! Otherwise,\n WARNING there might be no easy way to recover any previous data.\n WARNING Expensive intelligence services might restore some data.\n WARNING\n WARNING \Z1If you use the BASIC installer the target device will be\Zn\n WARNING \Z1********** COMPLETELY OVERWRITTEN **********\Zn\n WARNING\n WARNING \Z1If you want to keep an installed operating system,\Zn\n WARNING make sure to use the option\n WARNING \Z1'Partition drives and Install alongside current OS'\Zn" \ 0 0 #18 70 #0 0 #read -sn1 if [ -f "/home/$USER/mkhelp" ] then dpath="/home/$USER" elif [ -f "$PWD/mkhelp" ] then dpath="$PWD" elif [ -f "${HOME}/mkhelp" ] then dpath="${HOME}" elif [ -f "/usr/share/OBI/mkhelp" ] then dpath="/usr/share/OBI" else echo "Script not found. Change directory!" fi sudo "$dpath/init-dialog" tiptxt="$dpath/$tiptxt" # check for selected if [ -f /usr/share/OBI/selected ] then selected="/usr/share/OBI/selected" elif [ -f "$HOME/selected" ] then selected="$HOME/selected" elif [ -f "$PWD/selected" ] then selected="$PWD/selected" else selected="selected" echoout "Error finding the OBI selected path" fi ## Test to see if the tarball in 'selected' exists first selectedtest=$(cat "${selected}") if [ ! -f "${selectedtest}" ] then ## if it doesn't pick the last one listed so there is some reasonable choice available for i in "${tarpath}"/*.tar.[gx]z do target="$i" done echoout "Had to find a tarball.. OBI found $target" # write tarball name sudo bash -c "echo $target > $selected" fi ans="dummy" while [ "$ans" != "q" ] && [ "$ans" != "" ] do ls -1 "${tarpath}"/*.tar.[gx]z > /dev/null 2> /dev/null if [ $? -ne 0 ] then if test -s "$selected" then grep '\*.tar.\[gx\]z' "$selected" if [ $? -ne 0 ] then cat "$selected" read -p "Is this a tarball you want to use? (y/n) " an2 # new question if [ "$an2" == "y" ] then tarball=$(cat "${selected}") thisOS=$(basename "${tarball/.tar*/}") if [ "$thisOS" == "ball" ] then echoout "Unlabeled OS to install: $thisOS" menutitle="Unlabeled OS to install: $thisOS" ##Check tarball name else echoout "OS to install: $thisOS" menutitle="OS to install: $thisOS" fi fi fi else sudo rm "$selected" tarball= menutitle="No tarball selected" defitem=d fi else grep "tar.[gx]z" "$selected" > /dev/null 2> /dev/null if [ $? -ne 0 ] then sudo rm "$selected" fi if test -s "$selected" then tarball=$(cat "${selected}") thisOS=$(basename "${tarball/.tar*/}") if [ "$thisOS" == "ball" ] then echoout "Unlabeled OS to install: $thisOS" menutitle="Unlabeled OS to install: $thisOS" ##Check tarball name else echoout "OS to install: $thisOS" menutitle="OS to install: $thisOS" fi if test -s "$obilevel" then read level < "$obilevel" defitem=i else level=basic defitem=o fi else tarball= menutitle="No tarball selected" defitem=s fi fi echoout "Menu Title: $menutitle" if [ -z "$thisOS" ] then thisOS="tarball" fi cd "$dpath" ans=$(dialog --no-shadow --backtitle "$version - Starter Menu" \ --title "Please select an action with a letter key or the arrow keys" \ --default-item "$defitem" --colors --cancel-label Quit --menu "$menutitle" 19 76 12 \ s " Select tarball to install" \ a " Partition drives and \Z1Install $thisOS alongside current OS\Zn" \ i " Install $thisOS \Z1with the $prgnam\Zn" \ d " Download tarball" \ m " Make tarball" \ o " $level OBI level (select basic or advanced)" \ h " Help to select drive" \ t " Tips" \ c " Check (and repair) the file system /dev/sda1" \ q " Quit from this menu ($quit_msg)" \ r " Reboot" \ p " Poweroff" \ 3>&1 1>&2 2>&3 3>&- ) # read -n 1 -s ans if [ "$ans" == "s" ] then sudo "$dpath/select-tarball" elif [ "$ans" == "a" ] then echo "advanced" | sudo tee $obilevel sudo "$dpath/partition-help" elif [ "$ans" == "i" ] then sudo "$dpath/obi" elif [ "$ans" == "d" ] then echo sudo "$dpath/dltbl" ls -l "$dpath/dltbl" #read -p "looking for dltbl" sudo "$dpath/dltbl" elif [ "$ans" == "m" ] then sudo "$mktblpath/$mktar" #changed to use zenity mktbl IF X $DISPLAY is active elif [ "$ans" == "o" ] then sudo "$dpath/setlevel" elif [ "$ans" == "h" ] then sudo "$dpath/mkhelp" elif [ "$ans" == "t" ] then dialog --backtitle "$version - Tips (use arrow keys to scroll)" \ --textbox "$tiptxt" 17 76 elif [ "$ans" == "c" ] then sudo umount /dev/sda1 sudo e2fsck -f /dev/sda1 elif [ "$ans" == "r" ] then sudo reboot elif [ "$ans" == "p" ] then sudo poweroff fi done