#!/bin/bash ##################################################################################################### # DinGo script "ftp-upgrade-adafruit.sh" # # Applies to DinGo Pi # # This script should be placed in /opt/GoIoT/DinGo/bin # # The script must be made executable like this: # chmod +x /opt/GoIoT/DinGo/bin/ftp-upgrade-adafruit.sh # # The purpose of this script, is to install or upgrade the Adafruit Python SSD1306 LCD setup for the DINGO-stack. # # Note: The LCD setup for the DINGO-stack has some dependencies that should be manually solved. # This script will not try to install these dependencies. The dependencies are these: build-essential, # python-dev, python-pip, python-imaging, python-smbus and git. # # This script takes one parameter. If it equals "install", then the script will try to install # the LCD setup. If the parameter is empty or something else, then the LCD setup will be upgraded. # If using install-mode, when the LCD setup is already installed, then the script will switch # into upgrade-mode automatically. # # When installing or upgrading, this script will download files from a remote site. # The remote directory structure starts with a platform e.g. RPI for Raspberry Pi. It then has a # directory called "adafruit", which contains the files that should be copied onto the local filesystem. # Under the "adafruit", we have two directories: one called "configfiles", which contains files that # should only be copied once to the filesystem, and one called "exec", which basicly contains all # the other files. # # Usage: This script should be called when installing or upgrading the LCD setup for the DINGO-stack. # # Debug: # # Written by Danjal S. Adlersson @ Go-IoT # Created 12. Mar. 2018 # Copyright (c) Go-IoT ##################################################################################################### # Causes the shell to exit if any subcommand or pipeline returns a non-zero status. set -e # FTP settings for the remote downloading username="dingo" password="dingdong" server="82.221.35.195" #username="ftp" #password="ftp" #server="192.168.1.22" platform="RPI" # 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 # Function definitinos. These functions are called in the script function GetFiles { # wget # -m (mirror) uses recursion and timestamping. It will not delete any files. # -nv turns off verboseness, without being quit. # -nH does not create host directories. # --cut-dirs ignores a number of parent remote directories. echo -e "${blue}GoIoT: Get executables and other...${NC}" # Adafruit_Python_SSD1306 cd /Adafruit_Python_SSD1306 sudo wget -m -nv -nH --cut-dirs=4 ftp://$username:$password@$server/$platform/adafruit/exec/Adafruit_Python_SSD1306 # usr cd /usr sudo wget -m -nv -nH --cut-dirs=4 ftp://$username:$password@$server/$platform/adafruit/exec/usr # lib cd /lib sudo wget -m -nv -nH --cut-dirs=4 ftp://$username:$password@$server/$platform/adafruit/exec/lib } function SetPermissions { echo -e "${blue}GoIoT: Set permissions...${NC}" # Executables sudo chmod +x /Adafruit_Python_SSD1306/examples/DEMO/carousel.sh sudo chmod +x /Adafruit_Python_SSD1306/examples/DEMO/splash.sh sudo chmod +x /lib/systemd/system-shutdown/dingo-lcd } # MAIN SCRIPT STARTS HERE # Set default mode, install or upgrade mode="upgrade" # Check "mode" parameter if [ "$1" = "" ]; then # Parameter is empty, so we use default value echo -e "${blue}GoIoT: No parameter. Using default mode.${NC}" else if [ "$1" = "install" ]; then mode=$1 # Check if LCD setup is already installed if [ -d "/Adafruit_Python_SSD1306" ]; then # Directory exists - so this is a upgrade echo -e "${blue}GoIoT: Switching to upgrade mode.${NC}" mode="upgrade" fi fi fi # -- INSTALL --- if [ "$mode" = "install" ]; then echo -e "${blue}GoIoT: Start installing...${NC}" # 1. RUN PRE-SCRIPTS # Why do we install this sudo pip install RPi.GPIO # Go to the root folder cd / # Get Adafruit from GIT sudo git clone https://github.com/adafruit/Adafruit_Python_SSD1306.git # Then install Adafruit cd Adafruit_Python_SSD1306 sudo python setup.py install # 2. GET EXECUTABLES AND OTHER GetFiles # 3. SET PERMISSIONS ON EXECUTABLES SetPermissions # 4. RUN POST-SCRIPTS # Activate the splash script in rc.local (uncomment) sudo sed -i '/Adafruit_Python_SSD1306/s/^#//g' /etc/rc.local if [ ! -d /opt/Adafruit ]; then mkdir -p /opt/Adafruit fi if [ ! -d /opt/Adafruit/SSD1306 ]; then mkdir -p /opt/Adafruit/SSD1306 fi if [ ! -d /opt/Adafruit/SSD1306/DEMO ]; then ln -s /Adafruit_Python_SSD1306/examples/DEMO /opt/Adafruit/SSD1306 fi echo -e "${blue}GoIoT: Install finished.${NC}" exit 0 fi # -- UPGRADE -- if [ "$mode" = "upgrade" ]; then echo -e "${blue}GoIoT: Start upgrading...${NC}" # 1. RUN PRE-SCRIPTS # 2. GET EXECUTABLES AND OTHER GetFiles # 3. SET PERMISSIONS ON EXECUTABLES SetPermissions # 4. RUN POST-SCRIPTS # Activate the splash script in rc.local (uncomment) sudo sed -i '/Adafruit_Python_SSD1306/s/^#//g' /etc/rc.local if [ ! -d /opt/Adafruit ]; then mkdir -p /opt/Adafruit fi if [ ! -d /opt/Adafruit/SSD1306 ]; then mkdir -p /opt/Adafruit/SSD1306 fi if [ ! -d /opt/Adafruit/SSD1306/DEMO ]; then ln -s /Adafruit_Python_SSD1306/examples/DEMO /opt/Adafruit/SSD1306 fi echo -e "${blue}GoIoT: Finished upgrading.${NC}" exit 0 fi