Skip to content

Commit 64fd143

Browse files
committed
Update gatewaysetup.sh
1 parent feb879d commit 64fd143

1 file changed

Lines changed: 43 additions & 64 deletions

File tree

.setup/gatewaysetup.sh

Lines changed: 43 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,15 @@ GRN='\033[1;32m'
99
YLW='\033[1;33m'
1010
CYAN='\033[0;36m'
1111
NC='\033[0m' # No Color
12-
1312
APPSRVDIR='/home/pi/gateway/'
14-
#NODEDIR='/opt/nodejs'
15-
#NODEARCH=$(uname -m)
1613

1714
echo -e "${GRN}#########################################################################${NC}"
1815
echo -e "${GRN}# Low Power Lab Gateway App Setup #${NC}"
1916
echo -e "${GRN}#########################################################################${NC}"
2017
echo -e "${YLW}Note: script can take long on older Pis${NC}"
2118
echo -e "${YLW}Note: setup requires your input at certain steps${NC}"
2219

23-
if (whiptail --title " Gateway User License Agreement " --yesno "This software requires a license for any commercial use.\n\nBy installing this software I certify that either:\n\n- I use this software for personal/non-profit purposes\n- I have obtained a commercial license already" 12 78) then
20+
if (whiptail --title " Gateway User License Agreement " --yesno "This software is licensed with CC-BY-NC-4.0 and requires a commercial license for any commercial or for-profit use.\n\nBy installing this software I certify that either:\n\n- I use this software for personal/non-profit purposes\n- I have obtained a commercial license already" 12 78) then
2421
echo -e "${GRN}# LICENSE confirmation applied. #${NC}"
2522
else
2623
echo -e "${RED}# License required, exiting. #${NC}"
@@ -34,73 +31,42 @@ sudo apt-get update -m
3431
# sudo apt-get upgrade
3532
# echo -e "${CYAN}************* STEP: Running dist-upgrade *************${NC}"
3633
# sudo apt-get dist-upgrade
37-
#sudo apt-get clean
3834

3935
echo -e "${CYAN}************* STEP: Installing git & apache2-utils *************${NC}"
4036
sudo apt-get -y install git apache2-utils
4137

4238
#install NGINX
4339
echo -e "${CYAN}************* STEP: Install latest NGINX *************${NC}"
44-
#echo "deb http://mirrordirector.raspbian.org/raspbian/ stretch main contrib non-free rpi" | sudo tee -a /etc/apt/sources.list
45-
#sudo apt-get update
4640
sudo apt-get -y install nginx
47-
#sudo sed -e '/stretch/ s/^#*/#/' -i /etc/apt/sources.list
48-
#sudo apt-get update
4941

5042
# echo -e "${CYAN}************* STEP: Install PHP7 *************${NC}"
5143
sudo apt-get -y install php-common php-cli php-fpm
5244

53-
#install NodeJS
54-
# echo -e "${CYAN}************* STEP: Install NodeJS *************${NC}"
55-
# if [[ "$NODEARCH" == "armv6l" ]] ; then
56-
# mkdir ~/tempnode -p
57-
# cd ~/tempnode
58-
# wget https://nodejs.org/dist/v4.6.2/node-v4.6.2-linux-armv6l.tar.gz
59-
# tar -xzf node-v4.6.2-linux-armv6l.tar.gz
60-
# sudo rm node-v4.6.2-linux-armv6l.tar.gz
61-
# sudo rm -rf $NODEDIR
62-
# mkdir -p $NODEDIR
63-
# sudo mv node-v4.6.2-linux-armv6l/* $NODEDIR
64-
# sudo rm -rf ~/tempnode;
65-
# cd ~/
66-
# # sudo unlink /usr/bin/node;
67-
# # sudo unlink /usr/sbin/node;
68-
# # sudo unlink /sbin/node;
69-
# # sudo unlink /usr/local/bin/node;
70-
# # sudo unlink /usr/bin/npm;
71-
# # sudo unlink /usr/sbin/npm;
72-
# # sudo unlink /sbin/npm;
73-
# # sudo unlink /usr/local/bin/npm;
74-
# # sudo ln -s /opt/node/bin/node /usr/bin/node;
75-
# # sudo ln -s opt/node/bin/node /usr/sbin/node;
76-
# # sudo ln -s /opt/node/bin/node /sbin/node;
77-
# # sudo ln -s /opt/node/bin/node /usr/local/bin/node;
78-
# # sudo ln -s /opt/node/bin/npm /usr/bin/npm;
79-
# # sudo ln -s /opt/node/bin/npm /usr/sbin/npm;
80-
# # sudo ln -s /opt/node/bin/npm /sbin/npm;
81-
# # sudo ln -s /opt/node/bin/npm /usr/local/bin/npm;
82-
# echo 'Creating symbolic link to node in /usr/bin/'
83-
# sudo ln -sf $NODEDIR/bin/node /usr/bin/node
84-
# echo 'Creating symbolic link to nodejs in /usr/bin/'
85-
# sudo ln -sf $NODEDIR/bin/node /usr/bin/nodejs
86-
# echo 'Creating symbolic link to npm in /usr/bin/'
87-
# sudo ln -sf $NODEDIR/bin/npm /usr/bin/npm
88-
# else
89-
# curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -;
90-
# sudo apt-get -y install nodejs;
91-
# fi
92-
9345
#install latest NodeJS --- https://www.raspberrypi.org/forums/viewtopic.php?t=141770
9446
sudo wget -O - https://raw.githubusercontent.com/LowPowerLab/RaspberryPi-Gateway/master/.setup/Install-Node.sh | sudo bash
9547

