Sixfab_PPP_Installer/ppp_installer/install.sh

194 lines
5.5 KiB
Bash
Raw Normal View History

2020-11-18 18:12:00 +00:00
#!/bin/bash
2018-10-15 14:58:48 +00:00
2020-11-18 18:45:59 +00:00
REPO=revision
SIXFAB_PATH="/opt/sixfab"
PPP_PATH="/opt/sixfab/ppp_connection_manager"
2018-10-15 14:58:48 +00:00
YELLOW='\033[1;33m'
RED='\033[0;31m'
BLUE='\033[1;34m'
2018-10-15 14:58:48 +00:00
SET='\033[0m'
2020-11-18 18:45:59 +00:00
function debug()
{
echo $(date "+%Y/%m/%d - %H:%M:%S :") "$1"
}
2020-11-18 18:24:15 +00:00
2020-11-18 18:12:00 +00:00
function colored_echo
{
COLOR=${2:-$YELLOW}
echo -e "$COLOR $1 ${SET}"
}
2020-11-18 18:45:59 +00:00
# Check Sixfab path
if [[ -e $SIXFAB_PATH ]]; then
debug "Path already exist!"
else
sudo mkdir $SIXFAB_PATH
debug "Sixfab path is created."
fi
# Check PPP path
if [[ -e $PPP_PATH ]]; then
debug "Path already exist!"
else
sudo mkdir $PPP_PATH
debug "PPP path is created."
fi
2020-11-18 18:12:00 +00:00
colored_echo "Please choose your Sixfab Shield/HAT:"
colored_echo "1: GSM/GPRS Shield"
colored_echo "2: 3G, 4G/LTE Base Shield"
colored_echo "3: Cellular IoT App Shield"
colored_echo "4: Cellular IoT HAT"
colored_echo "5: Tracker HAT"
colored_echo "6: 3G/4G Base HAT"
2019-10-13 19:14:14 +00:00
2018-10-15 14:58:48 +00:00
read shield_hat
case $shield_hat in
2020-11-18 18:12:00 +00:00
1) colored_echo "You chose GSM/GPRS Shield";;
2) colored_echo "You chose Base Shield";;
3) colored_echo "You chose CellularIoT Shield";;
4) colored_echo "You chose CellularIoT HAT";;
5) colored_echo "You chose Tracker HAT";;
6) colored_echo "You chose 3G/4G Base HAT";;
*) colored_echo "Wrong Selection, exiting" ${RED}; exit 1;
2018-10-15 14:58:48 +00:00
esac
2020-11-18 18:12:00 +00:00
colored_echo "Downloading setup files..."
2020-11-18 18:24:15 +00:00
wget --no-check-certificate https://raw.githubusercontent.com/sixfab/Sixfab_PPP_Installer/$REPO/ppp_installer/chat-connect -O chat-connect
2018-10-15 14:58:48 +00:00
if [ $? -ne 0 ]; then
2020-11-18 18:12:00 +00:00
colored_echo "Download failed" ${RED}
2018-10-15 14:58:48 +00:00
exit 1;
fi
2020-11-18 18:24:15 +00:00
wget --no-check-certificate https://raw.githubusercontent.com/sixfab/Sixfab_PPP_Installer/$REPO/ppp_installer/chat-disconnect -O chat-disconnect
2018-10-15 14:58:48 +00:00
if [ $? -ne 0 ]; then
2020-11-18 18:12:00 +00:00
colored_echo "Download failed" ${RED}
exit 1;
2018-10-15 14:58:48 +00:00
fi
2020-11-18 18:24:15 +00:00
wget --no-check-certificate https://raw.githubusercontent.com/sixfab/Sixfab_PPP_Installer/$REPO/ppp_installer/provider -O provider
2018-10-15 14:58:48 +00:00
if [ $? -ne 0 ]; then
2020-11-18 18:12:00 +00:00
colored_echo "Download failed" ${RED}
exit 1;
2018-10-15 14:58:48 +00:00
fi
2020-10-21 15:02:46 +00:00
2020-11-18 18:12:00 +00:00
colored_echo "ppp and wiringpi (gpio tool) installing..."
apt-get install ppp wiringpi -y
2018-10-15 14:58:48 +00:00
2020-11-18 18:12:00 +00:00
colored_echo "What is your carrier APN?"
2018-10-15 14:58:48 +00:00
read carrierapn
while [ 1 ]
do
2020-11-18 18:12:00 +00:00
colored_echo "Does your carrier need username and password? [Y/n]"
read usernpass
case $usernpass in
[Yy]* ) while [ 1 ]
do
2020-11-18 18:12:00 +00:00
colored_echo "Enter username"
read username
2020-11-18 18:12:00 +00:00
colored_echo "Enter password"
read password
2019-05-02 13:52:46 +00:00
sed -i "s/noauth/#noauth\nuser \"$username\"\npassword \"$password\"/" provider
break
done
break;;
[Nn]* ) break;;
2020-11-18 18:12:00 +00:00
*) colored_echo "Wrong Selection, Select among Y or n" ${RED};;
esac
done
2020-11-18 18:12:00 +00:00
colored_echo "What is your device communication PORT? (ttyS0/ttyUSB3/etc.)"
2018-10-15 14:58:48 +00:00
read devicename
mkdir -p /etc/chatscripts
2020-10-21 15:02:46 +00:00
2018-10-15 14:58:48 +00:00
mv chat-connect /etc/chatscripts/
mv chat-disconnect /etc/chatscripts/
mkdir -p /etc/ppp/peers
sed -i "s/#APN/$carrierapn/" provider
sed -i "s/#DEVICE/$devicename/" provider
mv provider /etc/ppp/peers/provider
2019-12-03 11:11:23 +00:00
if ! (grep -q 'sudo route' /etc/ppp/ip-up ); then
2018-10-15 14:58:48 +00:00
echo "sudo route add default ppp0" >> /etc/ppp/ip-up
fi
if [ $shield_hat -eq 2 ]; then
2018-10-15 14:58:48 +00:00
if ! (grep -q 'max_usb_current' /boot/config.txt ); then
echo "max_usb_current=1" >> /boot/config.txt
fi
fi
while [ 1 ]
do
2020-11-18 18:12:00 +00:00
colored_echo "Do you want to activate auto connect/reconnect service at R.Pi boot up? [Y/n]"
read auto_reconnect
2018-10-15 14:58:48 +00:00
case $auto_reconnect in
2020-11-18 18:12:00 +00:00
[Yy]* ) colored_echo "Downloading setup file..."
2018-10-15 14:58:48 +00:00
2020-11-18 18:24:15 +00:00
wget --no-check-certificate https://raw.githubusercontent.com/sixfab/Sixfab_PPP_Installer/$REPO/ppp_installer/reconnect_service -O reconnect.service
2020-11-18 18:45:59 +00:00
wget --no-check-certificate https://raw.githubusercontent.com/sixfab/Sixfab_PPP_Installer/$REPO/ppp_installer/functions.sh
wget --no-check-certificate https://raw.githubusercontent.com/sixfab/Sixfab_PPP_Installer/$REPO/ppp_installer/configs.sh
2019-10-09 10:55:04 +00:00
if [ $shield_hat -eq 1 ]; then
2018-10-15 14:58:48 +00:00
2020-11-18 18:24:15 +00:00
wget --no-check-certificate https://raw.githubusercontent.com/sixfab/Sixfab_PPP_Installer/$REPO/ppp_installer/reconnect_gprsshield -O reconnect.sh
2018-10-15 14:58:48 +00:00
2019-10-09 10:55:04 +00:00
elif [ $shield_hat -eq 2 ]; then
2018-10-15 14:58:48 +00:00
2020-11-18 18:24:15 +00:00
wget --no-check-certificate https://raw.githubusercontent.com/sixfab/Sixfab_PPP_Installer/$REPO/ppp_installer/reconnect_baseshield -O reconnect.sh
2018-10-15 14:58:48 +00:00
2019-10-09 10:55:04 +00:00
elif [ $shield_hat -eq 3 ]; then
2018-10-15 14:58:48 +00:00
2020-11-18 18:24:15 +00:00
wget --no-check-certificate https://raw.githubusercontent.com/sixfab/Sixfab_PPP_Installer/$REPO/ppp_installer/reconnect_cellulariot_app -O reconnect.sh
2018-10-15 14:58:48 +00:00
2019-10-09 10:55:04 +00:00
elif [ $shield_hat -eq 4 ]; then
2020-11-18 18:24:15 +00:00
wget --no-check-certificate https://raw.githubusercontent.com/sixfab/Sixfab_PPP_Installer/$REPO/ppp_installer/reconnect_cellulariot -O reconnect.sh
2019-10-09 10:55:04 +00:00
elif [ $shield_hat -eq 5 ]; then
2020-11-18 18:24:15 +00:00
wget --no-check-certificate https://raw.githubusercontent.com/sixfab/Sixfab_PPP_Installer/$REPO/ppp_installer/reconnect_tracker -O reconnect.sh
2019-10-09 10:55:04 +00:00
2019-10-13 19:14:14 +00:00
elif [ $shield_hat -eq 6 ]; then
2020-11-18 18:24:15 +00:00
wget --no-check-certificate https://raw.githubusercontent.com/sixfab/Sixfab_PPP_Installer/$REPO/ppp_installer/reconnect_basehat -O reconnect.sh
2019-10-13 19:14:14 +00:00
2018-10-15 14:58:48 +00:00
fi
2020-11-18 18:45:59 +00:00
mv reconnect.sh $PPP_PATH
mv functions.sh $PPP_PATH
mv configs.sh $PPP_PATH
2018-10-15 14:58:48 +00:00
mv reconnect.service /etc/systemd/system/
systemctl daemon-reload
systemctl enable reconnect.service
break;;
2020-11-18 18:12:00 +00:00
[Nn]* ) echo -e "${YELLOW}To connect to internet run ${BLUE}\"sudo pon\"${YELLOW} and to disconnect run ${BLUE}\"sudo poff\" ${SET}"
2018-10-15 14:58:48 +00:00
break;;
2020-11-18 18:12:00 +00:00
*) colored_echo "Wrong Selection, Select among Y or n" ${RED};;
2018-10-15 14:58:48 +00:00
esac
done
read -p "Press ENTER key to reboot" ENTER
reboot