Page 1 of 1

PI Config Script (who wants to help)

Posted: Thursday 03 March 2016 19:41
by remb0
I had several notitions and scripts and want to combine them into one superscript.
1 script to setup and configure a Raspberry.

But it has no fancy gui, error handling and is not really complete.
Who can help me to complete this, script so installations can be made easier?
every kind of help is welcome..

Code: Select all

#!/bin/bash

## todo
## - modt script
## - fail2ban
## - error handling
## - setup backup script  en restore made backups
##  testen


#Configuration script for domoticz on a Raspberry Pi

INSTALL_DIR=/home/pi
DOMO_DIR=$INSTALL_DIR/domoticz
TEMP_DIR=/tmp

# Check for root priviledges
if [[ $(id -u) != 0 ]]
then
	echo "Superuser (root) priviledges are required for most of the installations"
	echo "Please do 'sudo -s' first"
	exit 1
fi

# Accept EULA
if [[ "$BOXED" != "yes" ]]
then
	echo "Do you accept the licence agreement?"
	echo "Please know what you are doing!!"
	while true
	do
		echo -n "yes/no: "
		read ANSWER < /dev/tty
		case $ANSWER in
			yes)
				break
				;;
			no)
				exit 1
				;;
		esac
		echo "Please answer yes or no"
	done
fi


show_menu(){
    NORMAL=`echo "\033[m"`
    MENU=`echo "\033[36m"` #Blue
    NUMBER=`echo "\033[33m"` #yellow
    FGRED=`echo "\033[41m"`
    RED_TEXT=`echo "\033[31m"`
    ENTER_LINE=`echo "\033[33m"`
    echo -e "${MENU}*********************************************${NORMAL}"
    echo -e "${MENU}**${NUMBER} 1)${MENU} Configure PI ${NORMAL}"
    echo -e "${MENU}**${NUMBER} 2)${MENU} Cleanup Installation ${NORMAL}"
    echo -e "${MENU}**${NUMBER} 3)${MENU} Install additionals ${NORMAL}"
    echo -e "${MENU}**${NUMBER} 4)${MENU} Update System ${NORMAL}"
	echo -e "${MENU}**${NUMBER} 5)${MENU} Update Domoticz ${NORMAL}"
	echo -e "${MENU}**${NUMBER} 6)${MENU} Monit ${NORMAL}"
	echo -e "${MENU}**${NUMBER} 7)${MENU} Ramdisk ${NORMAL}"
	echo -e "${MENU}**${NUMBER} 8)${MENU} MODT (inlogscript) ${NORMAL}"
    echo -e "${MENU}**${NUMBER} 9)${MENU} Fix permissions ${NORMAL}"
	echo -e "${MENU}**${NUMBER} 10)${MENU} Persistent USB ${NORMAL}"
	echo -e "${MENU}**${NUMBER} 11)${MENU} Domoticz logging  ${NORMAL}"
	echo -e "${MENU}**${NUMBER} 12)${MENU} Fix permissions ${NORMAL}"
    echo -e "${MENU}*********************************************${NORMAL}"
    echo -e "${ENTER_LINE}Please enter a menu option and enter or ${RED_TEXT}enter to exit. ${NORMAL}"
    read opt
}
function option_picked() {
    COLOR='\033[01;31m' # bold red
    RESET='\033[00;00m' # normal white
    MESSAGE=${@:-"${RESET}Error: No message passed"}
    echo -e "${COLOR}${MESSAGE}${RESET}"
}