9648
echo -e "${CYAN}************* STEP: Setup Gateway app & dependencies *************${NC}"
9749
sudo mkdir -p $APPSRVDIR #main dir where gateway app lives
9850
cd $APPSRVDIR || exit
99-
#could use git clone but that requires empty target directory which won't work if executed repeatedly
100-
#git clone --single-branch https://github.com/LowPowerLab/RaspberryPi-Gateway.git $APPSRVDIR
51+
10152
git init
10253
git remote add origin https://github.com/LowPowerLab/RaspberryPi-Gateway.git
103-
git pull origin master
54+
LASTTAG=$(curl --silent "https://api.github.com/repos/LowPowerLab/RaspberryPi-Gateway/releases/latest" | grep -Po '"tag_name": "\K.*?(?=")')
55+
WHICH=$(
56+
whiptail --title "Choose version to install" --menu "Pick version" 16 100 9 \
57+
"${LASTTAG}" "Latest stable release [recommended] (git checkout)" \
58+
"HEAD" "Latest available code [warning] (git pull)" 3>&2 2>&1 1>&3
59+
)
60+
if [ "$WHICH" == "HEAD" ]; then
61+
echo -e "${RED}# Installing LATEST GATEWAY CODE (HEAD). #${NC}"
62+
#could use git clone but that requires empty target directory which won't work if executed repeatedly
63+
git pull origin master
64+
else
65+
echo -e "${GRN}# Installing Latest Stable (v${LASTTAG}). #${NC}"
66+
git fetch --tags
67+
git checkout $LASTTAG
68+
fi
69+
10470
sudo npm install --unsafe-perm --build-from-source
10571
sudo npm cache verify #clear any caches/incomplete installs
10672
sudo mkdir $APPSRVDIR/logs -p
@@ -112,9 +78,9 @@ touch $APPSRVDIR/data/db/gateway_nonmatches.db
11278

11379
#create self signed certificate
11480
#WARNING: must do this *AFTER* the gateway app was git-cloned
115-
echo -e "${CYAN}************* STEP: Create self signed HTTPS certificate (5 year) *************${NC}"
81+
echo -e "${CYAN}************* STEP: Create self signed HTTPS certificate (10 year) *************${NC}"
11682
sudo mkdir $APPSRVDIR/data/secure -p
117-
sudo openssl req -new -x509 -nodes -days 1825 -newkey rsa:2048 -out $APPSRVDIR/data/secure/server.crt -keyout $APPSRVDIR/data/secure/server.key -subj "/C=US/ST=MI/L=Detroit/O=LowPowerLab/OU=IoT Department/CN=lowpowerlab.com"
83+
sudo openssl req -new -x509 -nodes -days 3650 -newkey rsa:2048 -out $APPSRVDIR/data/secure/server.crt -keyout $APPSRVDIR/data/secure/server.key -subj "/C=US/ST=MI/L=Detroit/O=LowPowerLab/OU=IoT Department/CN=lowpowerlab.com"
11884
sudo chown -R pi:pi $APPSRVDIR
11985

12086
#create uploads dir for user icons
@@ -129,28 +95,35 @@ touch $APPSRVDIR/data/secure/.htpasswd
12995
htpasswd -b $APPSRVDIR/data/secure/.htpasswd $HTTPUSER $HTTPPASS
13096
echo -e "You can change httpauth password using ${YLW}htpasswd $APPSRVDIR/data/secure/.htpasswd user newpassword${NC}"
13197

