Inkycal/prototype.sh

243 lines
9.4 KiB
Bash
Raw Normal View History

2019-01-27 20:53:50 +01:00
#!/bin/bash
2019-04-17 23:16:45 +02:00
# E-Paper-Calendar software installer for Raspberry pi
2019-02-03 15:58:17 +01:00
# Version: 1.5 (Early Februrary 2019)
2019-04-17 23:16:45 +02:00
# Stability status of this installer: Confirmed with Raspbain Stretch Lite on 12th March 2019
2019-01-27 20:53:50 +01:00
# Copyright by aceisace
2018-10-16 21:05:19 +02:00
2019-01-27 20:53:50 +01:00
echo -e "\e[1mPlease select an option from below:"
2019-02-06 01:07:37 +01:00
echo -e "\e[97mEnter \e[91m1 \e[97m to update the E-Paper software"
echo -e "\e[97mEnter \e[91m2 \e[97m to install the E-Paper software"
echo -e "\e[97mEnter \e[91m3 \e[97m to uninstall the E-Paper software"
2019-01-27 20:53:50 +01:00
echo -e "\e[97mConfirm your selection with [ENTER]"
read -r -p 'Waiting for input... ' option
2018-10-16 21:05:19 +02:00
2019-02-06 01:07:37 +01:00
if [ "$option" != 1 ] && [ "$option" != 2 ] && [ "$option" != 3 ]; then
2019-02-06 01:55:35 +01:00
echo -e "invalid number, aborting now"
2018-10-16 21:05:19 +02:00
exit
fi
2019-01-27 20:53:50 +01:00
if [ -z "$option" ]; then
2019-02-06 01:55:35 +01:00
echo -e "You didn't enter anything, aborting now."
2018-10-16 21:05:19 +02:00
exit
fi
2019-02-06 01:07:37 +01:00
if [ "$option" = 3 ]; then
2019-02-06 01:55:35 +01:00
echo -e "Removing the E-Paper software now..."
2019-04-18 12:27:45 +02:00
pip3 uninstall Pillow -y && sudo pip3 uninstall Pillow -y && sudo pip3 uninstall pyowm -y&& sudo pip3 uninstall ics -y && pip3 uninstall pyowm -y && pip3 uninstall ics -y && sudo apt-get remove supervisor -y && pip3 uninstall feedparser && sudo pip3 uninstall feedparser && sudo apt-get clean && sudo apt-get autoremove -y
2019-02-06 01:36:36 +01:00
if [ -e /etc/supervisor/conf.d/E-Paper.conf ]; then
sudo rm /etc/supervisor/conf.d/E-Paper.conf
fi
2019-02-06 01:55:35 +01:00
echo -e "The libraries have been removed successfully"
2019-04-17 23:16:45 +02:00
echo -e "Removing the Inky-Calendar folder if it exists"
if [ -d "/home/pi/Inky-Calendar" ]; then
sudo rm -r /home/pi/Inky-Calendar/
2019-02-06 00:11:54 +01:00
fi
2019-01-27 20:53:50 +01:00
fi
if [ "$option" = 1 ]; then
2019-02-06 01:07:37 +01:00
echo "Checking if the settings.py exists..."
2019-04-17 23:16:45 +02:00
if [ -e /home/pi/Inky-Calendar/Calendar/settings.py ]; then
2019-02-06 01:55:35 +01:00
echo -e "Found an E-Paper settings file."
2019-01-27 20:53:50 +01:00
sleep 2
echo "Backing up the current settings file in the home directory."
sleep 2
2019-04-17 23:16:45 +02:00
cp /home/pi/Inky-Calendar/Calendar/settings.py /home/pi/settings-old.py
2019-02-06 01:55:35 +01:00
echo -e "renaming the old E-Paper software folder"
2019-01-27 20:53:50 +01:00
sleep 2
2019-04-17 23:16:45 +02:00
cp -r /home/pi/Inky-Calendar /home/pi/Inky-Calendar-old
sudo rm -r /home/pi/Inky-Calendar
2019-01-27 20:53:50 +01:00
echo "Updating now..."
2019-02-06 01:07:37 +01:00
cd
2019-02-06 01:55:35 +01:00
else
2019-04-17 23:16:45 +02:00
echo -e "Could not find any settings.py file in /home/pi/Inky-Calendar/Calendar"
2019-02-06 01:55:35 +01:00
echo -e "Please uninstall the software first and then use the install option"
echo -e "Exiting now"
2019-02-06 01:07:37 +01:00
exit
2019-01-27 20:53:50 +01:00
fi
2019-02-06 01:07:37 +01:00
fi
2019-01-27 20:53:50 +01:00
2019-02-06 01:07:37 +01:00
if [ "$option" = 2 ]; then
echo -e "\e[1;36m"Setting up the system by installing some required libraries for python3 "\e[0m"
# Installing a few packages which are missing on Raspbian Stretch Lite
echo -e "\e[1;36m"Installing a few packages that are missing on Raspbian Stretch Lite..."\e[0m"
sudo apt-get install python3-pip -y python-rpi.gpio-dbgsym -y python3-rpi.gpio -y python-rpi.gpio -y python3-rpi.gpio-dbgsym -y python3-spidev -y git -y libopenjp2-7-dev -y libtiff5 -y python3-numpy -y
echo ""
# Running apt-get clean and apt-get autoremove
echo -e "\e[1;36m"Cleaning a bit of mess to free up some space..."\e[0m"
sudo apt-get clean && sudo apt-get autoremove -y
echo ""
fi
if [ "$option" = 1 ] || [ "$option" = 2 ]; then
2019-04-18 12:27:45 +02:00
# Ask to update system
echo -e "\e[1mWould you like to update and upgrade the operating system first?"
echo -e "\e[97mIt is not scrictly required, but highly recommended."
echo -e "\e[97mPlease note that updating may take quite some time, in rare cases up to 1 hour."
echo -e "\e[97mPlease type [y] for yes or [n] for no and confirm your selection with [ENTER]"
read -r -p 'Waiting for input... ' update
2019-02-06 01:24:19 +01:00
2019-04-18 12:27:45 +02:00
if [ "$update" != Y ] && [ "$update" != y ] && [ "$update" != N ] && [ "$update" != n ]; then
echo -e "invalid input, aborting now"
exit
fi
if [ -z "$update" ]; then
echo -e "You didn't enter anything, aborting now."
exit
fi
if [ "$update" = Y ] || [ "$update" = y ]; then
# Updating and upgrading the system, without taking too much space
echo -e "\e[1;36m"Running apt-get update and apt-get dist-upgrade for you..."\e[0m"
echo -e "\e[1;36m"This will take a while, sometimes up to 1 hour"\e[0m"
sudo apt-get update && sudo apt-get dist-upgrade -y
echo -e "\e[1;36m"System successfully updated and upgraded!"\e[0m"
echo ""
fi
# Installing dependencies
#PYOWM for user pi
echo -e "\e[1;36m"Installing dependencies of the Inky-Calendar software"\e[0m"
echo -e "\e[1;36m"Checking if pyowm is installed for user pi"\e[0m"
if python3.5 -c "import pyowm" &> /dev/null; then
2019-04-18 12:53:46 +02:00
echo 'pyowm is installed, skipping installation of this package.'
else
echo 'pywom is not installed, attempting to install now'
pip3 install pyowm
fi
#PYOWM for user sudo
echo -e "\e[1;36m"Checking if pyowm is installed for user sudo"\e[0m"
if sudo python3.5 -c "import pyowm" &> /dev/null; then
2019-04-18 12:53:46 +02:00
echo 'pyowm is installed, skipping installation of this package.'
else
echo 'pywom is not installed, attempting to install now'
sudo pip3 install pyowm
fi
#Pillow for user pi
echo -e "\e[1;36m"Checking if Pillow (PIL) (v=5.3.0) is installed for user pi"\e[0m"
if python3.5 -c "import PIL" &> /dev/null; then
2019-04-18 12:53:46 +02:00
echo 'Pillow is installed, skipping installation of this package.'
else
echo 'Pillow is not installed, attempting to install now'
pip3 install Pillow==5.3.0
fi
#Pillow for user pi
echo -e "\e[1;36m"Checking if Pillow (PIL) (v=5.3.0) is installed for user sudo"\e[0m"
if sudo python3.5 -c "import PIL" &> /dev/null; then
2019-04-18 12:53:46 +02:00
echo 'Pillow is installed, skipping installation of this package.'
else
echo 'Pillow is not installed, attempting to install now'
sudo pip3 install Pillow==5.3.0
fi
#Ics.py for user pi
echo -e "\e[1;36m"Checking if ics is installed for user pi"\e[0m"
if python3.5 -c "import ics" &> /dev/null; then
2019-04-18 12:53:46 +02:00
echo 'ics is installed, skipping installation of this package.'
else
echo 'ics is not installed, attempting to install now'
pip3 install ics
fi
#Ics.py for user sudo
echo -e "\e[1;36m"Checking if ics is installed for user sudo"\e[0m"
if sudo python3.5 -c "import ics" &> /dev/null; then
2019-04-18 12:53:46 +02:00
echo 'ics is installed, skipping installation of this package.'
else
echo 'ics is not installed, attempting to install now'
sudo pip3 ics
fi
2018-10-16 21:05:19 +02:00
#feedparser for user pi
echo -e "\e[1;36m"Checking if feedparser is installed for user pi"\e[0m"
if python3.5 -c "import feedparser" &> /dev/null; then
2019-04-18 12:53:46 +02:00
echo 'feedparser is installed, skipping installation of this package.'
else
echo 'ics is not installed, attempting to install now'
pip3 install ics
fi
#feedparser for user sudo
echo -e "\e[1;36m"Checking if feedparser is installed for user sudo"\e[0m"
if sudo python3.5 -c "import feedparser" &> /dev/null; then
2019-04-18 12:53:46 +02:00
echo 'feedparser is installed, skipping installation of this package.'
else
echo 'feedparser is not installed, attempting to install now'
sudo pip3 feedparser
fi
2018-10-16 21:05:19 +02:00
#sudo pip3 install pyowm
#sudo pip3 install Pillow==5.3.0
#sudo pip3 install ics
#sudo pip3 install feedparser
#pip3 install pyowm
#pip3 install ics
#pip3 install feedparser
#pip3 install Pillow==5.3.0
echo -e "\e[1;36m"Finished installing all dependencies"\e[0m"
2019-04-18 11:45:20 +02:00
# Clone the repository, then delete some non-required files
2019-04-17 23:16:45 +02:00
echo -e "\e[1;36m"Installing the Inky-Calendar Software for your display"\e[0m"
2019-01-27 20:53:50 +01:00
cd
2019-04-18 11:45:20 +02:00
git clone https://github.com/aceisace/Inky-Calendar Inky-Calendar-temp
mkdir Inky-Calendar
cd Inky-Calendar-temp
cp -r Calendar /home/pi/Inky-Calendar/
cp README.md /home/pi/Inky-Calendar/
cp LICENSE /home/pi/Inky-Calendar/
cp -r .git /home/pi/Inky-Calendar/
2019-04-17 23:16:45 +02:00
# Make a copy of the sample settings.py file
cd /home/pi/Inky-Calendar/Calendar
cp settings.py.sample settings.py
# Remove the downloaded (temporary) directory
2019-04-18 11:45:20 +02:00
cd
sudo rm -r Inky-Calendar-temp
2019-01-27 20:53:50 +01:00
2019-02-06 01:07:37 +01:00
# add a short info
2019-04-17 23:16:45 +02:00
cat > /home/pi/Inky-Calendar/Info.txt << EOF
This document contains a short info of the Inky-Calendar software version
2019-01-27 20:53:50 +01:00
Version: 1.6
Installer version: 1.6 (Mid April 2019)
2019-04-17 23:16:45 +02:00
configuration file: /home/pi/Inky-Calendar/Calendar/settings.py
2019-02-06 00:11:54 +01:00
If the time was set correctly, you installed this software on:
2019-02-06 01:55:35 +01:00
EOF
2019-04-17 23:16:45 +02:00
echo "$(date)" >> /home/pi/Inky-Calendar/Info.txt
2019-02-06 01:55:35 +01:00
echo ""
2019-01-27 20:53:50 +01:00
# Setting up supervisor
2019-02-06 01:07:37 +01:00
echo -e "\e[1;36m"Setting up auto-start of script at boot"\e[0m"
2019-01-27 20:53:50 +01:00
sudo apt-get install supervisor -y
sudo bash -c 'cat > /etc/supervisor/conf.d/E-Paper.conf' << EOF
2019-02-06 00:11:54 +01:00
[program:E-Paper]
2019-04-17 23:16:45 +02:00
command = sudo /usr/bin/python3.5 /home/pi/Inky-Calendar/Calendar/E-Paper.py
stdout_logfile = /home/pi/Inky-Calendar/E-Paper.log
2019-02-06 00:11:54 +01:00
stdout_logfile_maxbytes = 1MB
2019-04-17 23:16:45 +02:00
stderr_logfile = /home/pi/Inky-Calendar/E-Paper-err.log
2019-02-06 00:11:54 +01:00
stderr_logfile_maxbytes = 1MB
2019-02-06 01:55:35 +01:00
EOF
2019-01-27 20:53:50 +01:00
sudo service supervisor start E-Paper
2019-04-17 23:16:45 +02:00
2019-02-06 01:55:35 +01:00
echo ""
2018-10-16 21:05:19 +02:00
2019-01-27 20:53:50 +01:00
# Final words
echo -e "\e[1;36m"The install was successful"\e[0m"
2019-04-17 23:16:45 +02:00
echo -e "\e[1;36m"The programm is set to start at every boot."\e[0m"
2019-01-27 20:53:50 +01:00
echo -e "\e[1;31m"Please enter your details in the file 'settings.py'."\e[0m"
echo -e "\e[1;31m"If this file is not modified, the programm will not start"\e[0m"
2018-10-16 21:05:19 +02:00
2019-01-27 20:53:50 +01:00
echo -e "\e[1;36m"To modify the settings file, enter:"\e[0m"
2019-04-17 23:16:45 +02:00
echo -e "\e[1;36m"nano /home/pi/Inky-Calendar/Calendar/settings.py"\e[0m"
2019-02-06 00:11:54 +01:00
echo -e "\e[1;36m"You can test if the programm works by typing:"\e[0m"
2019-04-17 23:16:45 +02:00
echo -e "\e[1;36m"python3.5 /home/pi/Inky-Calendar/Calendar/E-Paper.py"\e[0m"
2019-02-06 01:55:35 +01:00
fi