freedomboneeee/src/freedombone

352 lines
9.1 KiB
Bash
Executable File

#!/bin/bash
#
# .---. . .
# | | |
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
#
# Freedom in the Cloud
#
# This install script is intended for use with Debian Jessie
#
# License
# =======
#
# Copyright (C) 2014-2016 Bob Mottram <bob@freedombone.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
NO_OF_ARGS=$#
PROJECT_NAME='freedombone'
export TEXTDOMAIN=$PROJECT_NAME
export TEXTDOMAINDIR="/usr/share/locale"
PROJECT_INSTALL_DIR=/usr/local/bin
if [ -f /usr/bin/${PROJECT_NAME} ]; then
PROJECT_INSTALL_DIR=/usr/bin
fi
source $PROJECT_INSTALL_DIR/${PROJECT_NAME}-vars
UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
for f in $UTILS_FILES
do
source $f
done
APP_FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
for f in $APP_FILES
do
source $f
done
command_options=$1
if [[ $command_options == "menuconfig-full" ]]; then
MINIMAL_INSTALL="no"
fi
if [[ $command_options == "menuconfig-onion" ]]; then
MINIMAL_INSTALL="yes"
ONION_ONLY="yes"
fi
if [ ! $CONFIGURATION_FILE ]; then
CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg
fi
if [ ! $COMPLETION_FILE ]; then
COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
fi
# before the interactive config so that wifi adaptors may be detected
setup_wifi_atheros
if [[ $command_options == "menuconfig"* ]]; then
if [[ "$2" == "--reset" ]]; then
if [ -f $CONFIGURATION_FILE ]; then
rm $CONFIGURATION_FILE
fi
if [ -f $COMPLETION_FILE ]; then
rm $COMPLETION_FILE
fi
if [ -f /usr/share/${PROJECT_NAME}/installed.txt ]; then
rm /usr/share/${PROJECT_NAME}/installed.txt
fi
if [ -f /root/removed ]; then
rm /root/removed
fi
fi
# clear the interactive file which indicates configuration success
interactive_file=$HOME/.${PROJECT_NAME}-interactive
if [ -f $interactive_file ]; then
rm $interactive_file
fi
interactive_configuration
# check that the interactive file was created
if [ ! -f $interactive_file ]; then
exit 6393562
fi
rm $interactive_file
else
while [[ $# > 1 ]]
do
key="$1"
case $key in
-h|--help)
show_help
;;
# load a configuration file
-c|--config)
shift
CONFIGURATION_FILE="$1"
INSTALLING_FROM_CONFIGURATION_FILE="yes"
break
;;
# username within /home
-u|--user)
shift
MY_USERNAME="$1"
;;
# default domain name
-d|--domain)
shift
DEFAULT_DOMAIN_NAME="$1"
;;
# The type of system
-s|--system)
shift
SYSTEM_TYPE="$1"
;;
# The dynamic DNS provider
--ddns)
shift
DDNS_PROVIDER="$1"
;;
# Username for the synamic DNS provider
--ddnsuser)
shift
DDNS_USERNAME="$1"
;;
# Password for the synamic DNS provider
--ddnspass)
shift
DDNS_PASSWORD="$1"
;;
# Whether this installation is on a Beaglebone Black
--bbb)
INSTALLING_ON_BBB="yes"
;;
# Static IP address for the system
--ip)
shift
LOCAL_NETWORK_STATIC_IP_ADDRESS=$1
;;
# IP address for the internet router
--iprouter)
shift
ROUTER_IP_ADDRESS=$1
;;
# ssh port
--ssh)
shift
SSH_PORT=$1
;;
# public mailing list name
--list)
shift
PUBLIC_MAILING_LIST="$1"
;;
# Number of CPU cores
--cores)
shift
CPU_CORES=$1
;;
# my name
--name)
shift
MY_NAME="$1"
;;
# my email address
--email)
shift
MY_EMAIL_ADDRESS="$1"
;;
# USB drive
--usb)
shift
USB_DRIVE=$1
;;
# Enable B.A.T.M.A.N
--batman)
shift
ENABLE_BATMAN="yes"
;;
# Mumble server password
--vpass)
shift
MUMBLE_SERVER_PASSWORD=$1
;;
# Mumble server port
--vport)
shift
MUMBLE_PORT=$1
;;
# DNS Nameserver 1
--ns1)
shift
NAMESERVER1=$1
;;
# DNS Nameserver 2
--ns2)
shift
NAMESERVER2=$1
;;
# DNS Nameserver 3
--ns3)
shift
NAMESERVER3=$1
;;
# DNS Nameserver 4
--ns4)
shift
NAMESERVER4=$1
;;
# DNS Nameserver 5
--ns5)
shift
NAMESERVER5=$1
;;
# DNS Nameserver 6
--ns6)
shift
NAMESERVER6=$1
;;
# Debian repository
--repo)
shift
DEBIAN_REPO=$1
;;
# clear the config file
--reset)
if [ -f $CONFIGURATION_FILE ]; then
rm $CONFIGURATION_FILE
fi
if [ -f $COMPLETION_FILE ]; then
rm $COMPLETION_FILE
fi
;;
# minimal install
--minimal)
shift
MINIMAL_INSTALL=$1
;;
*)
# unknown option
;;
esac
shift
done
fi
function parse_args {
if [[ $NO_OF_ARGS == 0 ]]; then
echo 'no_of_args = 0'
show_help
exit 0
fi
read_config_param 'DEFAULT_DOMAIN_NAME'
read_config_param 'MY_USERNAME'
read_config_param 'SYSTEM_TYPE'
read_config_param 'ONION_ONLY'
read_config_param 'DDNS_PROVIDER'
read_config_param 'DDNS_USERNAME'
read_config_param 'DDNS_PASSWORD'
if [ ! -d /home/$MY_USERNAME ]; then
echo $"There is no user '$MY_USERNAME' on the system. Use 'adduser $MY_USERNAME' to create the user."
exit 1
fi
if [ ! "$DEFAULT_DOMAIN_NAME" ]; then
if [[ $SYSTEM_TYPE != "mesh"* ]]; then
echo 'No default domain specified'
show_help
exit 2
fi
fi
if [ ! $MY_USERNAME ]; then
echo 'No username specified'
show_help
exit 3
fi
if [[ $SYSTEM_TYPE != "mesh"* ]]; then
if [[ "$DDNS_PROVIDER" != 'none' ]]; then
if [[ $ONION_ONLY == "no" ]]; then
if [ ! $DDNS_USERNAME ]; then
echo $'Please provide the username for your dynamic DNS provider with the --ddnsuser option'
exit 7823
fi
if [ ! $DDNS_PASSWORD ]; then
echo $'Please provide the password for your dynamic DNS provider with the --ddnspass option'
exit 6382
fi
fi
fi
fi
if [ ! $SYSTEM_TYPE ]; then
SYSTEM_TYPE=$'full'
write_config_param "SYSTEM_TYPE" "$SYSTEM_TYPE"
fi
if [[ $(is_valid_variant) == "0" ]]; then
echo $"'$SYSTEM_TYPE' is an unrecognised ${PROJECT_NAME} variant. Possible variants are:"
show_available_variants
exit 367245
fi
}
# run some initial tests
clear
${PROJECT_NAME}-tests
if [ ! "$?" = "0" ]; then
exit 768252
fi
clear
echo ''
echo $'Setting up the base installation'
echo ''
export DEBIAN_FRONTEND=noninteractive
upgrade_installation_from_previous_versions
setup_utils
setup_email
setup_web
setup_apps $command_options
setup_final
echo ''
echo "${PROJECT_NAME} installation is complete"
exit 0