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
|
|
|
SIXFAB_PATH="/opt/sixfab"
|
|
|
|
PPP_PATH="/opt/sixfab/ppp_connection_manager"
|
|
|
|
|
2020-11-18 19:09:09 +00:00
|
|
|
REPO_PATH="https://raw.githubusercontent.com/sixfab/Sixfab_PPP_Installer"
|
|
|
|
BRANCH=revision
|
|
|
|
SOURCE_PATH="$REPO_PATH/$BRANCH/src"
|
|
|
|
SCRIPT_PATH="$REPO_PATH/$BRANCH/src/reconnect_scripts"
|
2020-11-19 08:19:04 +00:00
|
|
|
SCRIPT_NAME="ppp_reconnect.sh"
|
|
|
|
SERVICE_NAME="ppp_connection_manager.service"
|
2020-11-18 19:09:09 +00:00
|
|
|
|
2018-10-15 14:58:48 +00:00
|
|
|
YELLOW='\033[1;33m'
|
|
|
|
RED='\033[0;31m'
|
2019-05-02 13:42:04 +00:00
|
|
|
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
|
|
|
|
2019-05-02 13:42:04 +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 19:09:09 +00:00
|
|
|
wget --no-check-certificate $SOURCE_PATH/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 19:09:09 +00:00
|
|
|
wget --no-check-certificate $SOURCE_PATH/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 19:09:09 +00:00
|
|
|
wget --no-check-certificate $SOURCE_PATH/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
|
|
|
|
|
2019-05-02 13:42:04 +00:00
|
|
|
while [ 1 ]
|
|
|
|
do
|
2020-11-18 18:12:00 +00:00
|
|
|
colored_echo "Does your carrier need username and password? [Y/n]"
|
2019-05-02 13:42:04 +00:00
|
|
|
read usernpass
|
|
|
|
|
|
|
|
case $usernpass in
|
|
|
|
[Yy]* ) while [ 1 ]
|
|
|
|
do
|
|
|
|
|
2020-11-18 18:12:00 +00:00
|
|
|
colored_echo "Enter username"
|
2019-05-02 13:42:04 +00:00
|
|
|
read username
|
|
|
|
|
2020-11-18 18:12:00 +00:00
|
|
|
colored_echo "Enter password"
|
2019-05-02 13:42:04 +00:00
|
|
|
read password
|
2019-05-02 13:52:46 +00:00
|
|
|
sed -i "s/noauth/#noauth\nuser \"$username\"\npassword \"$password\"/" provider
|
2019-05-02 13:42:04 +00:00
|
|
|
break
|
|
|
|
done
|
|
|
|
|
|
|
|
break;;
|
|
|
|
|
|
|
|
[Nn]* ) break;;
|
2020-11-18 18:12:00 +00:00
|
|
|
*) colored_echo "Wrong Selection, Select among Y or n" ${RED};;
|
2019-05-02 13:42:04 +00:00
|
|
|
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
|
|
|
|
|
2019-05-02 13:42:04 +00:00
|
|
|
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]"
|
2019-05-02 13:42:04 +00:00
|
|
|
read auto_reconnect
|
2018-10-15 14:58:48 +00:00
|
|
|
|
2019-05-02 13:42:04 +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-19 08:19:04 +00:00
|
|
|
wget --no-check-certificate $SOURCE_PATH/$SERVICE_NAME
|
2020-11-18 19:09:09 +00:00
|
|
|
wget --no-check-certificate $SOURCE_PATH/functions.sh
|
|
|
|
wget --no-check-certificate $SOURCE_PATH/configs.sh
|
2020-11-18 18:45:59 +00:00
|
|
|
|
|
|
|
|
2019-10-09 10:55:04 +00:00
|
|
|
if [ $shield_hat -eq 1 ]; then
|
2018-10-15 14:58:48 +00:00
|
|
|
|
2020-11-19 08:19:04 +00:00
|
|
|
wget --no-check-certificate $SCRIPT_PATH/reconnect_gprsshield -O $SCRIPT_NAME
|
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-19 08:19:04 +00:00
|
|
|
wget --no-check-certificate $SCRIPT_PATH/reconnect_baseshield -O $SCRIPT_NAME
|
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-19 08:19:04 +00:00
|
|
|
wget --no-check-certificate $SCRIPT_PATH/reconnect_cellulariot_app -O $SCRIPT_NAME
|
2018-10-15 14:58:48 +00:00
|
|
|
|
2019-10-09 10:55:04 +00:00
|
|
|
elif [ $shield_hat -eq 4 ]; then
|
2019-04-12 13:47:20 +00:00
|
|
|
|
2020-11-19 08:19:04 +00:00
|
|
|
wget --no-check-certificate $SCRIPT_PATH/reconnect_cellulariot -O $SCRIPT_NAME
|
2019-10-09 10:55:04 +00:00
|
|
|
|
|
|
|
elif [ $shield_hat -eq 5 ]; then
|
|
|
|
|
2020-11-19 08:19:04 +00:00
|
|
|
wget --no-check-certificate $SCRIPT_PATH/reconnect_tracker -O $SCRIPT_NAME
|
2019-10-09 10:55:04 +00:00
|
|
|
|
2019-10-13 19:14:14 +00:00
|
|
|
elif [ $shield_hat -eq 6 ]; then
|
|
|
|
|
2020-11-19 08:19:04 +00:00
|
|
|
wget --no-check-certificate $SCRIPT_PATH/reconnect_basehat -O $SCRIPT_NAME
|
2019-10-13 19:14:14 +00:00
|
|
|
|
2018-10-15 14:58:48 +00:00
|
|
|
fi
|
|
|
|
|
2020-11-19 08:19:04 +00:00
|
|
|
mv $SCRIPT_NAME $PPP_PATH
|
2020-11-18 18:45:59 +00:00
|
|
|
mv functions.sh $PPP_PATH
|
|
|
|
mv configs.sh $PPP_PATH
|
2020-11-19 08:19:04 +00:00
|
|
|
mv $SERVICE_NAME /etc/systemd/system/
|
2018-10-15 14:58:48 +00:00
|
|
|
|
|
|
|
systemctl daemon-reload
|
2020-11-19 08:19:04 +00:00
|
|
|
systemctl enable $SERVICE_NAME
|
2018-10-15 14:58:48 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2019-05-02 13:42:04 +00:00
|
|
|
read -p "Press ENTER key to reboot" ENTER
|
2020-06-04 09:12:42 +00:00
|
|
|
reboot
|