Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #Raspi-Setup Script
- #Joshua O'Leary 2012
- BOOTCONFIG=/boot/config.txt
- SETUPDIR=/etc/raspi-setup/
- HOMEDIR=/home/pi
- EDITOR=nano
- ROOT_DEVICE=/dev/root
- if [ "$USER" != "root" ]; then echo 'This script must be run as root. Exiting...'; exit; fi
- printmenu()
- {
- args=("$@")
- count=1
- end=$(($# + 1))
- while [ "$count" -lt "$end" ];
- do
- echo "$count: ${args[$(($count - 1))]}"
- count=$((count + 1))
- done
- }
- selectchoice()
- {
- choice=""
- echo ""
- read -e -n 1 -p '? ' choice
- }
- yesno()
- {
- echo '1: Yes 2: No'
- }
- anykey()
- {
- echo 'Press any key to continue.'
- read -n 1
- }
- avmenu()
- {
- clear
- printmenu "TV Type" "Change Overscan" "Audio Mode" "Back"
- selectchoice
- case $choice in
- 1 ) printmenu "NTSC (Default)" "Japan NTSC" "PAL" "Brazilian PAL"
- selectchoice
- for check in {1..4}
- do
- if [ "$check" = "$choice" ]; then valid=true; fi
- done
- if [ "$valid" = "true" ];
- then
- value=$(($choice - 1))
- echo $value > $SETUPDIR/config/tvtype
- valid="false"
- avmenu
- else
- echo 'Not a valid option'
- anykey
- avmenu
- fi
- ;;
- 2 ) printmenu "Enable" "Disable"
- selectchoice
- case $choice in
- 1 ) echo 'true' > $SETUPDIR/config/overscan ;;
- 2 ) echo 'false' > $SETUPDIR/config/overscan ;;
- * ) avmenu ;;
- esac
- ;;
- 3 ) printmenu "DVI only" "HDMI sound"
- selectchoice
- case $choice in
- 1 ) echo 'DVI' > $CONFIGDIR/config/soundmode ;;
- 2 ) echo 'HDMI' > $CONFIGDIR/config/soundmode ;;
- * ) avmenu ;;
- esac
- ;;
- 4 ) toplevel ;;
- * ) avmenu ;;
- esac
- }
- do_exit()
- {
- if [ -f $SETUPDIR/firstrun ]; then usermod --lock root; rm $SETUPDIR/firstrun; fi
- echo '# Generated by raspi-setup' > $BOOTCONFIG
- if [ "`cat $SETUPDIR/config/overscan`" = "false" ]; then echo 'disable_overscan=1' >> $BOOTCONFIG; fi
- if [ -f $SETUPDIR/config/tvtype ]; then echo "sdtv_mode=`cat $SETUPDIR/config/tvtype`" >> $BOOTCONFIG; fi
- if [ "`cat $SETUPDIR/config/soundmode`" = "HDMI" ]; then echo 'hdmi_drive=2' >> $BOOTCONFIG; fi
- echo '# Custom config from /etc/raspi-setup/config/config.append' >> $BOOTCONFIG
- cat $SETUPDIR/config/config.append >> $BOOTCONFIG
- exit 0
- }
- installdesktop()
- {
- clear
- echo 'Install xorg and fluxbox?'
- yesno
- selectchoice
- case $choice in
- 1 ) apt-get install xorg fluxbox -y
- xinstallresult=$?
- cp $SETUPDIR/xinitrc $HOMEDIR/.xinitrc
- cp $SETUPDIR/defaults/xinitrc /etc/skel/.xinitrc
- if [ "$xinstallresult" = "0" ]; then echo 'You can now start fluxbox by running startx.'; else echo 'Error during installation'; fi
- anykey
- toplevel
- ;;
- 2 ) toplevel
- ;;
- * ) installdesktop
- ;;
- esac
- }
- expandrootfs()
- {
- clear
- echo 'Are you sure? Not responsible for data loss!'
- echo '1: Yes 2: No'
- selectchoice
- if [ "$choice" = "1" ];
- then echo 'Resizing, please be patient...'
- /sbin/resize2fs $ROOT_DEVICE
- if [ "$?" = "0" ]; then echo 'Successful!'; else echo 'Resized failed.'; fi
- anykey
- fi
- toplevel
- }
- bootmenu()
- {
- clear
- echo "Enter config in the file below. Use Control+O to save in nano."
- echo "Video settings should be changed using this script."
- echo "Don't forget to choose 'finish' in the menu afterwards."
- anykey
- $EDITOR /etc/raspi-setup/config/config.append
- toplevel
- }
- changepasswd()
- {
- clear
- echo 'The following screen will change password for user pi.'
- anykey
- passwd pi
- toplevel
- }
- do_update()
- {
- clear
- echo 'Update firmware?'
- yesno
- selectchoice
- if [ "$choice" = "1" ]; then /usr/bin/rpi-update; anykey; fi
- toplevel
- }
- localemenu()
- {
- clear
- printmenu "Timezone" "Keyboard Layout" "Locales"
- selectchoice
- case $choice in
- 1 ) dpkg-reconfigure tzdata ;;
- 2 ) dpkg-reconfigure console-data ;;
- 3 ) dpkg-reconfigure locales ;;
- *) localemenu
- esac
- }
- toplevel()
- {
- clear
- echo "=========================="
- echo " Raspi-Setup Menu"
- echo "=========================="
- printmenu "A/V Settings" "Boot Settings" "Change Password" "Firmware Update" "Install Desktop System" "Expand Rootfs" "Localisation" "Finish / Write Config"
- selectchoice
- case $choice in
- 1 ) avmenu ;;
- 2 ) bootmenu ;;
- 3 ) changepasswd ;;
- 4 ) do_update ;;
- 5 ) installdesktop ;;
- 6 ) expandrootfs ;;
- 7 ) localemenu ;;
- 8 ) do_exit ;;
- * ) toplevel ;;
- esac
- }
- trap 'toplevel' INT
- toplevel
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement