2017-10-02 19:36:29 +00:00
#!/bin/bash
2024-07-22 06:04:59 +00:00
## PRE INSTALLATION OPERATIONS
2017-10-02 19:36:29 +00:00
2024-06-30 03:49:36 +00:00
source $RECEIVER_BASH_DIRECTORY /variables.sh
source $RECEIVER_BASH_DIRECTORY /functions.sh
2024-06-18 20:51:03 +00:00
clear
2024-07-23 21:39:20 +00:00
log_project_title
log_title_heading "Setting up Duck DNS"
log_title_message "------------------------------------------------------------------------------"
2024-07-22 06:04:59 +00:00
if ! whiptail --backtitle " ${ RECEIVER_PROJECT_TITLE } " \
--title "Duck DNS Dynamic DNS" \
--yesno "Duck DNS is a free dynamic DNS service hosted on Amazon VPC.\n\nPLEASE NOTE:\n\nBefore continuing this setup it is recommended that you visit the Duck DNS website and signup for then setup a sub domain which will be used by this device. You will need both the domain and token supplied to you after setting up your account.\n\n http://www.duckdns.org\n\nContinue with Duck DNS update script setup?" \
18 78; then
2024-07-23 18:45:59 +00:00
echo ""
2024-07-23 21:39:20 +00:00
log_alert_heading "INSTALLATION HALTED"
log_alert_message "Setup has been halted at the request of the user"
2024-06-18 20:51:03 +00:00
echo ""
2024-07-23 21:39:20 +00:00
log_title_message "------------------------------------------------------------------------------"
log_title_heading "Duck DNS setup halted"
2024-06-18 20:51:03 +00:00
echo ""
exit 1
2017-10-02 19:36:29 +00:00
fi
2024-06-30 03:49:36 +00:00
2017-10-03 18:08:52 +00:00
## CHECK FOR PREREQUISITE PACKAGES
2017-10-02 19:36:29 +00:00
2024-07-23 21:39:20 +00:00
log_heading "Installing packages needed to fulfill PlaneFinder client dependencies"
2024-07-22 06:04:59 +00:00
2024-07-23 21:39:20 +00:00
check_package cron
check_package curl
2017-10-02 19:36:29 +00:00
2024-06-30 03:49:36 +00:00
2024-07-22 06:04:59 +00:00
## GATHER REQUIRED INFORMATION FROM THE USER
2017-10-02 19:36:29 +00:00
2024-07-23 21:39:20 +00:00
log_heading "Gather information required to configure Duck DNS support"
2024-07-22 06:04:59 +00:00
2024-07-23 21:39:20 +00:00
log_message "Asking the user for the sub domain to be assigned to this device"
2024-07-24 00:38:11 +00:00
duckdns_domain_title = "Duck DNS Sub Domain"
while [ [ -z $duckdns_domain ] ] ; do
duckdns_domain = $( whiptail --backtitle " ${ RECEIVER_PROJECT_TITLE } " \
--title " ${ duckdns_domain_title } " \
2024-07-22 06:04:59 +00:00
--inputbox "\nPlease enter the Duck DNS sub domain you selected after registering.\nIf you do not have one yet visit http://www.ducknds.org to obtain one." \
2024-07-24 00:38:11 +00:00
9 78 3>& 1 1>& 2 2>& 3)
if [ [ $duckdns_domain = = 0 ] ] ; then
2024-07-23 21:39:20 +00:00
log_alert_heading "INSTALLATION HALTED"
log_alert_message "Setup has been halted due to lack of required information"
2024-07-22 06:04:59 +00:00
echo ""
2024-07-23 21:39:20 +00:00
log_title_message "------------------------------------------------------------------------------"
log_title_heading "Duck DNS decoder setup halted"
2024-07-22 06:04:59 +00:00
exit 1
fi
2024-07-24 00:38:11 +00:00
duckdns_domain_title = "Duck DNS Sub Domain (REQUIRED)"
2024-06-18 20:51:03 +00:00
done
2024-07-23 21:39:20 +00:00
log_message "Asking the user for the Duck DNS token"
2024-07-24 00:38:11 +00:00
duckdns_token_title = "Duck DNS Token"
while [ [ -z $duckdns_token ] ] ; do
duckdns_token = $( whiptail --backtitle " ${ RECEIVER_PROJECT_TITLE } " \
--title " ${ duckdns_token_title } " \
2024-07-22 06:04:59 +00:00
--inputbox "\nPlease enter your Duck DNS token." \
2024-07-24 00:38:11 +00:00
8 78 3>& 1 1>& 2 2>& 3)
if [ [ $duckdns_domain = = 0 ] ] ; then
2024-07-23 21:39:20 +00:00
log_alert_heading "INSTALLATION HALTED"
log_alert_message "Setup has been halted due to lack of required information"
2024-07-22 06:04:59 +00:00
echo ""
2024-07-23 21:39:20 +00:00
log_title_message "------------------------------------------------------------------------------"
log_title_heading "Duck DNS setup halted"
2024-07-22 06:04:59 +00:00
exit 1
fi
2024-07-24 00:38:11 +00:00
duckdns_token_title = "Duck DNS Token (REQUIRED)"
2024-06-18 20:51:03 +00:00
done
2017-10-02 19:36:29 +00:00
2024-06-30 03:49:36 +00:00
2024-07-22 06:04:59 +00:00
## CREATE THE DUCK DNS SCRIPT
2017-10-02 19:36:29 +00:00
2024-07-23 21:39:20 +00:00
log_heading "Creating the Duck DNS script"
2017-10-02 19:36:29 +00:00
2024-06-30 03:49:36 +00:00
if [ [ ! -d $RECEIVER_BUILD_DIRECTORY /duckdns ] ] ; then
2024-07-23 21:39:20 +00:00
log_message "Creating the Duck DNS build directory"
2017-10-03 18:08:52 +00:00
echo ""
2024-07-22 21:57:59 +00:00
mkdir -v $RECEIVER_BUILD_DIRECTORY /duckdns 2>& 1 | tee -a $RECEIVER_LOG_FILE
2017-10-03 18:08:52 +00:00
echo ""
2017-10-02 19:36:29 +00:00
fi
2024-07-23 21:39:20 +00:00
log_message "Creating the Duck DNS update script"
2024-06-30 03:49:36 +00:00
tee $RECEIVER_BUILD_DIRECTORY /duckdns/duck.sh > /dev/null <<EOF
2024-07-24 00:38:11 +00:00
echo url = " https://www.duckdns.org/update?domains= ${ duckdns_domain } &token= ${ duckdns_token } &ip= " | curl -k -o $RECEIVER_BUILD_DIRECTORY /duckdns/duck.log
2017-10-02 19:36:29 +00:00
EOF
2024-07-23 21:39:20 +00:00
log_message "Adding execute permissions for only this user to the Duck DNS update script"
2017-10-03 18:11:01 +00:00
echo ""
2024-07-22 21:57:59 +00:00
chmod -v 700 $RECEIVER_BUILD_DIRECTORY /duckdns/duck.sh 2>& 1 | tee -a $RECEIVER_LOG_FILE
2017-10-03 18:11:01 +00:00
echo ""
2017-10-02 19:36:29 +00:00
2024-07-23 21:39:20 +00:00
log_message "Creating the Duck DNS cron file"
2017-10-03 18:08:52 +00:00
sudo tee /etc/cron.d/duckdns_ip_address_update > /dev/null <<EOF
2024-06-30 03:49:36 +00:00
# Updates IP address with duckdns.org
*/5 * * * * $RECEIVER_BUILD_DIRECTORY /duckdns/duck.sh >/dev/null 2>& 1
2017-10-03 18:08:52 +00:00
EOF
2017-10-02 19:36:29 +00:00
2024-07-23 21:39:20 +00:00
log_message "Executing the Duck DNS update script"
2017-10-03 18:08:52 +00:00
echo ""
2024-07-22 06:04:59 +00:00
$RECEIVER_BUILD_DIRECTORY /duckdns/duck.sh
2017-10-03 18:08:52 +00:00
echo ""
2017-10-02 19:36:29 +00:00
2024-06-30 03:49:36 +00:00
2017-10-03 18:08:52 +00:00
## SETUP COMPLETE
2017-10-02 19:36:29 +00:00
2024-07-23 21:39:20 +00:00
log_message " Returning to ${ RECEIVER_PROJECT_TITLE } root directory "
2024-07-22 06:04:59 +00:00
cd $RECEIVER_ROOT_DIRECTORY
2017-10-02 19:36:29 +00:00
2017-10-03 18:08:52 +00:00
echo ""
2024-07-23 21:39:20 +00:00
log_title_message "------------------------------------------------------------------------------"
log_title_heading "Duck DNS setup is complete"
2017-10-03 18:08:52 +00:00
echo ""
2024-06-30 03:49:36 +00:00
read -p "Press enter to continue..." discard
2017-10-02 19:36:29 +00:00
2017-10-03 18:08:52 +00:00
exit 0