clear
show_menu
while [ opt != '' ]
    do
    if [[ $opt = "" ]]; then 
            exit;
    else
        case $opt in
        1) clear;
			option_picked "Option 1 Picked";
			echo "Option 1"
			##### The percentage of updates #####
			#####################################
			echo expand filesystem
			echo change wachtwoord
			echo Change Hostname
			echo enable SPI
			echo zet landinstellingen goed
			echo update
			echo mogelijk overklokken
			sudo raspi-config
			menu;
        ;;

        2) clear;
            option_picked "Option 2 Picked";
			echo "Option 2"
			echo "Removing Junk"
			sudo apt-get remove cups*
			sudo apt-get remove gnome*
			sudo apt-get remove x11-common*
			sudo apt-get autoremove
			menu;
            ;;

        3) clear;
            option_picked "Option 3 Picked";
			echo "Option 3"
			echo "Installing additional libraries"
			apt-get -y update
			## python voor scripts
			apt-get -qy install python 
			## voor het check RFXCom update script
			apt-get -qy install xml xml2 libxml2-dev
			##webcam, driver voor logitech webcam.
			apt-get -qy install uvccapture
						show_menu;
            ;;

        4) clear;
            option_picked "Option 4 Picked";
			echo "Update install"
			sudo apt-get update
			sudo apt-get upgrade
            ;;

		5) clear;
            option_picked "Option 5 Picked";
			echo "Option 5"
			echo "Update install"
			cd domoticz
			wget http://domoticz.sourceforge.net/beta/domoticz_linux_armv7l.tgz
			tar xvfz domoticz_linux_armv7l.tgz
			rm domoticz_linux_armv7l.tgz
			./domoticz
			
			menu;
            ;;

		6) clear;
            option_picked "Option 6 Picked";
			echo "Install Monit"
			## monit  (als domoticz niet meer reageerd krijg je een mailtje.)
			sudo apt-get install monit
			## zet de rechten tijdelijk anders zodat met winscp het bestand in windows aan te passen is. copy-pasten maar :)
			## ik zeg tijdelijk omdat monit niet kan werken met uitgebreide rechten.
			cd /etc/monit/
			sudo chmod 0777 /etc/monit/monitrc
			cd /home/pi/domoticz/ && cp monitrc /etc/monit/
			sudo chmod 0600 /etc/monit/monitrc
			sudo monit reload
			sudo monit -t
			sudo service monit start all
			sudo monit status
        menu;
            ;;

		7) clear;
            option_picked "Option 7 Picked";
			echo "Option 7"
			echo "Ramdisk"
			echo "Ramdisk   beter om logs van scripts niet naartoe te laten schrijven voor behoud van je kaartje."
			sudo mkdir /var/tmp
			sudo nano /etc/fstab
			echo "Voeg daar deze regel toe:"
			echo "tmpfs /var/tmp tmpfs nodev,nosuid,size=1M 0 0 "
			sudo mount -a
			df

        menu;
            ;;

		8) clear;
            option_picked "Option 8 Picked";
			echo "Option 2"
			echo "Motd.sh"
		echo "Copying"
		cp -r /home/pi/domoticz/motd.sh /etc/profile.d/motd.sh
        menu;
            ;;

		9) clear;
            option_picked "Option 9 Picked";
			echo "Option 9"
			echo "Fix permissions "
			## zet rechten goed (niet nodig gehad, maar goed als naslag):
			cd /home/pi/domoticz/
			sudo sh domoticz.sh stop
			sudo service domoticz stop
			sudo chown -R pi.pi *
			##zet rechten via 777 op scripts (bash script voor backup bijvoorbeeld)
			sudo chmod -R 0777 /tmp
			sudo service domoticz start

			menu;
            ;;

		10) clear;
            option_picked "Option 10 Picked";
			echo "option 10"
			echo "Persistent USB "
			## zet rechten goed (niet nodig gehad, maar goed als naslag):
			
			sudo nano /etc/udev/rules.d/99-usb-serial.rules
			## sudo lsusb -v | more    geeft my:  p1 cable, rfx, webcam, arduino
	#		SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="A6WJZP3I", SYMLINK+="ttyUSB11" 
	#		SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="A1WYA02C", SYMLINK+="ttyUSB22"
	#		SUBSYSTEM=="tty", ATTRS{idVendor}=="046d", ATTRS{idProduct}=="0825", ATTRS{serial}=="B89CE2A0", SYMLINK+="ttyUSB33"
	#		SUBSYSTEM=="tty", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", SYMLINK+="ttyUSB44"

			menu;
            ;;
			
			11) clear;
            option_picked "Option 11 Picked";
			echo "option 11"
			echo "Domoticz logging "
			## zet rechten goed (niet nodig gehad, maar goed als naslag):
	
			echo "edit Domoticz Logging"
			echo "Maybe also enable the logging in /etc/init.d/domoticz.sh:"
			##-->> DEAMON_ARGS="-daemon -www 8080 -log /var/log/domoticz.log -loglevel 0

			menu;
            ;;
			
			12) clear;
            option_picked "Option 12 Picked";
			echo "option 12"
			echo "Domoticz logging "
			## Mindergas! upload to mindergas (DUTCH).
			sudo apt-get install flex -y
			wget https://github.com/stedolan/jq/releases/download/jq-1.4/jq-1.4.tar.gz
			tar xfvz jq-1.4.tar.gz
			cd jq-1.4
			./configure
			make
			sudo make install
			rm /home/pi/jq-1.4.tar.gz
			cd home/pi/domoticz/scripts/bash/
			ls
			sh post-mindergas.sh 
			
			menu;
            ;;
			
			13) clear;
            option_picked "Option 13 Picked";
			echo "option 13"
			echo "Other "

			menu;
            ;;
        x)exit;
        ;;

        \n)exit;
        ;;

        *)clear;
        option_picked "Pick an option from the menu";
        show_menu;
        ;;
    esac
