#!/bin/bash ##################################################################################################### # DinGo script "install" # # Applies to DINGO Raspberry Pi based. # # This script is available at http://apps.control2net.com/apt/install # # The purpose of this script, is to install the DINGO-stack, in an easy way. # # This script takes one parameter. # "-c" stands for complete and will install DINGO-stack, network- and LCD-setup. # "-b" stands for basic and only the DINGO-stack will be installed. # "-h" or "--help" displays help information on command line arguments. # # If no parameters are provided, then the install process will ask questions as the installation # progresses. # # Regular usage: sudo ./install [parameter] # Usage from Internet: sudo bash -c "$(curl -s http://apps.control2net.com/apt/install)" -- [parameter] # # Debug: # # Written by Danjal S. Adlersson @ Go-IoT # Created 12. Jun. 2018 # Copyright (c) Go-IoT ##################################################################################################### # Causes the shell to exit if any subcommand or pipeline returns a non-zero status. set -e # Color settings for echo messages blue='\e[1;36m' # Blue color green='\e[1;32m' # Green color yellow='\e[1;33m' # Yellow color red='\e[1;31m' # Red color NC='\e[0m' # No color ##################################################################################################### # HELP ##################################################################################################### if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then echo "Regular usage: sudo ./install [parameter]" echo 'Usage from Internet: sudo bash -c "$(curl -s http://apps.control2net.com/apt/install)" -- [parameter]' echo "Parameters:" echo " -c Stands for complete and will install DINGO-stack, networking- and LCD-setup." echo " -b Stands for basic and will only install the DINGO-stack." echo " -h, --help Will display the help information." echo "" echo "The script will also ask for further information, that is not yet part of the parameter system." echo "If no parameters are provided, then the script will ask for information." exit 0 fi ##################################################################################################### # FUNCTIONS ##################################################################################################### function InstallDingoStack { echo -e "${blue}GoIoT: Install DINGO-stack...${NC}" # Install DINGO stack sudo apt-get -y install dingo-stack # Sleep 5 seconds, so the DINGO-stack has time todo its first setup. sleep 5 echo -e "${blue}GoIoT: Install DINGO-stack. Finished.${NC}" echo -e "${blue}GoIoT: Do FTP upgrade...${NC}" # Do an FTP upgrade sudo curl -s http://apps.control2net.com/apt/ftp-upgrade.txt | sudo bash /dev/stdin echo -e "${blue}GoIoT: Do FTP upgrade...${NC}" } function SetupWireless { sudo /opt/GoIoT/DinGo/bin/dingo-set-internet-interface-wireless } function SetupModem { sudo /opt/GoIoT/DinGo/bin/dingo-set-internet-interface-modem } function InstallDingoStackNetworking { echo -e "${blue}GoIoT: Install DINGO-stack network setup...${NC}" # Install DINGO networking setup sudo apt-get -y install dingo-stack-networking # Set primary Internet interface (ETHERNET, WIRELESS or MODEM) # TODO: ETHERNET2 while true; do read -p $'\e[1;32mSpecify primary Internet interface (e=ethernet, w=wireless and m=modem)? [Default=e]\e[0m' yn case $yn in [Ee]* ) break;; [Ww]* ) SetupWireless; break;; [Mm]* ) SetupModem; break;; * ) break;; esac done echo -e "${blue}GoIoT: Install DINGO-stack network setup. Finished.${NC}" } function InstallDingoStackAdafruit { echo -e "${blue}GoIoT: Install DINGO-stack LCD setup...${NC}" # Setup i2c-0 grep -q -F 'dtparam=i2c_vc=on' /boot/config.txt || sed -i -e '$i \dtparam=i2c_vc=on\n' /boot/config.txt # Install LCD package set +e sudo apt-get -y install dingo-stack-adafruit set -e # Temporary work around bug in Adafruit package. # https://github.com/adafruit/Adafruit_Python_SSD1306/issues/22 sudo rm -r /Adafruit_Python_SSD1306/ # Then install the LCD package again sudo apt-get -y install dingo-stack-adafruit # Retrieve any new files sudo /opt/GoIoT/DinGo/bin/ftp-upgrade-adafruit.sh echo -e "${blue}GoIoT: Install DINGO-stack LCD setup. Finished.${NC}" } function InstallHardwareClock { echo -e "${blue}GoIoT: Setup hardware clock...${NC}" # Remove the fake clock sudo apt-get -y purge fake-hwclock # Setup hardware clock grep -q -F 'dtoverlay=i2c-rtc,ds1339' /boot/config.txt || sed -i -e '$i \dtoverlay=i2c-rtc,ds1339\n' /boot/config.txt grep -q -F 'rtc-ds1339' /etc/modules || sed -i -e '$i \rtc-ds1339\n' /etc/modules # Create default adjtime file sudo echo '0.000000 0 0.000000 0 UTC' > /etc/adjtime echo -e "${blue}GoIoT: Setup hardware clock. Finished.${NC}" } function SetupDingoRepositories { # Allow DINGO repositories echo -e "${blue}GoIoT: Setup repositories...${NC}" sudo curl -s http://apps.control2net.com/apt/apt.txt | sudo bash /dev/stdin echo -e "${blue}GoIoT: Setup repositories. Finish.${NC}" } ##################################################################################################### # START INSTALLATION ##################################################################################################### # It is recommended, when doing a new installation to first change the default password on the device. # Then use enable SSH, SPI and I2C. This can all be done with "sudo raspi-config" echo -e "${yellow}INSTALL DINGO-STACK AND ACCESSORIES.${NC}" echo -e "" echo -e "${yellow} It is recommended, when doing a new installation, to first change the default password on the device.${NC}" echo -e "${yellow} Then enable SSH, SPI and I2C. This can all be done with: sudo raspi-config${NC}" echo -e "" if grep -qF "http://apps.control2net.com/apt/" /etc/apt/sources.list; then dummy="" else #SetupDingoRepositories; echo -e "${yellow}The installation needs to setup the DINGO repositories. This should be done only once.${NC}" while true; do read -p $'\e[1;32mDo you wish to setup DINGO repositories? [Default=y]\e[0m' yn case $yn in [Yy]* ) SetupDingoRepositories; break;; [Nn]* ) break;; * ) SetupDingoRepositories; break;; esac done fi ##################################################################################################### # INSTALL DINGO-STACK ##################################################################################################### if [ "$1" = "-b" ] || [ "$1" = "-c" ]; then InstallDingoStack else while true; do read -p $'\e[1;32mDo you wish to install the DINGO-stack? [Default=y]\e[0m' yn case $yn in [Yy]* ) InstallDingoStack; break;; [Nn]* ) break;; * ) InstallDingoStack; break;; esac done fi ##################################################################################################### # INSTALL DINGO-STACK NETWORKING ##################################################################################################### if [ "$1" = "-c" ]; then InstallDingoStackNetworking else while true; do read -p $'\e[1;32mDo you wish to install the DINGO-stack networking? [Default=y]\e[0m' yn case $yn in [Yy]* ) InstallDingoStackNetworking; break;; [Nn]* ) break;; * ) InstallDingoStackNetworking; break;; esac done fi ##################################################################################################### # INSTALL DINGO-STACK LCD ##################################################################################################### if [ "$1" = "-c" ]; then InstallDingoStackAdafruit else while true; do read -p $'\e[1;32mDo you wish to install the DINGO-stack LCD setup? [Default=y]\e[0m' yn case $yn in [Yy]* ) InstallDingoStackAdafruit; break;; [Nn]* ) break;; * ) InstallDingoStackAdafruit; break;; esac done fi ##################################################################################################### # SETUP HARDWARE CLOCK ##################################################################################################### if [ "$1" = "-c" ]; then InstallHardwareClock else while true; do read -p $'\e[1;32mDo you wish to install the hardware clock? [Default=y]\e[0m' yn case $yn in [Yy]* ) InstallHardwareClock; break;; [Nn]* ) break;; * ) InstallHardwareClock; break;; esac done fi ##################################################################################################### # MISC. SETUPS ##################################################################################################### while true; do read -p $'\e[1;32mDo you wish to install FTP client? [Default=y]\e[0m' yn case $yn in [Yy]* ) sudo apt-get install ftp; break;; [Nn]* ) break;; * ) sudo apt-get install ftp; break;; esac done while true; do read -p $'\e[1;32mDo you want to change hostname? [Default=y]\e[0m' yn case $yn in [Yy]* ) # Ask for hostname read -e -p " New hostname: " hostname sudo /opt/GoIoT/DinGo/bin/dingo-set-hostname "$hostname" break;; [Nn]* ) break;; * ) # Ask for hostname read -e -p " New hostname: " hostname sudo /opt/GoIoT/DinGo/bin/dingo-set-hostname "$hostname" break;; esac done #while true; do # read -p $'\e[1;32mDo you want to change timezone? [Default=n]\e[0m' yn # case $yn in # [Yy]* ) sudo apt-get install ftp; break;; # [Nn]* ) break;; # * ) break;; # esac #done while true; do read -p $'\e[1;32mDo you want to install OpenPort? [Default=n]\e[0m' yn case $yn in [Yy]* ) sudo wget https://openport.io/download/arm/latest.deb sudo dpkg -i latest.deb while true; do read -p $'\e[1;32mDo you want to register the device to OpenPort? [Default=n]\e[0m' yn2 case $yn2 in [Yy]* ) # Ask for open port reg. key read -e -p " Openport Reg. key: " KEY HOSTNAME=`sudo cat /etc/hostname` sudo openport --register-key "$KEY" --name "$HOSTNAME" # Open ports sudo openport 22 -R -d sudo openport 80 -R -d break;; [Nn]* ) break;; * ) break ;; esac done break;; [Nn]* ) break;; * ) break;; esac done while true; do read -p $'\e[1;32mDo you want to get the latest binaries (ftp-debug)? [Default=n]\e[0m' yn case $yn in [Yy]* ) # Retrieve latest files sudo /opt/GoIoT/DinGo/bin/ftp-debug-upgrade.sh break;; [Nn]* ) break;; * ) break;; esac done echo -e "${yellow}INSTALLATION FINISHED. REBOOT IF NEEDED.${NC}" exit 0