#!/bin/bash # initialize variables FIDIANVERSION="1.3.3" OPTDEV=$FIDIANVERSION OPTDOCKERADD="" OPTDRYRUN=0 OPTUPDATEONLY=0 OPTRECONFIGUREONLY=0 TTYD_VERSION="1.7.4" RESTART_TTYD="0" os="" osversion="" os_allowed=";debian;raspbian;docker;" osversion_allowed=";10.buster;11.bullseye;12.bookworm" TMP="" TZ="UTC" dockeropts="" [ "$FIDIAN_DEV" == "1" ] && OPTDEV="master" declare -a CFGOPTIONS CFGOPTIONS[1]="YOUR_SYSTEM;Your system name;Johnny's FidoMailer;64;required" CFGOPTIONS[2]="YOUR_LOCATION;Your geographical location;Frankfurt, germany;64;required" CFGOPTIONS[3]="YOUR_HOSTNAME;Your hostname;john.kennmer.net;64;required" CFGOPTIONS[4]="ENABLE_TTYD;Enable TTYd as a service?;;YN;required" CFGOPTIONS[5]="WEB_PASSWORD;Web Password;SECRET123;32;" CFGOPTIONS[6]="LINK_NAME;Link name;FidoNet;32;required" CFGOPTIONS[7]="LINK_DOMAIN;Link domain;fidonet;32;required" CFGOPTIONS[8]="YOUR_NAME;Your full name;John Doe;64;required" CFGOPTIONS[9]="YOUR_AKA;Your full AKA;2:240/5853.1;32;required" CFGOPTIONS[10]="UPLINK_HOST;Your Uplink's hostname or IP;kuehlbox.wtf;64;required" CFGOPTIONS[11]="UPLINK_PORT;Your Uplink's binkp port;24554;32;" CFGOPTIONS[12]="UPLINK_AKA;Your Uplink's AKA;2:240/5853;32;required" CFGOPTIONS[13]="SESSION_PASSWORD;Your Session password;;32;required" CFGOPTIONS[14]="PACKET_PASSWORD;Your Packet password;leave empty to use Session password;32;" CFGOPTIONS[15]="AREAFIX_PASSWORD;Your Areafix password;leave empty to use Packet password;32;" CFGOPTIONS[16]="FILEFIX_PASSWORD;Your Filefix password;leave empty to use Areafix password;32;" declare -A HELPTEXT HELPTEXT[ENABLE_TTYD]="TTYd provides a webinterface to fidian. While being very convinient, it's not very secure. So only enable this, if your fidian is inside an otherwise secured environment." HELPTEXT[WEB_PASSWORD]="Password for the webinterface provided by TTYd." HELPTEXT[LINK_NAME]="Name of this link. Can be anything, should be the name of the network. This will be used in communication with you, only." HELPTEXT[LINK_DOMAIN]="Domainname of this link. Can be anything, should be the name of the network in all lowercase letters. This will be used internally to group users, areas and access rights." HELPTEXT[YOUR_NAME]="Depending on the the rules of the network, you're currently setting up, this may be an alias or must be your full real name. FidoNet requires you to use your realname. If in doubt please check with the rules of your network." HELPTEXT[YOUR_SYSTEM]="Name of your system. Can be anything, like your BBS name or your name. This will be shown to any binkp connection." HELPTEXT[YOUR_LOCATION]="Your geographical location. This doesn't need to be 100% accurate, but give an idea of where your mailer is located." HELPTEXT[YOUR_HOSTNAME]="Fully qualified domain name of your system. If you want to be able to receive crashmails, this has to be reachable from the internet." HELPTEXT[UPLINK_HOST]="Hostname or IP of your uplink for this network." HELPTEXT[UPLINK_PORT]="Network port of your uplink for this network. Leave empty for default: 24554." HELPTEXT[UPLINK_AKA]="AKA of your uplink for this network." HELPTEXT[SESSION_PASSWORD]="Session password of your uplink for this network. Used for binkp authentication." HELPTEXT[PACKET_PASSWORD]="Packet password of your uplink for this network. Used for extracting received mail packages from your uplink. Leave empty to reuse the Session password." HELPTEXT[AREAFIX_PASSWORD]="Areafix password of your uplink for this network. Used for communicating with your uplinks Areafix bot. Leave empty to reuse the Packet password." HELPTEXT[FILEFIX_PASSWORD]="Filefix password of your uplink for this network. Used for communicating with your uplinks Filefix bot. Leave empty to reuse the Areafix password." declare -A CFG CFGFILES="/etc/husky/areas;ftn:ftn;660 /etc/binkd/binkd.cfg;ftn:ftn;660 /etc/binkd/binkd.inc;ftn:ftn;660 /home/fido/.golded/charsets.cfg;fido:fido;660 /etc/husky/config;ftn:ftn;660 /etc/husky/fileareas;ftn:ftn;660 /home/fido/.golded/golded.cfg;fido:fido;660 /home/fido/.golded/local.cfg;fido:fido;660 /home/fido/.golded/goldkeys.cfg;fido:fido;660 /etc/husky/links;ftn:ftn;660 /etc/husky/route;ftn:ftn;660 /etc/logrotate.d/husky;root:root;640 /etc/systemd/system/ttyd.service;root:fido;640" SCRIPTS="/usr/local/sbin/fidohelp.sh;root:ftn;750 /usr/local/sbin/fidorescan.sh;root:ftn;750 /usr/local/sbin/fidoecholist.sh;root:ftn;750 /usr/local/sbin/fidosubscribe.sh;root:ftn;750 /usr/local/sbin/fidounsubscribe.sh;root:ftn;750 /usr/local/sbin/poll.sh;root:ftn;750 /usr/local/sbin/toss.sh;root:ftn;750 /usr/local/sbin/tick.sh;root:ftn;750 /usr/local/sbin/echoscan.sh;root:ftn;750 /usr/local/sbin/netscan.sh;root:ftn;750 /usr/local/sbin/fidocomplete.sh;root:ftn;750 /usr/local/sbin/fixpermissions.sh;root:ftn;750 /usr/local/sbin/semacheck.sh;root:root;750 /usr/local/sbin/fidodashboard.sh;root:ftn;750 /usr/local/sbin/tmuxmenu.sh;root:ftn;750 /usr/local/sbin/tmuxblank.sh;root:ftn;750 /usr/local/sbin/fidowebpw.sh;root:ftn;750 /home/fido/.tmux.conf;fido:fido;640 /home/fido/.multitailrc;fido:fido;640" function print_status() { # meta function for printing formatted # status information to stdout if [ -z "$1" ] then prio=1 else prio="$1" fi dr1=""; dr2=""; if [ "$OPTDRYRUN" == "1" ] then dr1="NOT "; dr2=" (dry-run)"; fi case "${prio}" in 1) echo "" echo " * $dr1$2$dr2" ;; 2) echo " - $dr1$2$dr2" ;; 3) echo " . $dr1$2$dr2" ;; 0) echo "" echo "!!! $2" echo "" ;; *) echo " $dr1$2$dr2" ;; esac } function create_tmp() { # create temp-folder print_status 1 "Creating temp folder" TMP=$( mktemp -d ) } function delete_tmp() { # delete temp-folder print_status 1 "Deleting temp folder" rm -rf "${TMP}" } function helptext() { # print help and exit echo "" echo "Usage: ${0} [--debian|raspbian|docker]" echo "" echo " --docker - Install as Docker container" echo " --debian - Override OS autodetection to debian" echo " --raspbian - Override OS autodetection to raspbian" echo "" echo " --non-interactive - Don't ask any questions" echo " --update-only - Update only. No Re-Configuration" echo " --dry-run - Don't install anything. Just pretend" echo " --dev - Install current development snapshot" echo "" echo " --add-docker-parameters -- (must be last parameter)" echo " Additional parameters for docker run call." echo " eg: --add-docker-parameters -- --network fido --ip 192.168.23.42" echo "" echo " eg: ${0} --debian" echo "" exit 0 } function check_root() { # check if executed as root and exit with warning if not. if [ "$(whoami)" != "root" ] then print_status 0 "You need to run this as root. !!! eg: sudo ./$(/usr/bin/basename "$0")" exit 1 fi } function get_options() { # read parameters #options=$( getopt -o ":h" -l dev -l dry-run -l non-interactive -l update-only -l reconfigure-only -l debian -l raspbian -l docker -l buster -l bullseye -l bookworm -l add-docker-parameters: -l help -- "$@" ) #eval set -- "$options" while [ -n "$1" ] do case "$1" in -h|--help) helptext;; --dev) OPTDEV="master";; --update-only) OPTUPDATEONLY=1; DEBIAN_FRONTEND=noninteractive;; --reconfigure-only) OPTRECONFIGUREONLY=1; DEBIAN_FRONTEND=noninteractive;; --dry-run) OPTDRYRUN=1;; --non-interactive) DEBIAN_FRONTEND=noninteractive;; --docker) os="docker";; --debian) os="debian";; --raspbian) os="raspbian";; --buster) osversion="10";; --bullseye) osversion="11";; --bookworm) osversion="12";; --add-docker-parameters) OPTDOCKERADD="1";; --) shift if [ "$OPTDOCKERADD" == "1" ] then OPTDOCKERADD=" $*" fi break ;; esac shift done } function check_os() { # check whether running on debian or raspbian # and exit with warning if neither if ! echo "${os_allowed}" |grep -q ";$os;" 2>/dev/null then get_os if ! echo "${os_allowed}" |grep -q ";$os;" 2>/dev/null then print_status 0 "Unknown OS: ${os} !!! Only $( echo "${os_allowed}" |cut -d';' -f2 ) and $( echo "${os_allowed}" |cut -d';' -f3 ) are supported at the moment !!! Use parameter to override autodetection at your own risk: !!! ${0} <--$( echo "${os_allowed}" |cut -d';' -f2 )|$( echo "${os_allowed}" |cut -d';' -f3 )>\n" exit 2 fi fi } function get_os() { # get distribution name if [ -e /etc/rpi-issue ] then os="raspbian" else os="$( grep '^ID=' /etc/os-release |cut -d'=' -f2 )" fi } function check_osversion() { # get and check os version for compatibility with fidian if ! echo "${osversion_allowed}" |grep -q ";${osversion}." 2>/dev/null && [ "${os}" != "docker" ] then get_osversion if ! echo "${osversion_allowed}" |grep -q ";${osversion}." 2>/dev/null then print_status 0 "Wrong OS version: ${osversion} !!! Only $( echo "${osversion_allowed}" |cut -d';' -f2 |cut -d'.' -f2 ) and $( echo "${osversion_allowed}" |cut -d';' -f3 |cut -d'.' -f2 ) are supported at the moment. !!! Use second parameter to override autodetection at your own risk: !!! eg: ./fidosetup.sh --${os} --$( echo "${osversion_allowed}" |cut -d';' -f3 |cut -d'.' -f2 )" exit 3 fi fi } function get_osversion() { # get os version osversion="$( grep '^VERSION_ID=' /etc/os-release |cut -d'"' -f2 |cut -d'.' -f1 )" } function check_docker() { if [ ! -e /usr/bin/docker ] && [ ! -e /usr/local/bin/docker ] && [ "${os}" == "docker" ] then print_status 0 "No Docker installation found !!! Docker has to be installed already to build a fidian docker image. !!! Please follow the instructions at docker.com/get-started to !!! install Docker on your system." exit 4 fi } function error_exit() { if [ "$1" -gt "0" ] then c=$1 else c=255 fi if [ "$2" != "" ] then m=$2 else m="An error has occurred:" fi echo "" print_status 0 "$m" [ -e "${TMP}/output" ] && cat "${TMP}/output" echo "" delete_tmp exit "$c" } function clean_exit() { # delete TMP folder, clear dialog screen and exit # with given exit code or 0 if [ "$1" -gt "0" ] then c=$1 else c=0 fi dialog --clear echo "" delete_tmp print_status 0 "Exiting." exit "$c" } function read_fidianconfig() { # read fidian configuration from files in ~/.fidianconfig local k local v local c local n while read -r line do if [ -n "$line" ] then k=$( echo "$line" |cut -d' ' -f1 ) v=$( echo "$line" |cut -d' ' -f2- ) if [ "$v" == "$k" ] then c=${k//[0-9]} n=${k//$c/} if [ "$c" == "UPLINK_PORT_" ] then v="24554" elif [ "$c" == "PACKET_PASSWORD_" ] then v=${CFG[SESSION_PASSWORD_$n]} elif [ "$c" == "AREAFIX_PASSWORD_" ] then v=${CFG[PACKET_PASSWORD_$n]} elif [ "$c" == "FILEFIX_PASSWORD_" ] then v=${CFG[AREAFIX_PASSWORD_$n]} fi fi fi CFG[$k]="$v" done <"$1" } function copy_fidianconfig() { if [ -e "${TMP}/.fidianconfig" ] then if [ "$OPTDRYRUN" == "0" ] then cp "${TMP}/.fidianconfig" /home/fido/ fi fi } function copy_oldfidianconfig() { if [ -e ./fidoconfig.txt ] then cp ./fidoconfig.txt "${TMP}/.fidianconfig" elif [ -e ./.fidianconfig ] then cp ./.fidianconfig "${TMP}/" elif [ -e /home/fido/.fidianconfig ] then cp /home/fido/.fidianconfig "${TMP}/" fi } function d_helpbox() { local c c=${1//_[0-9]*/} dialog --backtitle "$2" --msgbox "${c}\n${HELPTEXT[$c]}" 10 30 #dialog --backtitle "$2" --msgbox "$c" 10 30 } function d_yesno() { # dialog driven inputbox for interactive fidian setup echo -n '' >"${TMP}/dialog.tmp" local d=2 while [ "$d" == "2" ] do dialog --backtitle "$2" --help-button --yesno "$3" 0 0 2>"${TMP}/dialog.tmp" d=$? if [ "$d" == "2" ] then d_helpbox "$1" "$2" fi done if [ "$d" == "0" ] then d=1 else d=0 fi echo "$1 $d" >>"${TMP}/.fidianconfig" } function d_inputbox() { # dialog driven inputbox for interactive fidian setup echo -n '' >"${TMP}/dialog.tmp" local d="" if [ "$6" == "required" ] then while [ "$d" == "" ] do local helploop=1 while [ $helploop -eq 1 ] do dialog --backtitle "$2" --help-button --max-input "$5" --inputbox "$3" "$4" "$5" 2>"${TMP}/dialog.tmp" helploop=$? if [ $helploop -eq 2 ] then d_helpbox "$1" "$2" elif [ $helploop -eq 1 ] then clean_exit 10 fi done d="$(cat "${TMP}/dialog.tmp")" done else dialog --backtitle "$2" --help-button --max-input "$5" --inputbox "$3" "$4" "$5" 2>"${TMP}/dialog.tmp" d="$(cat "${TMP}/dialog.tmp")" fi echo "$1 $d" >>"${TMP}/.fidianconfig" } function interactive() { # interactive setup routine using dialog local var_name local var_backtitle local var_description local var_example local var_position local var_length local var_required if [ -e ./.fidianconfig ] || [ -e /home/fido/.fidianconfig ] || [ -e ./fidoconfig.txt ] then [ "$DEBIAN_FRONTEND" != "noninteractive" ] && dialog --backtitle "Fidian v${FIDIANVERSION} interactive setup" --timeout 10 --yesno "Found existing configuration. Use it to automatically (re-)configure fidian?\n(\"YES\" is automatically selected after 10 seconds)" 0 0 2>"${TMP}/dialog.tmp" if [ "$?" != "1" ] || [ "$DEBIAN_FRONTEND" == "noninteractive" ] then [ "$DEBIAN_FRONTEND" != "noninteractive" ] && dialog --clear copy_oldfidianconfig fi fi if [ ! -e "${TMP}/.fidianconfig" ] then dialog --backtitle "Fidian v${FIDIANVERSION} interactive setup" --extra-button --extra-label Cancel --msgbox "Starting interactive mode.\nPlease answer the following questions for your primary uplink.\nIf you need help, check https://kuehlbox.wtf/fidian\nYou can add more uplinks, later." 12 40 if [ $? -lt 1 ] then echo -n "" >"${TMP}/.fidianconfig" for c in $( seq 1 ${#CFGOPTIONS[@]} ) do var_name=$( echo "${CFGOPTIONS[$c]}" |cut -d';' -f1 ) var_backtitle="Fidian v${FIDIANVERSION} interactive setup" var_description=$( echo "${CFGOPTIONS[$c]}" |cut -d';' -f2 ) var_example=$( echo "${CFGOPTIONS[$c]}" |cut -d';' -f3 ) var_position=10 var_length=$( echo "${CFGOPTIONS[$c]}" |cut -d';' -f4 ) var_required=$( echo "${CFGOPTIONS[$c]}" |cut -d';' -f5 ) if [ "${var_length}" == "YN" ] || [ "${var_length}" == "yn" ] then if [ "$c" -le "5" ] then d_yesno "${var_name}" "${var_backtitle}" "${var_description}\neg: ${var_example}" "${var_required}" else d_yesno "${var_name}_1" "${var_backtitle}" "${var_description}\neg: ${var_example}" "${var_required}" fi else if [ "${var_name}" == "WEB_PASSWORD" ] && [ "$(grep -c 'ENABLE_TTYD 0' "${TMP}/.fidianconfig" 2>/dev/null )" != "0" ] then echo "WEB_PASSWORD fidian" >>"${TMP}/.fidianconfig" else if [ "$c" -le "5" ] then d_inputbox "${var_name}" "${var_backtitle}" "${var_description}\neg: ${var_example}" "${var_position}" "${var_length}" "${var_required}" else d_inputbox "${var_name}_1" "${var_backtitle}" "${var_description}\neg: ${var_example}" "${var_position}" "${var_length}" "${var_required}" fi fi fi done dialog --backtitle "Fidian v${FIDIANVERSION} interactive setup" --msgbox "All done.\nContinuing with non-interactive installation." 10 40 dialog --clear else clean_exit 10 fi fi } function fidian_title() { # Print the Fidian title with version and copyright echo "Fidian v${FIDIANVERSION} (c) 2023 by Philipp Giebel " } function fidian_adduser() { # Add user "fido" if not found if [ "$( grep -c fido /etc/passwd)" -eq 0 ] then print_status 1 "Adding Fido user" if [ "$OPTDRYRUN" == "0" ] then /usr/sbin/adduser --quiet --disabled-password --gecos "" fido fi fi } function fidian_addaptkey() { # Add modern keyring as required since Debian 11+ if [ ! -e /usr/local/share/keyrings/ ] then mkdir -p /usr/local/share/keyrings/ fi if [ ! -e /usr/local/share/keyrings/fido.gpg ] then if [ "$os" == "debian" ] then wget --quiet -O "${TMP}/import.gpg" "https://repo.fido.de/debian/gpg.key" else wget --quiet -O" ${TMP}/import.gpg" "https://repo.fido.de/raspbian/gpg.key" fi gpg -q --no-default-keyring --keyring "${TMP}/tmp.gpg" --import "${TMP}/import.gpg" gpg -q --no-default-keyring --keyring "${TMP}/tmp.gpg" --export --output /usr/local/share/keyrings/fido.gpg rm -f "${TMP}/tmp.gpg" rm -f "${TMP}/import.gpg" fi if ! grep -q '/usr/local/share/keyrings/fido.gpg' /etc/apt/sources.list.d/fido.list 2>/dev/null then sed -i 's|^deb http|deb [signed-by=/usr/local/share/keyrings/fido.gpg] http|' /etc/apt/sources.list.d/fido.list fi } function fidian_addrepos() { # delete old repo config if found, # add new fido repo if not found if [ -e /etc/apt/sources.list.d/kuehlbox.list ] then print_status 0 "Removing old repository and replacing with repo.fido.de" if [ "$OPTDRYRUN" == "0" ] then rm -f /etc/apt/sources.list.d/kuehlbox.list fi fi if [ ! -e /etc/apt/sources.list.d/fido.list ] then print_status 1 "Adding Husky and GoldED Repository from fido.de" if [ "$OPTDRYRUN" == "0" ] then if [ "$os" == "debian" ] then if [ "$osversion" == "10" ] then wget --quiet -O /etc/apt/sources.list.d/fido.list https://repo.fido.de/debian/fido.buster.list elif [ "$osversion" == "11" ] then wget --quiet -O /etc/apt/sources.list.d/fido.list https://repo.fido.de/debian/fido.bullseye.list else wget --quiet -O /etc/apt/sources.list.d/fido.list https://repo.fido.de/debian/fido.bookworm.list fi else if [ "$osversion" == "10" ] then wget --quiet -O /etc/apt/sources.list.d/fido.list https://repo.fido.de/raspbian/fido.buster.list elif [ "$osversion" == "11" ] then wget --quiet -O /etc/apt/sources.list.d/fido.list https://repo.fido.de/raspbian/fido.bullseye.list else wget --quiet -O /etc/apt/sources.list.d/fido.list https://repo.fido.de/raspbian/fido.bookworm.list fi fi fi if [ ! -e /usr/local/share/keyrings/fido.gpg ] then print_status 1 "Installing fido.de repo gpg key" if [ "$OPTDRYRUN" == "0" ] then fidian_addaptkey fi fi print_status 1 "Updating package cache" if [ "$OPTDRYRUN" == "0" ] then apt-get -qq update >"${TMP}/output" 2>&1 || error_exit 100 fi else print_status 1 "Husky and GoldED Repository from fido.de already added" fi } function install_dependencies() { # install fidosetup.sh dependencies print_status 1 "Installing dependencies" if [ "$OPTDRYRUN" == "0" ] then apt-get -qqy install coreutils apt-transport-https sudo gnupg dialog wget unzip zip >"${TMP}/output" 2>&1 || error_exit 101 fi } function fidian_install() { # install fido packages from repo print_status 1 "Installing packages" print_status 2 "binkd, hpt, htick, nltools, sqpack, goldedplus, tmux, locales, multitail" if [ "$OPTDRYRUN" == "0" ] then apt-get -qqy install binkd hpt htick nltools sqpack goldedplus tmux locales multitail >"${TMP}/output" 2>&1 || error_exit 102 if [ "${osversion}" != "10" ] && [ "${osversion}" != "11" ] then print_status 2 "libftnjam-perl, libwebsockets-evlib-uv, libuv1, ttyd-fidian" apt-get -qqy install libftnjam-perl libwebsockets-evlib-uv libuv1 ttyd-fidian >"${TMP}/output" 2>&1 || error_exit 103 fi fi } function fidian_sudoconfig() { # sudo setup if ! grep -q fido /etc/sudoers 2>/dev/null then print_status 1 "Setting up sudo configuration for user \"fido\"" if [ "$OPTDRYRUN" == "0" ] then echo 'fido ALL=(ALL) ALL' | (EDITOR="tee -a" /usr/sbin/visudo >"${TMP}/output" 2>&1) || error_exit 107 echo 'fido ALL=(ftn) NOPASSWD: /usr/sbin/binkd, /usr/bin/hpt, /usr/bin/htick, /usr/bin/sqpack, /usr/bin/nlupd' | (EDITOR="tee -a" /usr/sbin/visudo >"${TMP}/output" 2>&1) || error_exit 107 echo 'fido ALL=(ALL) NOPASSWD: /usr/local/sbin/fidosetup.sh, /usr/local/sbin/fixpermissions.sh' | (EDITOR="tee -a" /usr/sbin/visudo >"${TMP}/output" 2>&1) || error_exit 107 fi fi } function fidian_addtogroup() { # add user fido to group ftn print_status 1 "adding fido user to group ftn" if [ "$OPTDRYRUN" == "0" ] then /usr/sbin/adduser --quiet fido ftn >"${TMP}/output" 2>&1 || error_exit 108 fi } function fidian_fixpath() { # fix path variable if needed if ! grep -q 'PATH="/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"' /etc/profile 2>/dev/null then print_status 2 "fixing PATH" if [ "$OPTDRYRUN" == "0" ] then sed -i 's|^PATH=.*|PATH="/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"|' /etc/profile 2>/dev/null fi fi } function fidian_disableinetd() { # disable inetd configuration for binkd if found if [ -e /etc/inetd.conf ] then if grep -q 'binkd' /etc/inetd.conf 2>/dev/null then if [ ! -e /etc/supervisor/conf.d/binkd.conf ] then print_status 1 "Disabling inetd start of binkd, running as daemon" if [ "$OPTDRYRUN" == "0" ] then /usr/sbin/service openbsd-inetd stop >/dev/null 2>&1 sed -i "/binkd/d" /etc/inetd.conf sleep 5 /usr/sbin/service openbsd-inetd start >/dev/null 2>&1 fi elif [ -e /etc/inetd.conf ] then print_status 1 "Disabling inetd start of binkd, running as daemon" if [ "$OPTDRYRUN" == "0" ] then sed -i "/binkd/d" /etc/inetd.conf fi fi fi fi } function fidian_genscripts() { local varname local f print_status 1 "Setting up scripts" for scriptfile in ${SCRIPTS} do f=$(echo -n "$scriptfile" |cut -d';' -f1) c=$( basename "$f" ) for o in $( seq 1 ${#CFGOPTIONS[@]} ) do varname=$( echo "${CFGOPTIONS[$o]}" |cut -d';' -f1 ) if [ "$o" -le "4" ] then sed -i "s|@${varname}@|${CFG[${varname}]}|g" "${TMP}/${c}" else sed -i "s|@${varname}@|${CFG[${varname}_1]}|g" "${TMP}/${c}" fi done done } function fidian_genconfig() { # generate configuration files for binkd, husky, golded, etc, from templates # using the configuration from /home/fido/.fidianconfig local maxnum local varname local f local c local u print_status 1 "Generating configuration files" if [ -e /home/fido/.fidianconfig ] then maxnum=$( grep -c 'LINK_NAME_' /home/fido/.fidianconfig 2>/dev/null ) print_status 2 "Setting up links" for cfgfile in ${CFGFILES} do f=$(echo -n "$cfgfile" |cut -d';' -f1) c=$( basename "$f" ) for o in $( seq 1 ${#CFGOPTIONS[@]} ) do varname=$( echo "${CFGOPTIONS[$o]}" |cut -d';' -f1 ) if [ "$o" -le 4 ] then sed -i "s|@${varname}@|${CFG[${varname}]}|g" "${TMP}/${c}" else sed -i "s|@${varname}@|${CFG[${varname}_1]}|g" "${TMP}/${c}" fi done done for num in $(seq 1 "${maxnum}") do echo " . ${CFG[LINK_NAME_$num]}" sed -i "s|@ADDRESSES@|${CFG[YOUR_AKA_$num]}@${CFG[LINK_DOMAIN_$num]} @ADDRESSES@|g" "${TMP}/binkd.cfg" sed -i "s|@ADDRESSES@|address ${CFG[YOUR_AKA_$num]}\n@ADDRESSES@|g" "${TMP}/config" if [ "$num" != "1" ] then sed -i "s|@OTHER_DOMAINS@|domain ${CFG[LINK_DOMAIN_$num]} /var/spool/ftn/outb 2\n@OTHER_DOMAINS@|g" "${TMP}/binkd.cfg" fi if [ "$num" == "1" ] then sed -i "s|@ADDRESSES@|ADDRESS ${CFG[YOUR_AKA_$num]} ;${CFG[LINK_DOMAIN_$num]}\n@ADDRESSES@|g" "${TMP}/golded.cfg" else sed -i "s|@ADDRESSES@|AKA ${CFG[YOUR_AKA_$num]} ;${CFG[LINK_DOMAIN_$num]}\n@ADDRESSES@|g" "${TMP}/golded.cfg" fi echo "" >>"${TMP}/binkd.inc" echo "node ${CFG[UPLINK_AKA_$num]}@${CFG[LINK_DOMAIN_$num]} ${CFG[UPLINK_HOST_$num]}:${CFG[UPLINK_PORT_$num]} ${CFG[SESSION_PASSWORD_$num]} i" >>"${TMP}/binkd.inc" echo "Link ${CFG[LINK_NAME_$num]} Uplink" >>"${TMP}/links" echo "Aka ${CFG[UPLINK_AKA_$num]}" >>"${TMP}/links" echo "ourAka ${CFG[YOUR_AKA_$num]}" >>"${TMP}/links" echo "Password ${CFG[PACKET_PASSWORD_$num]}" >>"${TMP}/links" echo "EchoMailFlavour Crash" >>"${TMP}/links" echo "areafixAutoCreateDefaults -a ${CFG[YOUR_AKA_$num]} -b Jam -p 3650 -dupeCheck move -dupeHistory 14 -d \"(${CFG[LINK_DOMAIN_$num]}) \" -g ${CFG[LINK_DOMAIN_$num]}" >>"${TMP}/links" echo "linkMsgBaseDir /var/spool/ftn/msgbase/fido" >>"${TMP}/links" echo "filebox /var/spool/ftn/filebase/fido" >>"${TMP}/links" echo "forwardRequests on" >>"${TMP}/links" echo "Packer zip" >>"${TMP}/links" echo "LinkGrp ${CFG[LINK_DOMAIN_$num]}" >>"${TMP}/links" echo "AccessGrp ${CFG[LINK_DOMAIN_$num]}" >>"${TMP}/links" echo "" >>"${TMP}/links" if [ "${CFG[LINK_DOMAIN_$num]}" == "fidonet" ] then echo "route crash ${CFG[UPLINK_AKA_$num]} 1:* 2:* 3:* 4:* 5:*" >>"${TMP}/route" else u=$( echo "${CFG[UPLINK_AKA_$num]}" |cut -d':' -f1 ) echo "route crash ${CFG[UPLINK_AKA_$num]} ${u}:*" >>"${TMP}/route" fi done fi sed -i "s|@ADDRESSES@||g" "${TMP}/golded.cfg" sed -i "s|@ADDRESSES@||g" "${TMP}/config" sed -i "s|@ADDRESSES@||g" "${TMP}/binkd.cfg" sed -i "s|@OTHER_DOMAINS@||g" "${TMP}/binkd.cfg" } function fidian_dltemplates() { # download config file templates from gitlab.ambhost.net print_status 1 "Downloading Fidian" wget --quiet -O "${TMP}/templates.zip" "https://gitlab.ambhost.net/scripts/fidian/-/archive/${OPTDEV}/fidian-${OPTDEV}.zip" >"${TMP}/output 2>&1" || error_exit 105 "Error downloading config templates" unzip -qqo "${TMP}/templates.zip" -d "${TMP}/" >"${TMP}/output 2>&1" || error_exit 106 "Error unzipping config templates" mv "${TMP}/fidian-${OPTDEV}/cfgs/"* "${TMP}/" mv "${TMP}/fidian-${OPTDEV}/cfgs/.multitailrc" "${TMP}/" mv "${TMP}/fidian-${OPTDEV}/cfgs/.tmux.conf" "${TMP}/" } function fidian_installttyd() { # install TTYD if [ ! -e /usr/local/bin/ttyd ] && [ ! -e /usr/bin/ttyd ] then print_status 1 "Installing TTYd" fi if [ ! -e /usr/local/bin/ttyd ] && [ ! -e /usr/bin/ttyd ] && [ "$OPTDRYRUN" == "0" ] then if [ "${osversion}" == "10" ] || [ "${osversion}" == "11" ] then wget --quiet -O /usr/bin/ttyd "https://github.com/tsl0922/ttyd/releases/download/${TTYD_VERSION}/ttyd.x86_64" >"${TMP}/output 2>&1" || error_exit 110 "Error downloading ttyd" fi chown root:fido /usr/bin/ttyd chmod 755 /usr/bin/ttyd fi } function fidian_enablettyd() { # enable TTYD as a service if [ "${CFG[ENABLE_TTYD]}" == "1" ] then if [ -e /etc/supervisor/conf.d/ttyd.conf ] then if grep -q "autostart=false" /etc/supervisor/conf.d/ttyd.conf then print_status 1 "Enabling TTYd service" RESTART_TTYD="1" if [ "$OPTDRYRUN" == "0" ] then sed -i 's/autostart=false/autostart=true/' /etc/supervisor/conf.d/ttyd.conf sed -i 's/autorestart=false/autorestart=true/' /etc/supervisor/conf.d/ttyd.conf fi fi elif [ -e /usr/bin/systemctl ] then if ! /usr/bin/systemctl -q is-active ttyd.service then print_status 1 "Enabling TTYd service" RESTART_TTYD="1" if [ "$OPTDRYRUN" == "0" ] then /usr/bin/systemctl daemon-reload >/dev/null 2>&1 /usr/bin/systemctl enable ttyd >/dev/null 2>&1 fi fi fi else if grep -q "autostart=true" /etc/supervisor/conf.d/ttyd.conf then if [ -e /etc/supervisor/conf.d/ttyd.conf ] then if grep -q "autostart=true" /etc/supervisor/conf.d/ttyd.conf then print_status 1 "Disabling TTYd service" RESTART_TTYD="1" if [ "$OPTDRYRUN" == "0" ] then sed -i 's/autostart=true/autostart=false/' /etc/supervisor/conf.d/ttyd.conf sed -i 's/autorestart=true/autorestart=false/' /etc/supervisor/conf.d/ttyd.conf fi fi elif [ -e /usr/bin/systemctl ] then if /usr/bin/systemctl -q is-active ttyd.service then print_status 1 "Disabling TTYd service" RESTART_TTYD="1" if [ "$OPTDRYRUN" == "0" ] then /usr/bin/systemctl daemon-reload >/dev/null 2>&1 /usr/bin/systemctl disable ttyd >/dev/null 2>&1 fi fi fi fi fi } function fidian_installstatbinkd() { # install stat-binkd.pl if [ ! -e /usr/local/bin/stat-binkd.pl ] then print_status 1 "Installing stat-binkd.pl" else print_status 1 "Updating stat-binkd.pl" rm -f /usr/local/bin/stat-binkd.pl fi if [ "$OPTDRYRUN" == "0" ] then wget --quiet -O /usr/local/sbin/stat-binkd.pl https://gitlab.ambhost.net/scripts/stat-binkd/-/raw/main/stat-binkd.pl >"${TMP}/output 2>&1" || error_exit 112 "Error downloading stat-binkd.pl" chown root:fido /usr/local/sbin/stat-binkd.pl chmod 750 /usr/local/sbin/stat-binkd.pl fi } function fidian_copyconfig() { # copy generated configuration files from tmp to their final locations print_status 1 "Copying configuration files to their destinations" if [ "$OPTDRYRUN" == "0" ] then for cfgfile in ${CFGFILES} do f=$(echo -n "$cfgfile" |cut -d';' -f1) ug=$(echo -n "$cfgfile" |cut -d';' -f2) u=$(echo -n "$ug" |cut -d':' -f1) g=$(echo -n "$ug" |cut -d':' -f2) m=$(echo -n "$cfgfile" |cut -d';' -f3) s=$( basename "$f" ) if [ "${s}" == "areas" ] || [ "${s}" == "fileareas" ] || [ "${s}" == "local.cfg" ] then if [ -e "${f}" ] then sizea=$(stat --printf="%s" "${TMP}/${s}" ) sizeb=$(stat --printf="%s" "${f}" ) if [ "$sizeb" -gt "$sizea" ] && [ "$( grep -c '2:5080/80' "${f}" 2>/dev/null)" != "2" ] then print_status 2 "skipping ${f} - found previous version." else install -D -o "$u" -g "$g" -m "$m" "${TMP}/${s}" "${f}" fi else install -D -o "$u" -g "$g" -m "$m" "${TMP}/${s}" "${f}" fi else install -D -o "$u" -g "$g" -m "$m" "${TMP}/${s}" "${f}" fi done fi } function fidian_createmissing() { # create missing folders and files print_status 1 "Creating missing files and directories" if [ "$OPTDRYRUN" == "0" ] then mkdir -p /var/spool/ftn/outb mkdir -p /var/spool/ftn/inb/insecure mkdir -p /var/spool/ftn/tmp/inb mkdir -p /var/spool/ftn/tmp/outb mkdir -p /var/spool/ftn/dupes mkdir -p /var/spool/ftn/nodelist mkdir -p /var/spool/ftn/fileboxes mkdir -p /var/spool/ftn/filebase mkdir -p /var/spool/ftn/transit mkdir -p /var/spool/ftn/flags mkdir -p /var/spool/ftn/msgbase/fido mkdir -p /usr/local/share/keyrings mkdir -p /var/log/husky touch /var/spool/ftn/msgbase/netmail.jdt touch /var/spool/ftn/msgbase/netmail.jdx touch /var/spool/ftn/msgbase/netmail.jhr touch /var/spool/ftn/msgbase/netmail.jlr touch /var/spool/ftn/msgbase/bad.jdt touch /var/spool/ftn/msgbase/bad.jdx touch /var/spool/ftn/msgbase/bad.jhr touch /var/spool/ftn/msgbase/bad.jlr touch /var/spool/ftn/msgbase/dupe.jdt touch /var/spool/ftn/msgbase/dupe.jdx touch /var/spool/ftn/msgbase/dupe.jhr touch /var/spool/ftn/msgbase/dupe.jlr touch /var/spool/ftn/msgbase/personal.mail.jdt touch /var/spool/ftn/msgbase/personal.mail.jdx touch /var/spool/ftn/msgbase/personal.mail.jhr touch /var/spool/ftn/msgbase/personal.mail.jlr touch /var/log/husky/hpt.log touch /var/log/husky/htick.log touch /var/log/binkd/binkd fi } function fidian_createcronjobs() { # create cronjob if [ ! -e /etc/cron.d/fido ] then print_status 1 "Installing cronjobs" if [ "$OPTDRYRUN" == "0" ] then echo "*/1 * * * * root /usr/local/sbin/semacheck.sh" >/etc/cron.d/fido echo "*/10 * * * * ftn touch /var/spool/ftn/flags/poll; touch /var/spool/ftn/flags/echoscan; touch /var/spool/ftn/flags/netscan" >>/etc/cron.d/fido echo '8 6 * * 3 ftn /usr/bin/cronic /usr/bin/sqpack -c /etc/husky/config "*"; chmod -R 770 /var/spool/ftn/msgbase; find /var/spool/ftn/msgbase -type f -exec chmod 660 "{}" \;' >>/etc/cron.d/fido print_status 2 "restarting cron" if [ -e /etc/supervisor/conf.d/cron.conf ] then if [ -e /var/run/supervisor.sock ] then /usr/bin/supervisorctl restart cron:cron_00 >/dev/null 2>&1 fi elif [ -e /usr/sbin/service ] then /usr/sbin/service cron restart >/dev/null 2>&1 fi fi fi } function fidian_installnodelists() { # download and install latest fidonet nodelist and bt_ibn.inc print_status 1 "Downloading FidoNet Nodelist" if [ "$OPTDRYRUN" == "0" ] then wget --quiet -O "${TMP}/nl.zip" https://kuehlbox.wtf/nlget/fido/nl || error_exit 120 "Error downloading FidoNet Nodelist" unzip -qqo "${TMP}/nl.zip" -d /var/spool/ftn/nodelist || error_exit 121 "Error unzipping FidoNet Nodelist" chown ftn:ftn /var/spool/ftn/nodelist/* chmod 660 /var/spool/ftn/nodelist/* print_status 2 "Downloading unofficial BinkD Nodelist" wget --quiet -O "${TMP}/btnl.zip" https://kuehlbox.wtf/BT_IBN.zip || error_exit 122 "Error downloading BinkD Nodelist" unzip -qqo "${TMP}/btnl.zip" -d /etc/binkd/ || error_exit 123 "Error unzipping BinkD Nodelist" chown ftn:ftn /etc/binkd/bt_ibn.inc chmod 660 /etc/binkd/bt_ibn.inc fi } function fidian_fixpermissions() { # fix permissions of files and folders print_status 1 "Fixing permissions" if [ "$OPTDRYRUN" == "0" ] then chown -fR fido:fido /home/fido/.golded chown -fR fido:fido /home/fido/.fidoconfig* chown -fR ftn:ftn /etc/binkd chown -fR ftn:ftn /etc/husky chown -fR ftn:ftn /var/spool/ftn chown -fR ftn:ftn /var/log/binkd chown -fR ftn:ftn /var/log/husky chmod -f 770 /home/fido/.golded chmod -f 660 /home/fido/.golded/* chmod -f 660 /home/fido/.fidoconfig* chmod -f 770 /etc/binkd chmod -f 660 /etc/binkd/* chmod -f 770 /etc/husky chmod -f 660 /etc/husky/* chmod -f 770 /var/log/binkd chmod -f 660 /var/log/binkd/* chmod -f 770 /var/log/husky chmod -f 660 /var/log/husky/* chmod -fR 770 /var/spool/ftn find /var/spool/ftn/ -type f -exec chmod -f 660 "{}" \; fi } function fidian_gengoldedconfig() { # copy golded example configuration from docs folder # if no existing files are found # compile golded nodelist if [ ! -e /home/fido/.golded/charsets.cfg ] || [ ! -e /home/fido/.golded/goldkeys.cfg ] || [ ! -e /home/fido/.golded/goldlang.cfg ] || [ ! -e /home/fido/.golded/goldhelp.cfg ] then print_status 1 "Copying GoldED default cfg files" if [ "$OPTDRYRUN" == "0" ] then if [ ! -e /home/fido/.golded/charsets.cfg ] then gunzip -c /usr/share/doc/goldedplus/examples/config/charsets.cfg.gz >/home/fido/.golded/charsets.cfg fi if [ ! -e /home/fido/.golded/goldkeys.cfg ] then gunzip -c /usr/share/doc/goldedplus/examples/config/goldkeys.cfg.gz >/home/fido/.golded/goldkeys.cfg fi if [ ! -e /home/fido/.golded/goldlang.cfg ] then gunzip -c /usr/share/doc/goldedplus/examples/config/goldlang.cfg.gz >/home/fido/.golded/goldlang.cfg fi if [ ! -e /home/fido/.golded/goldhelp.cfg ] then gunzip -c /usr/share/doc/goldedplus/examples/config/goldhelp.cfg.gz >/home/fido/.golded/goldhelp.cfg fi fi fi print_status 1 "compiling GoldED Nodelist" if [ "$OPTDRYRUN" == "0" ] then sudo -u fido gnlnx -Q -F /home/fido/.golded/golded.cfg 2>/dev/null fi } function fidian_installscripts() { # install latest fidian scripts if [ ! -e /usr/local/sbin/fidoconfig.sh ] || [ ! -e /usr/local/sbin/fidosetup.sh ] || [ ! -e /usr/local/sbin/fidouninstall.sh ] then print_status 1 "Installing Fidian scripts" else print_status 1 "Updating Fidian scripts" fi if [ "$OPTDRYRUN" == "0" ] then print_status 2 "fidoconfig.sh" install -D -o fido -g ftn -m 755 "${TMP}/fidian-${OPTDEV}/fidoconfig.sh" /usr/local/sbin/fidoconfig.sh print_status 2 "fidosetup.sh" install -D -o root -g ftn -m 755 "${TMP}/fidian-${OPTDEV}/fidosetup.sh" /usr/local/sbin/fidosetup.sh print_status 2 "fidouninstall.sh" install -D -o root -g ftn -m 755 "${TMP}/fidian-${OPTDEV}/fidouninstall.sh" /usr/local/sbin/fidouninstall.sh for scriptfile in ${SCRIPTS} do f=$(echo -n "$scriptfile" |cut -d';' -f1) ug=$(echo -n "$scriptfile" |cut -d';' -f2) u=$(echo -n "$ug" |cut -d':' -f1) g=$(echo -n "$ug" |cut -d':' -f2) m=$(echo -n "$scriptfile" |cut -d';' -f3) s=$( basename "$f" ) print_status 2 "$s" install -D -o "$u" -g "$g" -m "$m" "${TMP}/${s}" "${f}" done fi } function fidian_setlocales() { # set some standard locales for a smoother fido experience print_status 1 "Setting locales" if [ "$OPTDRYRUN" == "0" ] then if ! grep -q '^de_DE ISO-8859-1' /etc/locale.gen 2>/dev/null then print_status 2 "adding de_DE ISO-8859-1" echo "de_DE ISO-8859-1" >>/etc/locale.gen fi if ! grep -q '^de_DE.UTF-8 UTF-8' /etc/locale.gen 2>/dev/null then print_status 2 "adding de_DE.UTF-8 UTF-8" echo " - adding de_DE.UTF-8 UTF-8" echo "de_DE.UTF-8 UTF-8" >>/etc/locale.gen fi if ! grep -q '^de_DE@euro ISO-8859-15' /etc/locale.gen 2>/dev/null then print_status 2 "adding de_DE@euro ISO-8859-15" echo "de_DE@euro ISO-8859-15" >>/etc/locale.gen fi if ! grep -q '^en_GB ISO-8859-1' /etc/locale.gen 2>/dev/null then print_status 2 "adding en_GB ISO-8859-1" echo "en_GB ISO-8859-1" >>/etc/locale.gen fi if ! grep -q '^en_GB.ISO-8859-15 ISO-8859-15' /etc/locale.gen 2>/dev/null then print_status 2 "adding en_GB.ISO-8859-15 ISO-8859-15" echo "en_GB.ISO-8859-15 ISO-8859-15" >>/etc/locale.gen fi if ! grep -q '^en_GB.UTF-8 UTF-8' /etc/locale.gen 2>/dev/null then print_status 2 "adding en_GB.UTF-8 UTF-8" echo "en_GB.UTF-8 UTF-8" >>/etc/locale.gen fi if ! grep -q '^en_US ISO-8859-1' /etc/locale.gen 2>/dev/null then print_status 2 "adding en_US ISO-8859-1" echo "en_US ISO-8859-1" >>/etc/locale.gen fi if ! grep -q '^en_US.ISO-8859-15 ISO-8859-15' /etc/locale.gen 2>/dev/null then print_status 2 "adding en_US.ISO-8859-15 ISO-8859-15" echo "en_US.ISO-8859-15 ISO-8859-15" >>/etc/locale.gen fi if ! grep -q '^en_US.UTF-8 UTF-8' /etc/locale.gen 2>/dev/null then print_status 2 "adding en_US.UTF-8 UTF-8" echo "en_US.UTF-8 UTF-8" >>/etc/locale.gen fi print_status 2 "Running locale-gen (this will take a while)" /usr/sbin/locale-gen >"${TMP}/output" 2>&1 || error_exit 130 fi } function fidian_restartservices() { # restart services print_status 1 "(Re-)starting binkd" if [ "$OPTDRYRUN" == "0" ] then if [ -e /usr/bin/systemctl ] then /usr/bin/systemctl daemon-reload >/dev/null 2>&1 fi if [ -e /etc/supervisor/conf.d/binkd.conf ] then if [ -e /var/run/supervisor.sock ] then /usr/bin/supervisorctl stop binkd:binkd_00 >/dev/null 2>&1 sleep 5 /usr/bin/supervisorctl start binkd:binkd_00 >/dev/null 2>&1 fi elif [ -e /usr/sbin/service ] then /usr/sbin/service binkd stop >/dev/null 2>&1 sleep 5 /usr/sbin/service binkd start >/dev/null 2>&1 fi fi if [ "${CFG[ENABLE_TTYD]}" == "1" ] then if [ "${RESTART_TTYD}" == "1" ] then print_status 1 "(Re-)starting ttyd" if [ "$OPTDRYRUN" == "0" ] then if [ -e /etc/supervisor/conf.d/ttyd.conf ] then if [ -e /var/run/supervisor.sock ] then /usr/bin/supervisorctl stop ttyd:ttyd_00 >/dev/null 2>&1 sleep 5 /usr/bin/supervisorctl start ttyd:ttyd_00 >/dev/null 2>&1 fi elif [ -e /usr/sbin/service ] then /usr/sbin/service ttyd stop >/dev/null 2>&1 sleep 5 /usr/sbin/service ttyd start >/dev/null 2>&1 fi fi fi fi } function fidian_updatewebpassword() { # Update password for webinterface if [ -e /etc/supervisor/conf.d/ttyd.conf ] then if ! grep -q "${CFG[WEB_PASSWORD]:-fidian}" /etc/supervisor/conf.d/ttyd.conf 2>/dev/null then print_status 1 "Web Password changed. Updating..." sed -i "s@command=\(.*\) -cfido:[^ ]\+ \(.*\)/usr/local/sbin/fidodashboard.sh@command=\1 -cfido:${CFG[WEB_PASSWORD]:-fidian} \2/usr/local/sbin/fidodashboard.sh@" /etc/supervisor/conf.d/ttyd.conf RESTART_TTYD="1" fi elif [ -e /etc/systemd/system/ttyd.service ] then if ! grep -q "${CFG[WEB_PASSWORD]:-fidian}" /etc/systemd/system/ttyd.service 2>/dev/null then print_status 1 "Web Password changed. Updating..." sed -i "s@ExecStart=\(.*\) -cfido:[^ ]\+ \(.*\)/usr/local/sbin/fidodashboard.sh@ExecStart=\1 -cfido:${CFG[WEB_PASSWORD]:-fidian} \2/usr/local/sbin/fidodashboard.sh@" /etc/systemd/system/ttyd.service RESTART_TTYD="1" fi fi } function fidian_setpassword() { # wait 10 seconds for the user to enter a password # print warning if he didnt if [ "$OPTDRYRUN" == "0" ] && [ "$DEBIAN_FRONTEND" != "noninteractive" ] then echo "" echo ' * Press any key to set a password for user "fido"' if read -r -s -n 1 -t 10 -p ' or wait 10 seconds for default password "fidian".' then echo "" passwd fido else echo "fido:fidian" |/usr/sbin/chpasswd echo "" echo ' ! Using default password "fidian".' echo ' ! You should change it asap using the Fidian dashboard or' echo ' ! passwd on the commandline.' fi fi } function fidian_finished() { # print final text and first steps echo "" echo ' * ALL DONE!' echo ' You can now login via SSH or Docker as user "fido" and start using' echo ' Fidian by running "fidodashboard.sh". This will help you using the' echo ' most important features.' echo '' if [ "${CFG[ENABLE_TTYD]}" == "1" ] then echo ' Or use the webinterface at http://localhost:24580' echo '' fi echo '' echo ' Mail is polled and tossed automatically every 10 minutes or when you ' echo ' write any of your own.' echo ' You can also use the convenience scripts "poll.sh", "toss.sh", ' echo ' "tick.sh", "echoscan.sh" and "netscan.sh" to force running the ' echo ' corresponding function or "fidocomplete.sh" to run all of the above.' echo '' echo ' Use "fidoconfig.sh" to change your configuration and/or add links.' echo '' echo ' Use "fidouninstall.sh" to uninstall everything, you just installed.' echo '' echo ' Use "fidodashboard.sh" for easy access to all the fidian features.' echo "" } function docker_finished() { # print final text and first steps echo "" echo ' * ALL DONE!' echo ' You have successfully configured, installed and started a fidian docker ' echo ' container.' echo ' Configuration inside the docker container may take a few minutes, especially' echo ' on first run.' echo '' echo ' When finished, you can access fidian using the commandline:' echo ' docker exec -ti -u fido fidian bash' echo ' or:' echo ' docker exec -ti -u fido fidian fidodashboard.sh' echo '' if [ "${CFG[ENABLE_TTYD]}" == "1" ] then echo ' Or use the webinterface at http://localhost:24580' echo '' fi echo '' echo ' Mail is polled and tossed automatically every 10 minutes or when you ' echo ' write any of your own.' echo ' You can also use the convenience scripts "poll.sh", "toss.sh", ' echo ' "tick.sh", "echoscan.sh" and "netscan.sh" to force running the ' echo ' corresponding function or "fidocomplete.sh" to run all of the above.' echo '' echo ' Use "fidoconfig.sh" to change your configuration and/or add links.' echo '' echo ' Use "fidouninstall.sh" to uninstall everything, you just installed.' echo '' echo ' Use "fidodashboard.sh" for easy access to all the fidian features.' echo "" } function docker_devdownload() { # download dockerfile from gitlab.ambhost.net print_status 2 "downloading Dockerfile" if [ "$OPTDRYRUN" == "0" ] then wget --quiet -O "${TMP}/dockerfile.zip" "https://gitlab.ambhost.net/docker/fidian/-/archive/${OPTDEV}/fidian-${OPTDEV}.zip" >"${TMP}/output" 2>&1 || error_exit 140 "Error downloading Dockerfile" unzip -qqo" ${TMP}/dockerfile.zip" -d "${TMP}/" >"${TMP}/output" 2>&1 || error_exit 141 "Error downloading Dockerfile" fi } function docker_devbuild() { # build docker image if [ "$OPTDRYRUN" == "0" ] then pwd=$(pwd) cd "${TMP}/fidian-${OPTDEV}" >"${TMP}/output" 2>&1 || error_exit 140 docker build --no-cache -tfidian:latest . >"${TMP}/output" 2>&1 || error_exit 143 cd "$pwd" || error_exit 140 fi } function docker_stop() { # stop running fidian container if [ "$( docker ps |grep fidian |sed 's/.*\s\([^ ]\+\)$/\1/' )" == "fidian" ] then print_status 2 "Stopping running container" if [ "$OPTDRYRUN" == "0" ] then docker stop fidian >"${TMP}/output" 2>&1 || error_exit 144 fi fi } function docker_remove_container() { # remove stopped fidian container if [ "$( docker ps -a |grep fidian |sed 's/.*\s\([^ ]\+\)$/\1/' )" == "fidian" ] then print_status 2 "Removing old container" if [ "$OPTDRYRUN" == "0" ] then docker rm -v fidian >"${TMP}/output" 2>&1 || error_exit 145 fi fi } function docker_remove_image() { # remove old fidian image if [ "$OPTDEV" == "master" ] then DOCKERTAG="latest" else DOCKERTAG=$OPTDEV fi if [ -n "$( docker images fidian:${DOCKERTAG} -q )" ] then print_status 2 "Removing old image" if [ "$OPTDRYRUN" == "0" ] then docker image rm fidian:${DOCKERTAG} >"${TMP}/output" 2>&1 || error_exit 146 fi fi } function docker_buildopts() { # generate options for docker run local var_name read_fidianconfig "${TMP}/.fidianconfig" ports="-p 24554:24554" if [ "${CFG[ENABLE_TTYD]}" == "1" ] then ports="${ports} -p 24580:24580" fi dockeropts="${ports} -v fidian_config:/etc/fidian -v fidian_logs:/var/log/fidian -v fidian_data:/var/spool/ftn -e YOUR_SYSTEM='${CFG[YOUR_SYSTEM]}' -e YOUR_LOCATION='${CFG[YOUR_LOCATION]}' -e YOUR_HOSTNAME='${CFG[YOUR_HOSTNAME]}' -e ENABLE_TTYD='${CFG[ENABLE_TTYD]}' -e WEB_PASSWORD='${CFG[WEB_PASSWORD]}' " tz=$(cat /etc/timezone) if [ "$tz" != "" ] then dockeropts="${dockeropts}-e TZ='$tz' " fi for c in $(seq 1 "$( grep -c LINK_NAME_ "${TMP}/.fidianconfig" 2>/dev/null )") do for n in $(seq 1 ${#CFGOPTIONS[@]} ) do if [ "$n" -gt "5" ] then var_name=$( echo "${CFGOPTIONS[$n]}" |cut -d';' -f1 ) if [ "${CFG[${var_name}_$c]}" != "" ] then dockeropts="${dockeropts}-e ${var_name}_${c}='${CFG[${var_name}_${c}]}' " fi fi done done } function docker_run() { # run docker container print_status 2 "Running new container" docker_buildopts if [ "$OPTDRYRUN" == "0" ] then if [ "${OPTDEV}" == "master" ] then eval "docker run -i -t -d --name fidian --hostname fidian$OPTDOCKERADD $dockeropts fidian:latest" >"${TMP}/output" 2>&1 || error_exit 147 else eval "docker run -i -t -d --name fidian --hostname fidian$OPTDOCKERADD $dockeropts registry.ambhost.net/docker/fidian:$OPTDEV" >"${TMP}/output" 2>&1 || error_exit 147 fi fi } function docker_install() { # install docker container print_status 1 "Installing docker container" docker_stop docker_remove_container docker_remove_image if [ "${OPTDEV}" == "master" ] then docker_devdownload docker_devbuild fi docker_run } function main() { check_root check_os check_osversion check_docker create_tmp if [ "$OPTRECONFIGUREONLY" != "1" ] then install_dependencies interactive fi if [ "${os}" == "docker" ] then docker_install delete_tmp docker_finished else if [ "$OPTUPDATEONLY" != "1" ] && [ "$OPTRECONFIGUREONLY" != "1" ] then fidian_adduser fidian_addrepos fi if [ "$OPTRECONFIGUREONLY" != "1" ] then fidian_install fi fidian_dltemplates if [ "$OPTUPDATEONLY" != "1" ] then if [ "$OPTRECONFIGUREONLY" != "1" ] then fidian_sudoconfig fidian_addtogroup fidian_fixpath fidian_disableinetd fi copy_fidianconfig [ -e /home/fido/.fidianconfig ] && read_fidianconfig "/home/fido/.fidianconfig" fidian_genconfig fidian_copyconfig if [ "$OPTRECONFIGUREONLY" != "1" ] then fidian_createmissing fi fi if [ "$OPTRECONFIGUREONLY" != "1" ] then fidian_genscripts fidian_installscripts fidian_installttyd fidian_installstatbinkd fidian_installnodelists fi if [ "$OPTUPDATEONLY" != "1" ] then fidian_enablettyd fidian_updatewebpassword fidian_createcronjobs fidian_gengoldedconfig fidian_setlocales fidian_setpassword fi fidian_fixpermissions fidian_restartservices delete_tmp fidian_finished fi } fidian_title get_options "$@" main