fi
done



echo "Thank you for using Domoticz installation script!"

exit 0

Re: PI Config Script (who wants to help)

Posted: Sunday 06 March 2016 9:17
by Albsucher
Hello,

well, maybe i could do some help on this, as i also think of changing from Pi 1 to Pi 2 or 3. so give back the community something.
If i have the prerequisites needed for this...

What is the exact intention of your script - beside of the image for Domoticz?

/ Ralf

Re: PI Config Script (who wants to help)

Posted: Sunday 06 March 2016 15:55
by remb0
My intention is to create a script to help people do the most common settings and things. Is can be extended with everything that's handy, but users can choose what they want.. I hope to see some contributions.

Re: PI Config Script (who wants to help)

Posted: Monday 07 March 2016 18:01
by Albsucher
Well, i would help with my knowledge on this script. We just need to define a base OS where it should work.
And of course the ideas.
Maybe start with a base script and later add some gui to it.

Re: PI Config Script (who wants to help)

Posted: Monday 07 March 2016 18:28
by remb0
It must work on the domoticz images.
Ideas:
All popular thing from the wiki can be automated in this script.

For now I have some troubles with the menu. When I choose an option, it execute that option but in a loop. You don't get the menu.

Re: PI Config Script (who wants to help)

Posted: Monday 07 March 2016 21:12
by pepijn
Just a hint: try using whiptail for your menu's

Re: PI Config Script (who wants to help)

Posted: Monday 07 March 2016 21:28
by Westcott
Thanks Pepijn - never knew it was that easy!
See - https://www.raspberrypi.org/forums/view ... 66&t=78057

Re: PI Config Script (who wants to help)

Posted: Wednesday 09 March 2016 12:32
by remb0
thanks! looks very nice. just what we need. :) now the content ;)

Re: PI Config Script (who wants to help)

Posted: Wednesday 09 March 2016 21:48
by HansieNL
This is what I've made so far... These are my most used functions if I use ssh.
Naamloos 2.jpg
Naamloos 2.jpg (44.2 KiB) Viewed 3723 times
#!/bin/bash
clear
RETVAL=$(whiptail --title "Domoticz Menu" --menu "" 12 53 0 \
"1" "Backup of Domoticz folder" \
"2" "Update Domoticz to the latest beta version" \
"3" "Updating and Upgrading Raspbian" \
"4" "Raspberry Pi Software Configuration Tool" \
"5" "Reboot System" \
"6" "Shutdown System" \
3>&1 1>&2 2>&3)

# Below you can enter the corresponding commands
# Create backupz folder in pi folder first

case $RETVAL in
1) echo "Backing up Domoticz folder... (please standby...)"
sudo service domoticz.sh stop
sudo tar --verbose --verify --create --file=./backupz/domoticz_bak.tar domoticz/ --exclude=domoticz_linux_armv7l.tgz
echo "Restarting Domoticz... (please standby...)"
sudo service domoticz.sh restart ;;
2) cd ~/domoticz
echo "Updating to latest beta version... (please standby...)"
sudo service domoticz.sh stop
sudo cp domoticz.db ../backupz/domoticz.db
mv domoticz_linux_armv7l.tgz ../backupz/domoticz_linux_armv7l.tgz
wget http://releases.domoticz.com/releases/b ... armv7l.tgz
tar xvfz domoticz_linux_armv7l.tgz
echo "Restarting Domoticz... (please standby...)"
sudo service domoticz.sh restart ;;
3) sudo apt-get update
sudo apt-get upgrade ;;
4) sudo raspi-config ;;
5) sudo reboot ;;
6) sudo poweroff ;;
*) echo "You chose Cancel." ;;
esac

Re: PI Config Script (who wants to help)

Posted: Friday 11 March 2016 20:56
by wijbet
Nice start for good project.
I want to give it a try and offer my help, so give a shot off your needings... :roll:

Re: PI Config Script (who wants to help)