132-
echo -e "${CYAN}************* STEP: Copy default site config to sites-available *************${NC}"
133-
cp -rf $APPSRVDIR/.setup/default /etc/nginx/sites-available/default
98+
echo -e "${CYAN}************* STEP: Copy gateway site config to sites-available *************${NC}"
99+
cp -rf $APPSRVDIR/.setup/gateway /etc/nginx/sites-available/gateway
134100
#determine php-fpm version and replace in gateway site config
135101
phpfpmsock=$(grep -ri "listen = " /etc/php)
136102
phpfpmsock=${phpfpmsock##*/}
137-
sudo sed -i "s/PHPFPMSOCK/${phpfpmsock}/g" /etc/nginx/sites-available/default
103+
sudo sed -i "s/PHPFPMSOCK/${phpfpmsock}/g" /etc/nginx/sites-available/gateway
138104
cd /etc/nginx/sites-enabled
139-
sudo ln -s /etc/nginx/sites-available/default
105+
sudo ln -s /etc/nginx/sites-available/gateway
140106
sudo service nginx restart
141107

142-
echo -e "${CYAN}************* STEP: ATXRaspi shutdown script setup *************${NC}"
108+
echo -e "${CYAN}************* STEP: Fail2Ban install *************${NC}"
109+
if (whiptail --title "Proftpd" --yesno "Do you want to install Fail2Ban?\nNote: Fail2Ban couples into the NGINX webserver to ban clients that make repeated failed attempts to authenticate to the Gateway App." 12 78) then
110+
sudo apt-get -y install fail2ban
111+
cp -n $APPSRVDIR/.setup/jail.local /etc/fail2ban/
112+
sudo service fail2ban restart
113+
fi
114+
115+
echo -e "${CYAN}************* STEP: ATXRaspi/MightyHat shutdown script setup *************${NC}"
143116
if (whiptail --title "ATXRaspi shutdown script" --yesno "Do you have a MightyHat or ATXRaspi installed on this Pi?\nNote: the script will start running only after a reboot so make sure to your ATXRaspi is wired before next boot otherwise leaving the feedback GPIO7 floating can cause unexpected reboots/shutdown!" 12 78) then
144117
sudo wget https://raw.githubusercontent.com/LowPowerLab/ATX-Raspi/master/shutdownchecksetup.sh
145118
sudo bash shutdownchecksetup.sh && sudo rm shutdownchecksetup.sh
146119
fi
147120

148121
echo -e "${CYAN}************* STEP: Disable GPIO serial console *************${NC}"
149122
sudo raspi-config nonint do_serial 1
150-
# sudo wget https://raw.githubusercontent.com/lurch/rpi-serial-console/master/rpi-serial-console -O /usr/bin/rpi-serial-console && sudo chmod +x /usr/bin/rpi-serial-console
151-
# if [[ "$(rpi-serial-console status | grep wheezy)" == *"enabled"* ]]; then
152-
# sudo rpi-serial-console disable
153-
# fi
123+
124+
echo -e "${CYAN}************* STEP: Disconnect GPIO/ttyAMA0 serial port from BT module *************${NC}"
125+
echo "enable_uart=1" >> /boot/config.txt
126+
echo "dtoverlay=pi3-disable-bt" >> /boot/config.txt
154127

155128
echo -e "${CYAN}************* STEP: Run raspi-config *************${NC}"
156129
if (whiptail --title "Run raspi-config ?" --yesno "Would you like to run raspi-config?\nNote: you should run this tool and configure the essential settings of your Pi if you haven't done it yet!" 12 78) then
@@ -179,11 +152,17 @@ sudo systemctl daemon-reload
179152
sudo systemctl enable gateway.service
180153
sudo systemctl start gateway.service
181154

155+
echo -e "${CYAN}************* STEP: Proftpd install *************${NC}"
156+
if (whiptail --title "Proftpd" --yesno "Do you want to install Proftpd?\nNote: Proftpd makes it easy to connect to the Pi via FTP." 12 78) then
157+
sudo apt-get -y install proftpd
158+
fi
159+
160+
sudo apt-get clean
161+
182162
echo -e "${RED}Make sure: ${YLW}to edit your gateway settings from the UI or from settings.json5 (and restart to apply changes)${NC}"
183163
echo -e "${RED}By default ${YLW}the gateway app uses the GPIO serial port. Run ${GRN}raspi-config${NC} and ensure the GPIO serial is enabled and GPIO console is disabled.${NC}"
184164
echo -e "${YLW}If you use MoteinoUSB or another serial port you must edit the serial port setting or the app will not receive messages from your Moteino nodes.${NC}"
185165
echo -e "${RED}App restarts ${YLW}can be requested from the Gateway UI (power symbol button on settings page, or from the terminal via ${RED}sudo systemctl restart gateway.service${NC}"
186-
echo -e "${RED}Don't forget: ${YLW}install proftpd (choose standalone mode) if you plan to FTP transfer files to your Pi (very useful!) with ${GRN}sudo apt-get install proftpd${NC}"
187166
echo -e "${RED}Don't forget: ${YLW}install minicom - useful for serial port debugging with ${GRN}sudo apt-get install minicom${NC}"
188167
echo -e "${RED}Adding users: ${YLW}You can run tool again to add more gateway users (skip all other steps, reboot when done)${NC}"
189168
echo -e "${RED}! Important : ${YLW}If not done already - configure your Pi core settings (timezone, expand SD etc) by running ${GRN}raspi-config${NC}"

0 commit comments

Comments
 (0)