Posted: Monday 14 March 2016 18:40
by wijbet
@remb0
For me I think help for this is not a prior?!? (After a couple day's no response.)
I think to spent my time to other things, so I wish you good luck and hope for you that this goal where finised.
With regards

Re: PI Config Script (who wants to help)

Posted: Monday 14 March 2016 19:40
by remb0
Sorry wijbet I thought I pméd you. But no!, help is still more then welcome..


this is the simple script now (with tips from above):

todo:
- Setup wifi
- split software into a sub menu so we can add more on a different menu
- help with cronjobs
- every nice and handy tutorial from the wiki can be added (with choices/variables/info and input boxes etc)

please shoot!

Code: Select all

#!/bin/bash

##whiptail —yesno "Did you already know whiptail?" —yes-button "Yes, I did" —no-button "No, never heard of it"  10 70
##  CHOICEs=$?
  
  
clear
RETVAL=$(whiptail --title "Domoticz Menu" --menu "" 12 53 0 \
"1" "Backup of Domoticz folder" \
"2" "Update Domoticz to the latest beta version" \
"3" "Updating and Upgrading Raspbian" \
"4" "Raspberry Pi Software Configuration Tool" \
"5" "Install Extra software" \
"6" "Domoticz configurations" \
"7" "Fix permissions" \
"8" "Reboot System" \
"9" "Shutdown System" \
3>&1 1>&2 2>&3)

# Below you can enter the corresponding commands
# Create backupz folder in pi folder first

case $RETVAL in
1) echo "Backing up Domoticz folder... (please standby...)"
sudo service domoticz.sh stop
sudo tar --verbose --verify --create --file=./backupz/domoticz_bak.tar domoticz/ --exclude=domoticz_linux_armv7l.tgz
echo "Restarting Domoticz... (please standby...)"
sudo service domoticz.sh restart ;;

2) 

##whiptail --title "Example Dialog" --infobox "This is an example of an info box." 8 78
cd ~/domoticz
echo "Updating to latest beta version... (please standby...)"
sudo service domoticz.sh stop
sudo cp domoticz.db ../backupz/domoticz.db
mv domoticz_linux_armv7l.tgz ../backupz/domoticz_linux_armv7l.tgz
wget http://releases.domoticz.com/releases/beta/domoticz_linux_armv7l.tgz
tar xvfz domoticz_linux_armv7l.tgz
echo "Restarting Domoticz... (please standby...)"
sudo service domoticz.sh restart ;;

3) 
sudo apt-get update
sudo apt-get upgrade ;;

4) sudo raspi-config ;;

5)  echo " Extra software" ;; 
##whiptail —yesno "Are you sure?" —yes-button "Yes, I did" —no-button "No, never heard of it"  10 70
##  CHOICEs=$?

##Monit
##MODT
##ramdisk


6) echo " Configure domoticz extras"

##logging
##persistent usb
##scripting:   hue, mindergas


			## Mindergas! upload to mindergas (DUTCH).
			sudo apt-get install flex -y
			wget https://github.com/stedolan/jq/releases/download/jq-1.4/jq-1.4.tar.gz
			tar xfvz jq-1.4.tar.gz
			cd jq-1.4
			./configure
			make
			sudo make install
			rm /home/pi/jq-1.4.tar.gz
			cd home/pi/domoticz/scripts/bash/
			ls
			sh post-mindergas.sh ;;

7) echo "Fix permissions"
			## zet rechten goed (niet nodig gehad, maar goed als naslag):
			cd /home/pi/domoticz/
			sudo sh domoticz.sh stop
			sudo service domoticz stop
			sudo chown -R pi.pi *
			##zet rechten via 777 op scripts (bash script voor backup bijvoorbeeld)
			sudo chmod -R 0777 /tmp
			sudo service domoticz start ;;
8) sudo reboot ;;

9) sudo poweroff ;; 

*) echo "You chose Cancel." ;;
esac

Re: PI Config Script (who wants to help)

Posted: Wednesday 16 March 2016 20:08
by wijbet
Hello remb0,
Strange, contact with you is only possible to give here a reply. :oops:
All respect for you and all the orther people who spent the time to make this site a realy great turtual for people like me. Have to say this.
My idea was not only 'take' from this site, but even give (from my own experience).
Grtz. Wijbe

Re: PI Config Script (who wants to help)

Posted: Monday 21 March 2016 21:19
by remb0
posted my work in progres script at github: https://github.com/remb0/Domoticz_configurator

Tomorrown the code
hope other members will contribute to make an nice configurator/installer.