freedombone/src/freedombone-utils-setup

1178 lines
34 KiB
Plaintext
Raw Normal View History

2016-07-03 17:13:34 +02:00
#!/bin/bash
#
# .---. . .
# | | |
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
#
# Freedom in the Cloud
#
# Setup functions
#
# License
# =======
#
2017-06-22 12:55:28 +02:00
# Copyright (C) 2014-2017 Bob Mottram <bob@freedombone.net>
2016-07-03 17:13:34 +02:00
#
# 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/>.
2016-09-22 19:11:31 +02:00
if [ ! $PROJECT_NAME ]; then
PROJECT_NAME='freedombone'
fi
2017-06-22 12:55:28 +02:00
if [ ! $LOCAL_NAME ]; then
LOCAL_NAME=${PROJECT_NAME}
fi
2016-07-03 17:13:34 +02:00
DEFAULT_DOMAIN_NAME=
DEFAULT_DOMAIN_CODE=
MY_USERNAME=
2016-10-11 14:25:26 +02:00
if [ ! $SYSTEM_TYPE ]; then
SYSTEM_TYPE="full"
fi
2016-07-03 17:13:34 +02:00
# An optional configuration file which overrides some of these variables
2016-10-11 14:25:26 +02:00
if [ ! $CONFIGURATION_FILE ]; then
CONFIGURATION_FILE="$HOME/${PROJECT_NAME}.cfg"
fi
2016-07-03 17:13:34 +02:00
# Directory where source code is downloaded and compiled
INSTALL_DIR=$HOME/build
# device name for an attached usb drive
USB_DRIVE=/dev/sda1
# Location where the USB drive is mounted to
USB_MOUNT=/mnt/usb
# Number of days to keep backups for
BACKUP_MAX_DAYS=30
# file containing a list of remote locations to backup to
# Format: [username@friendsdomain//home/username] [ssh_password]
# With the only space character being between the server and the password
FRIENDS_SERVERS_LIST=/home/$MY_USERNAME/backup.list
export DEBIAN_FRONTEND=noninteractive
# used to limit CPU usage
CPULIMIT='/usr/bin/cpulimit -l 20 -e'
# command to create a git repository
CREATE_GIT_PROJECT_COMMAND='create-project'
# File which keeps track of what has already been installed
COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
# log file where details of remote backups are stored
REMOTE_BACKUPS_LOG=/var/log/remotebackups.log
# message if something fails to install
2017-06-22 18:52:52 +02:00
CHECK_MESSAGE="Check your internet connection, /etc/network/interfaces and /etc/resolvconf/resolv.conf.d/head, then delete $COMPLETION_FILE, run 'rm -fR /var/lib/apt/lists/* && apt-get update --fix-missing' and run this script again. If hash sum mismatches persist then try setting $DEBIAN_REPO to a different mirror and also change /etc/apt/sources.list."
2016-07-03 17:13:34 +02:00
# Default diffie-hellman key length in bits
DH_KEYLENGTH=2048
2017-07-15 18:27:52 +02:00
function support_256_colours {
if ! grep 'xterm-256color' /etc/skel/.profile; then
echo '' >> /etc/skel/.profile
echo 'export TERM=xterm-256color' >> /etc/skel/.profile
fi
if ! grep 'xterm-256color' /home/$MY_USERNAME/.profile; then
echo '' >> /home/$MY_USERNAME/.profile
echo 'export TERM=xterm-256color' >> /home/$MY_USERNAME/.profile
2017-07-15 18:33:02 +02:00
chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.profile
2017-07-15 18:27:52 +02:00
fi
}
2016-10-25 11:40:49 +02:00
function detect_usb_drive {
# sets to the highest available drive letter
# which is likely to be the last drive connected
read_config_param USB_DRIVE
partition_number='1'
if [[ "$1" == "nopath" ]]; then
partition_number=''
fi
2017-06-23 16:49:46 +02:00
if [ -b /dev/sda${partition_number} ]; then
USB_DRIVE=/dev/sda${partition_number}
fi
2016-10-25 11:40:49 +02:00
if [ -b /dev/sdb${partition_number} ]; then
USB_DRIVE=/dev/sdb${partition_number}
fi
if [ -b /dev/sdc${partition_number} ]; then
USB_DRIVE=/dev/sdc${partition_number}
fi
if [ -b /dev/sdd${partition_number} ]; then
USB_DRIVE=/dev/sdd${partition_number}
fi
if [ -b /dev/sde${partition_number} ]; then
USB_DRIVE=/dev/sde${partition_number}
fi
if [ -b /dev/sdf${partition_number} ]; then
USB_DRIVE=/dev/sdf${partition_number}
fi
if [ -b /dev/sdg${partition_number} ]; then
USB_DRIVE=/dev/sdg${partition_number}
fi
if [ -b /dev/sdh${partition_number} ]; then
USB_DRIVE=/dev/sdh${partition_number}
fi
write_config_param USB_DRIVE "$USB_DRIVE"
}
2016-11-30 21:10:51 +01:00
function separate_tmp_filesystem {
tmp_filesystem_size_mb=$1
if [ ! -d /tmp ]; then
mkdir -p /tmp
fi
if ! grep -q '/tmp' /etc/fstab; then
mount -t tmpfs -o size=${tmp_filesystem_size_mb}m tmpfs /tmp
echo "tmpfs /tmp tmpfs nodev,nosuid,noexec,nodiratime,size=${tmp_filesystem_size_mb}M 0 0" >> /etc/fstab
fi
}
2017-06-26 14:32:17 +02:00
function proc_filesystem_settings {
2017-08-05 21:08:57 +02:00
if ! grep -q "proc proc defaults,nodev,nosuid " /etc/fstab; then
sed -i 's|proc /proc proc defaults |proc /proc proc defaults,nodev,nosuid |g' /etc/fstab
fi
2017-06-26 14:32:17 +02:00
}
2016-11-29 14:01:00 +01:00
function remove_bluetooth {
2017-08-07 15:18:59 +02:00
bluetooth_changed=
bnep_exists=$(lsmod | grep bnep)
if [[ "$bnep_exists" == "bnep"* ]]; then
rmmod -f bnep
bluetooth_changed=1
fi
bluetooth_exists=$(lsmod | grep bluetooth)
if [[ "$bluetooth_exists" == "bluetooth"* ]]; then
rmmod -f bluetooth
bluetooth_changed=1
fi
2016-11-29 14:01:00 +01:00
if [ -f /etc/default/bluetooth ]; then
2017-06-28 14:52:14 +02:00
if grep -q "BLUETOOTH_ENABLED=" /etc/default/bluetooth; then
2016-11-29 14:01:00 +01:00
sed -i 's|BLUETOOTH_ENABLED=.*|BLUETOOTH_ENABLED=0|g' /etc/default/bluetooth
else
echo "BLUETOOTH_ENABLED=0" >> /etc/default/bluetooth
fi
2017-08-07 15:18:59 +02:00
bluetooth_changed=1
2016-11-29 14:01:00 +01:00
fi
2017-06-28 14:52:14 +02:00
if ! grep -q 'blacklist bnep' /etc/modprobe.d/bluetooth.conf; then
2016-11-29 14:01:00 +01:00
echo 'blacklist bnep' >> /etc/modprobe.d/bluetooth.conf
2017-08-07 15:18:59 +02:00
bluetooth_changed=1
2016-11-29 14:01:00 +01:00
fi
2017-06-28 14:52:14 +02:00
if ! grep -q 'blacklist btusb' /etc/modprobe.d/bluetooth.conf; then
2016-11-29 14:01:00 +01:00
echo 'blacklist btusb' >> /etc/modprobe.d/bluetooth.conf
2017-08-07 15:18:59 +02:00
bluetooth_changed=1
2016-11-29 14:01:00 +01:00
fi
2017-06-28 14:52:14 +02:00
if ! grep -q 'blacklist bluetooth' /etc/modprobe.d/bluetooth.conf; then
2016-11-29 14:01:00 +01:00
echo 'blacklist bluetooth' >> /etc/modprobe.d/bluetooth.conf
2017-08-07 15:18:59 +02:00
bluetooth_changed=1
fi
if [ $bluetooth_changed ]; then
update-initramfs -u -k `uname -r` -v
update-rc.d bluetooth remove
2016-11-29 14:01:00 +01:00
fi
}
2016-10-21 14:56:13 +02:00
function running_as_root {
if [[ $EUID != 0 ]] ; then
echo "0"
else
echo "1"
fi
}
2016-10-21 15:00:29 +02:00
function reset_usb_devices {
2016-10-21 15:10:57 +02:00
for xhci in /sys/bus/pci/drivers/?hci-pci ; do
2016-10-21 15:00:29 +02:00
if ! cd $xhci ; then
return
fi
2016-10-21 15:06:03 +02:00
echo "Resetting devices from $xhci..."
2016-10-21 15:00:29 +02:00
for i in ????:??:??.? ; do
echo -n "$i" > unbind
echo -n "$i" > bind
done
done
udevadm control --reload-rules
}
2016-11-02 18:03:56 +01:00
function install_backports_kernel {
# install backports kernel if possible
architecture_type=$(uname -a)
if [[ "$architecture_type" == *"amd64"* ]]; then
package_installed=$(dpkg-query -W -f='${Package}\n' linux-image-amd64 2>/dev/null)
if [ ! $package_installed ]; then
apt-get -yq install linux-image-amd64
fi
2016-11-02 18:03:56 +01:00
fi
}
2016-11-18 19:08:18 +01:00
function turn_off_rsys_logging {
2017-08-06 22:21:51 +02:00
if grep -q '/dev/null' /etc/rsyslog.conf; then
2017-08-05 23:23:52 +02:00
return
fi
2016-11-18 19:08:18 +01:00
sed -i 's|mail,news.none.*|mail,news.none /dev/null|g' /etc/rsyslog.conf
sed -i 's|auth,authpriv.\*.*|auth,authpriv.\* /dev/null|g' /etc/rsyslog.conf
sed -i 's|mail.info.*|mail.info /dev/null|g' /etc/rsyslog.conf
sed -i 's|mail.warn.*|mail.warn /dev/null|g' /etc/rsyslog.conf
sed -i 's|mail.err.*|mail.err /dev/null|g' /etc/rsyslog.conf
sed -i 's|daemon.\*.*|daemon.\* /dev/null|g' /etc/rsyslog.conf
sed -i 's|mail.\*.*|mail.\* /dev/null|g' /etc/rsyslog.conf
sed -i 's|user.\*.*|user.\* /dev/null|g' /etc/rsyslog.conf
sed -i 's|news.none;mail.none.*|news.none;mail.none /dev/null|g' /etc/rsyslog.conf
sed -i 's|\*.\*;auth,authpriv.none.*|\*.\*;auth,authpriv.none /dev/null|g' /etc/rsyslog.conf
sed -i 's|#cron.\*|cron.\*|g' /etc/rsyslog.conf
sed -i 's|cron.\*.*|cron.\* /dev/null|g' /etc/rsyslog.conf
shred -zu /var/log/wtmp*
shred -zu /var/log/debug*
shred -zu /var/log/cron.*
shred -zu /var/log/auth.*
shred -zu /var/log/mail.*
shred -zu /var/log/daemon.*
shred -zu /var/log/user.*
shred -zu /var/log/messages*
}
2016-07-03 17:13:34 +02:00
function initial_setup {
2016-10-16 20:50:56 +02:00
if [[ $(is_completed $FUNCNAME) == "1" ]]; then
2016-08-10 23:16:34 +02:00
return
fi
2017-06-14 11:50:46 +02:00
apt-get -yq remove --purge apache2-bin*
2016-10-23 20:38:14 +02:00
apt-get -yq dist-upgrade
apt-get -yq install ca-certificates
apt-get -yq install apt-utils
2017-08-25 19:27:12 +02:00
apt-get -yq install cryptsetup libgfshare-bin duplicity sshpass wget avahi-daemon
2016-10-23 20:38:14 +02:00
apt-get -yq install avahi-utils avahi-discover connect-proxy openssh-server
apt-get -yq install sudo git dialog build-essential avahi-daemon avahi-utils
apt-get -yq install avahi-discover avahi-autoipd iptables dnsutils net-tools
apt-get -yq install network-manager iputils-ping libnss-mdns libnss-myhostname
apt-get -yq install libnss-gw-name nano man ntp locales locales-all debconf
2017-07-10 11:08:56 +02:00
apt-get -yq install wireless-tools wpasupplicant usbutils zsh cpulimit screen
apt-get -yq install pinentry-curses eatmydata iotop bc hostapd
# With some VMs, the hardware cycles counter is emulated and deterministic,
# and thus predictible, so havege should not be used
if [[ $ARCHITECTURE != 'qemu'* ]]; then
apt-get -yq install haveged
fi
2016-08-10 23:16:34 +02:00
2017-02-24 16:44:01 +01:00
if [[ $ARCHITECTURE == 'qemu'* || $ARCHITECTURE == 'amd64' || $ARCHITECTURE == 'x86_64' || $ARCHITECTURE == 'i686' || $ARCHITECTURE == 'i386' ]]; then
2017-07-17 15:51:21 +02:00
apt-get -yq install grub2 lvm2
2017-02-24 16:44:01 +01:00
fi
2016-08-10 23:16:34 +02:00
if [ ! -d $INSTALL_DIR ]; then
mkdir -p $INSTALL_DIR
fi
2016-10-16 20:50:56 +02:00
mark_completed $FUNCNAME
2016-07-03 17:13:34 +02:00
}
2017-08-09 18:46:09 +02:00
function turn_off_magic_sysrq {
if grep -q 'kernel.sysrq = 0' /etc/sysctl.conf; then
return
fi
if grep -q 'kernel.sysrq' /etc/sysctl.conf; then
sed -i 's|#kernel.sysrq.*|kernel.sysrq = 0|g' /etc/sysctl.conf
sed -i 's|kernel.sysrq.*|kernel.sysrq = 0|g' /etc/sysctl.conf
else
echo 'kernel.sysrq = 0' >> /etc/sysctl.conf
fi
}
2017-06-21 21:59:33 +02:00
function setup_grub {
if [[ $ARCHITECTURE == 'qemu'* || $ARCHITECTURE == 'amd64' || $ARCHITECTURE == 'x86_64' || $ARCHITECTURE == 'i686' || $ARCHITECTURE == 'i386' ]]; then
2017-08-06 22:21:51 +02:00
if ! grep -q 'ifnames=0' /etc/default/grub; then
2017-08-09 18:34:44 +02:00
sed -i 's|GRUB_CMDLINE_LINUX_DEFAULT=.*|GRUB_CMDLINE_LINUX_DEFAULT="quiet ifnames=0 slub_debug=FZP slab_nomerge page_poison=1 panic=0"|g' /etc/default/grub
2017-06-21 21:59:33 +02:00
update-grub
fi
fi
}
function admin_user_sudo {
2016-10-18 12:16:04 +02:00
if ! grep -q "$MY_USERNAME ALL=(ALL) ALL" $rootdir/etc/sudoers; then
echo "$MY_USERNAME ALL=(ALL) ALL" >> $rootdir/etc/sudoers
fi
}
2016-07-03 17:13:34 +02:00
function search_for_attached_usb_drive {
2016-08-10 23:16:34 +02:00
# If a USB drive is attached then search for email,
# gpg, ssh keys and emacs configuration
2016-10-16 21:00:20 +02:00
if [[ $(is_completed $FUNCNAME) == "1" ]]; then
2016-08-10 23:16:34 +02:00
return
fi
detect_usb_drive
2016-08-10 23:16:34 +02:00
if [ -b $USB_DRIVE ]; then
if [ ! -d $USB_MOUNT ]; then
echo $'Mounting USB drive'
mkdir $USB_MOUNT
mount $USB_DRIVE $USB_MOUNT
fi
2016-10-08 20:32:04 +02:00
if [ -d $USB_MOUNT/.gnupg ]; then
echo $'Importing GPG keyring'
cp -r $USB_MOUNT/.gnupg /home/$MY_USERNAME
chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.gnupg
if [ ! -f /home/$MY_USERNAME/.gnupg/secring.gpg ]; then
echo $'GPG files did not copy'
exit 73529
2016-08-10 23:16:34 +02:00
fi
2016-10-08 20:32:04 +02:00
fi
2016-08-10 23:16:34 +02:00
2016-10-08 20:32:04 +02:00
if [ -f $USB_MOUNT/private_key.gpg ]; then
echo $'GPG private key found on USB drive'
MY_GPG_PRIVATE_KEY=$USB_MOUNT/private_key.gpg
2016-08-10 23:16:34 +02:00
fi
2016-10-08 20:32:04 +02:00
if [ -f $USB_MOUNT/public_key.gpg ]; then
echo $'GPG public key found on USB drive'
MY_GPG_PUBLIC_KEY=$USB_MOUNT/public_key.gpg
fi
2016-10-26 23:55:59 +02:00
if [ -f $USB_MOUNT/letsencrypt ]; then
echo $'Copying letsencrypt keys"'
cp -r $USB_MOUNT/letsencrypt /etc
fi
2016-08-10 23:16:34 +02:00
if [ -d $USB_MOUNT/.ssh ]; then
echo $'Importing ssh keys'
cp -r $USB_MOUNT/.ssh /home/$MY_USERNAME
chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.ssh
# for security delete the ssh keys from the usb drive
if [ ! -f /home/$MY_USERNAME/.ssh/id_rsa ]; then
echo $'ssh files did not copy'
exit 8
fi
fi
if [ -f $USB_MOUNT/.emacs ]; then
echo $'Importing .emacs file'
cp -f $USB_MOUNT/.emacs /home/$MY_USERNAME/.emacs
chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.emacs
fi
if [ -d $USB_MOUNT/.emacs.d ]; then
echo $'Importing .emacs.d directory'
cp -r $USB_MOUNT/.emacs.d /home/$MY_USERNAME
chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.emacs.d
fi
if [ -d $USB_MOUNT/ssl ]; then
echo $'Importing SSL certificates'
cp -r $USB_MOUNT/ssl/* /etc/ssl
chmod 640 /etc/ssl/certs/*
chmod 400 /etc/ssl/private/*
# change ownership of some certificates
if [ -d /etc/prosody ]; then
chown prosody:prosody /etc/ssl/private/xmpp.*
chown prosody:prosody /etc/ssl/certs/xmpp.*
fi
if [ -d /etc/dovecot ]; then
chown root:dovecot /etc/ssl/certs/dovecot.*
chown root:dovecot /etc/ssl/private/dovecot.*
fi
if [ -f /etc/ssl/private/exim.key ]; then
cp /etc/ssl/private/exim.key /etc/exim4
cp /etc/ssl/certs/exim.crt /etc/exim4
cp /etc/ssl/certs/exim.dhparam /etc/exim4
chown root:Debian-exim /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam
chmod 640 /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam
fi
fi
if [ -d $USB_MOUNT/personal ]; then
echo $'Importing personal directory'
cp -r $USB_MOUNT/personal /home/$MY_USERNAME
chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/personal
fi
else
if [ -d $USB_MOUNT ]; then
umount $USB_MOUNT
rm -rf $USB_MOUNT
fi
echo $'No USB drive attached'
fi
2016-10-16 20:50:56 +02:00
mark_completed $FUNCNAME
2016-07-03 17:13:34 +02:00
}
function mark_admin_user_account {
2016-10-16 20:50:56 +02:00
set_completion_param "Admin user" "$MY_USERNAME"
2016-07-03 17:13:34 +02:00
}
function remove_instructions_from_motd {
2017-08-05 23:15:32 +02:00
if grep -q "## " /etc/motd; then
sed -i '/## /d' /etc/motd
fi
2016-07-03 17:13:34 +02:00
}
function remove_default_user {
2016-08-10 23:16:34 +02:00
# make sure you don't use the default user account
if [[ $MY_USERNAME == "debian" ]]; then
echo 'Do not use the default debian user account. Create a different user with: adduser [username]'
exit 68
fi
# remove the default debian user to prevent it from becoming an attack vector
if [ -d /home/debian ]; then
userdel -r debian
echo 'Default debian user account removed'
fi
2016-07-06 20:45:58 +02:00
}
2016-07-24 11:20:15 +02:00
function create_completion_file {
2016-08-10 23:16:34 +02:00
if [ ! -f $COMPLETION_FILE ]; then
touch $COMPLETION_FILE
fi
2016-07-24 11:20:15 +02:00
}
function remove_management_engine_interface {
# see https://www.kernel.org/doc/Documentation/misc-devices/mei/mei.txt
# Disabling this interface doesn't cure the problems of ME, but it
# might stop an adversary in control of AMT from using the command
# interface to control the operating system.
if [ -f /dev/mei0 ]; then
rmmod mei_me
rmmod mei0
fi
blacklist_changed=
if [ ! -f /etc/modprobe.d/blacklist.conf ]; then
touch /etc/modprobe.d/blacklist.conf
blacklist_changed=1
fi
if ! grep -q "blacklist mei" /etc/modprobe.d/blacklist.conf; then
echo "blacklist mei" >> /etc/modprobe.d/blacklist.conf
blacklist_changed=1
fi
if ! grep -q "blacklist mei_me" /etc/modprobe.d/blacklist.conf; then
echo "blacklist mei_me" >> /etc/modprobe.d/blacklist.conf
blacklist_changed=1
fi
if [ $blacklist_changed ]; then
depmod -ae -E
update-initramfs -u
2017-05-02 11:59:31 +02:00
fi
}
2016-11-29 14:31:36 +01:00
function set_login_umask {
2017-08-07 18:31:37 +02:00
logindefs_umask=$(cat /etc/login.defs | grep UMASK | grep -v '#')
if [[ "$logindefs_umask" != *'077' ]]; then
2017-08-06 00:16:37 +02:00
sed -i 's|UMASK\t.*|UMASK\t\t077|g' /etc/login.defs
fi
2016-11-29 14:31:36 +01:00
}
2016-11-29 14:53:16 +01:00
function disable_deferred_execution {
systemctl stop atd
systemctl disable atd
}
2016-11-29 15:31:54 +01:00
function set_shadow_permissions {
chown root:root /etc/shadow
chmod 0000 /etc/shadow
chown root:root /etc/gshadow
chmod 0000 /etc/gshadow
}
2016-11-29 17:31:07 +01:00
function set_max_login_tries {
max_tries=$1
2017-06-28 14:52:14 +02:00
if ! grep -q ' deny=' /etc/pam.d/common-auth; then
2016-11-29 19:10:27 +01:00
sed -i "/pam_deny.so/a auth required\t\t\tpam_tally.so onerr=fail no_lock_time per_user deny=$max_tries" /etc/pam.d/common-auth
2016-11-29 17:31:07 +01:00
else
2017-08-06 00:13:28 +02:00
if ! grep -q " deny=$max_tries" /etc/pam.d/common-auth; then
sed -i "s| deny=.*| deny=$max_tries|g" /etc/pam.d/common-auth
fi
2016-11-29 19:10:27 +01:00
fi
2017-08-07 16:17:41 +02:00
if ! grep -q 'pam_tally.so' /etc/pam.d/common-account; then
2016-11-29 19:10:27 +01:00
sed -i '/pam_deny.so/a account required\t\t\tpam_tally.so' /etc/pam.d/common-account
2016-11-29 17:31:07 +01:00
fi
}
2016-11-29 20:30:36 +01:00
function limit_user_logins {
# overall max logins
2017-06-28 14:52:14 +02:00
if ! grep -q '* hard maxsyslogins' /etc/security/limits.conf; then
2016-11-29 20:30:36 +01:00
echo '* hard maxsyslogins 10' >> /etc/security/limits.conf
else
2017-08-06 00:07:31 +02:00
if ! grep -q '* hard maxsyslogins 10' /etc/security/limits.conf; then
sed -i 's|hard maxsyslogins.*|hard maxsyslogins 10|g' /etc/security/limits.conf
fi
2016-11-29 20:30:36 +01:00
fi
# Max logins for each user
2017-06-28 14:52:14 +02:00
if ! grep -q '* hard maxlogins' /etc/security/limits.conf; then
2016-11-29 20:30:36 +01:00
echo '* hard maxlogins 2' >> /etc/security/limits.conf
else
2017-08-06 00:07:31 +02:00
if ! grep -q '* hard maxlogins 2' /etc/security/limits.conf; then
sed -i 's|hard maxlogins.*|hard maxlogins 2|g' /etc/security/limits.conf
fi
2016-11-29 20:30:36 +01:00
fi
}
2016-11-29 21:34:29 +01:00
function remove_serial_logins {
2017-06-28 14:52:14 +02:00
if grep -q 'ttyS' /etc/securetty; then
2016-11-29 21:34:29 +01:00
cp /etc/securetty /etc/securetty_old
sed -i '/ttyS/d' /etc/securetty
fi
}
2016-11-30 14:40:17 +01:00
function set_sticky_bits {
world_writable=$(find / -xdev -type d -perm -002 \! -perm -1000)
for w in $world_writable; do
echo "Setting sticky bit on $w"
chmod +t $w
done
}
2016-11-30 16:43:31 +01:00
function disable_ctrl_alt_del {
2017-08-06 00:00:46 +02:00
ctrl_alt_del=$(ls -l /etc/systemd/system/ctrl-alt-del.target)
if [[ "$ctrl_alt_del" != *'/dev/null' ]]; then
ln -sf /dev/null /etc/systemd/system/ctrl-alt-del.target
fi
2016-11-30 16:43:31 +01:00
}
2016-11-30 10:41:56 +01:00
function lockdown_permissions {
2017-06-26 16:01:22 +02:00
if [ -d /root/.npm ]; then
find /root/.npm -name package.json -exec chmod 700 {} \;
fi
# All commands owned by root
2017-04-14 11:41:48 +02:00
if [ -d /root/.cache/yarn ]; then
rm -rf /root/.cache/yarn
fi
2017-03-18 12:24:19 +01:00
if [ -d /usr/local/share/.cache/yarn ]; then
rm -rf /usr/local/share/.cache/yarn
fi
2017-03-18 13:48:54 +01:00
if [ -f /usr/lib/ssl/certs/ssl-cert-snakeoil.pem ]; then
chown root:root /usr/lib/ssl/certs/ssl-cert-snake*
fi
2016-11-29 21:49:11 +01:00
if [ -d /bin ]; then
chown root:root /bin/*
fi
if [ -d /usr/bin ]; then
chown root:root /usr/bin/*
fi
if [ -d /usr/local/bin ]; then
chown root:root /usr/local/bin/*
fi
if [ -d /sbin ]; then
chown root:root /sbin/*
fi
if [ -d /usr/sbin ]; then
chown root:root /usr/sbin/*
fi
if [ -d /usr/local/sbin ]; then
chown root:root /usr/local/sbin/*
fi
if [ -d /usr/share/${PROJECT_NAME} ]; then
chown -R root:root /usr/share/${PROJECT_NAME}
chmod -R +r /usr/share/${PROJECT_NAME}
fi
2016-11-29 22:17:52 +01:00
# All libraries owned by root
2016-11-29 22:17:52 +01:00
if [ -d /lib ]; then
chown -R root:root /lib/*
fi
if [ -d /lib64 ]; then
chown -R root:root /lib64/*
fi
if [ -d /usr/lib ]; then
chown -R root:root /usr/lib/*
2017-09-10 18:04:02 +02:00
if [ -d /usr/lib/node_modules ]; then
chmod -R 750 /usr/lib/node_modules/*
fi
2016-11-29 22:17:52 +01:00
fi
if [ -d /usr/lib64 ]; then
chown -R root:root /usr/lib64/*
fi
# sudo permissions
chmod 4755 /usr/bin/sudo
chmod 4755 /usr/lib/sudo/sudoers.so
chown root:root /etc/sudoers
2016-11-30 14:12:15 +01:00
# permissions on email commands
2016-11-30 14:12:15 +01:00
if [ -f /usr/bin/procmail ]; then
chmod 6755 /usr/bin/procmail
fi
if [ -f /usr/sbin/exim ]; then
chmod u+s /usr/sbin/exim
fi
if [ -f /usr/sbin/exim4 ]; then
chmod u+s /usr/sbin/exim4
fi
2016-11-30 14:40:17 +01:00
set_sticky_bits
# Create some directories to correspond with users in passwords file
if [ ! -d /var/spool/lpd ]; then
mkdir /var/spool/lpd
fi
if [ ! -d /var/spool/news ]; then
mkdir /var/spool/news
fi
if [ ! -d /var/spool/uucp ]; then
mkdir /var/spool/uucp
fi
if [ ! -d /var/list ]; then
mkdir /var/list
fi
if [ ! -d /var/lib/gnats ]; then
mkdir /var/lib/gnats
fi
if [ ! -d /var/lib/saned ]; then
mkdir /var/lib/saned
fi
2016-12-03 18:57:00 +01:00
if [ -d /etc/prosody ]; then
2016-12-03 13:37:07 +01:00
chown -R prosody /etc/prosody
2016-12-03 18:57:00 +01:00
chmod -R 700 /etc/prosody/conf.d
2016-12-03 13:37:07 +01:00
fi
2016-12-03 18:57:00 +01:00
if [ -d /var/lib/prosody ]; then
2016-12-03 14:07:29 +01:00
chown -R prosody /var/lib/prosody
fi
2017-05-28 15:31:55 +02:00
if [ -d /etc/letsencrypt ]; then
chmod -R 600 /etc/letsencrypt
chmod -R g=rX /etc/letsencrypt
fi
2016-11-29 21:49:11 +01:00
}
2016-11-30 00:19:31 +01:00
function disable_core_dumps {
2017-08-06 00:07:31 +02:00
if ! grep -q '* hard core' /etc/security/limits.conf; then
2016-11-30 00:19:31 +01:00
echo '* hard core 0' >> /etc/security/limits.conf
else
2017-08-06 00:07:31 +02:00
if ! grep -q '* hard core 0' /etc/security/limits.conf; then
sed -i 's|hard core.*|hard core 0|g' /etc/security/limits.conf
fi
2016-11-30 00:19:31 +01:00
fi
}
function dummy_nologin_command {
if [ ! -f /sbin/nologin ]; then
echo '#!/bin/bash' > /sbin/nologin
chmod +x /sbin/nologin
fi
}
2016-11-30 18:54:45 +01:00
function disable_null_passwords {
2017-08-06 00:13:28 +02:00
if grep -q ' nullok_secure' /etc/pam.d/common-auth; then
sed -i 's| nullok_secure||g' /etc/pam.d/common-auth
fi
2016-11-30 18:54:45 +01:00
}
2017-05-01 13:25:15 +02:00
function create_usb_canary {
if [[ $SYSTEM_TYPE == "mesh"* ]]; then
return
fi
2017-05-01 13:28:44 +02:00
if [[ $(is_completed $FUNCNAME) == "1" ]]; then
return
fi
2017-05-01 13:25:15 +02:00
echo "ACTION==\"add\", KERNEL==\"sd*[!0-9]\", RUN+=\"/usr/local/bin/${PROJECT_NAME}-usb-canary\"" > /etc/udev/rules.d/00-usb-canary.rules
udevadm control --reload-rules
2017-05-01 13:28:44 +02:00
mark_completed $FUNCNAME
2017-05-01 13:25:15 +02:00
}
2016-07-03 17:13:34 +02:00
function setup_firewall {
2016-08-10 23:16:34 +02:00
function_check create_completion_file
create_completion_file
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check configure_firewall
configure_firewall
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check configure_firewall_ping
configure_firewall_ping
2016-07-24 11:20:15 +02:00
2017-04-25 13:28:26 +02:00
function_check firewall_drop_telnet
firewall_drop_telnet
2017-04-25 14:40:11 +02:00
function_check firewall_drop_spoofed_packets
firewall_drop_spoofed_packets
function_check firewall_rate_limits
firewall_rate_limits
2016-08-10 23:16:34 +02:00
function_check configure_firewall_for_dns
configure_firewall_for_dns
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check configure_firewall_for_avahi
configure_firewall_for_avahi
function_check global_rate_limit
global_rate_limit
2017-03-31 16:27:09 +02:00
function_check firewall_block_bad_ip_ranges
firewall_block_bad_ip_ranges
2016-07-03 17:13:34 +02:00
}
2017-05-27 15:03:52 +02:00
function setup_powerline {
2017-06-01 22:30:17 +02:00
if [ -f ~/${PROJECT_NAME}/src/${PROJECT_NAME}-powerline ]; then
if [ ! -f ~/.powerline.bash ]; then
cp ~/${PROJECT_NAME}/src/${PROJECT_NAME}-powerline ~/.powerline.bash
else
HASH1=$(sha256sum ~/${PROJECT_NAME}/src/${PROJECT_NAME}-powerline | awk -F ' ' '{print $1}')
HASH2=$(sha256sum ~/.powerline.bash | awk -F ' ' '{print $1}')
if [[ "$HASH1" != "$HASH2" ]]; then
cp ~/${PROJECT_NAME}/src/${PROJECT_NAME}-powerline ~/.powerline.bash
fi
fi
if [ ! -f /etc/skel/.powerline.bash ]; then
cp ~/${PROJECT_NAME}/src/${PROJECT_NAME}-powerline /etc/skel/.powerline.bash
else
HASH1=$(sha256sum ~/${PROJECT_NAME}/src/${PROJECT_NAME}-powerline | awk -F ' ' '{print $1}')
HASH2=$(sha256sum /etc/skel/.powerline.bash | awk -F ' ' '{print $1}')
if [[ "$HASH1" != "$HASH2" ]]; then
cp ~/${PROJECT_NAME}/src/${PROJECT_NAME}-powerline /etc/skel/.powerline.bash
fi
fi
2017-05-27 15:03:52 +02:00
else
2017-06-01 22:30:17 +02:00
if [ -f /home/${MY_USERNAME}/${PROJECT_NAME}/src/${PROJECT_NAME}-powerline ]; then
if [ ! -f ~/.powerline.bash ]; then
cp /home/${MY_USERNAME}/${PROJECT_NAME}/src/${PROJECT_NAME}-powerline ~/.powerline.bash
else
HASH1=$(sha256sum /home/${MY_USERNAME}/${PROJECT_NAME}/src/${PROJECT_NAME}-powerline | awk -F ' ' '{print $1}')
HASH2=$(sha256sum ~/.powerline.bash | awk -F ' ' '{print $1}')
if [[ "$HASH1" != "$HASH2" ]]; then
cp /home/${MY_USERNAME}/${PROJECT_NAME}/src/${PROJECT_NAME}-powerline ~/.powerline.bash
fi
fi
if [ ! -f /etc/skel/.powerline.bash ]; then
cp /home/${MY_USERNAME}/${PROJECT_NAME}/src/${PROJECT_NAME}-powerline /etc/skel/.powerline.bash
else
HASH1=$(sha256sum /home/${MY_USERNAME}/${PROJECT_NAME}/src/${PROJECT_NAME}-powerline | awk -F ' ' '{print $1}')
HASH2=$(sha256sum /etc/skel/.powerline.bash | awk -F ' ' '{print $1}')
if [[ "$HASH1" != "$HASH2" ]]; then
cp /home/${MY_USERNAME}/${PROJECT_NAME}/src/${PROJECT_NAME}-powerline /etc/skel/.powerline.bash
fi
fi
2017-05-27 15:03:52 +02:00
fi
fi
if ! grep -q "powerline" ~/.bashrc; then
if [ -f ~/.powerline.bash ]; then
echo 'source ~/.powerline.bash' >> ~/.bashrc
fi
fi
if ! grep -q "powerline" /etc/skel/.bashrc; then
if [ -f /etc/skel/.powerline.bash ]; then
echo 'source ~/.powerline.bash' >> /etc/skel/.bashrc
fi
fi
}
2017-07-22 19:31:11 +02:00
function congestion_control {
# see /proc/sys/net/ipv4/tcp_congestion_control
if [ ! -f /etc/sysctl.d/10-custom-kernel-bbr.conf ]; then
echo 'net.core.default_qdisc=fq' > /etc/sysctl.d/10-custom-kernel-bbr.conf
echo 'net.ipv4.tcp_congestion_control=bbr' >> /etc/sysctl.d/10-custom-kernel-bbr.conf
sysctl --system
fi
2017-07-22 19:31:11 +02:00
}
2016-07-06 21:06:57 +02:00
function setup_utils {
2016-10-10 15:21:08 +02:00
read_config_param "PROJECT_REPO"
write_config_param "PROJECT_REPO" "$PROJECT_REPO"
function_check remove_management_engine_interface
remove_management_engine_interface
2017-05-02 11:59:31 +02:00
2017-07-15 18:27:52 +02:00
function_check support_256_colours
support_256_colours
2017-07-22 19:31:11 +02:00
function_check congestion_control
congestion_control
2017-06-19 15:48:51 +02:00
function_check enable_predictable_device_names
enable_predictable_device_names
2017-08-09 18:46:09 +02:00
function_check turn_off_magic_sysrq
turn_off_magic_sysrq
2016-11-30 21:10:51 +01:00
function_check separate_tmp_filesystem
separate_tmp_filesystem 150
2016-11-30 21:10:51 +01:00
2017-06-26 14:32:17 +02:00
function_check proc_filesystem_settings
proc_filesystem_settings
function_check optimise_filesystem
optimise_filesystem
2016-11-30 18:54:45 +01:00
function_check disable_null_passwords
disable_null_passwords
2016-11-30 16:43:31 +01:00
function_check disable_ctrl_alt_del
disable_ctrl_alt_del
function_check dummy_nologin_command
dummy_nologin_command
2016-11-30 00:19:31 +01:00
function_check disable_core_dumps
disable_core_dumps
2016-11-29 21:34:29 +01:00
function_check remove_serial_logins
remove_serial_logins
2016-11-29 17:31:07 +01:00
function_check set_max_login_tries
set_max_login_tries 10
2016-11-29 15:31:54 +01:00
function_check set_shadow_permissions
set_shadow_permissions
2016-11-29 14:01:00 +01:00
function_check remove_bluetooth
remove_bluetooth
2016-11-29 14:31:36 +01:00
function_check set_login_umask
set_login_umask
2016-11-29 14:53:16 +01:00
function_check disable_deferred_execution
disable_deferred_execution
2016-11-18 19:08:18 +01:00
function_check turn_off_rsys_logging
turn_off_rsys_logging
2016-11-02 18:03:56 +01:00
function_check install_backports_kernel
install_backports_kernel
2016-08-10 23:16:34 +02:00
function_check create_completion_file
create_completion_file
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check read_configuration
read_configuration
2016-07-24 11:20:15 +02:00
2016-10-09 12:07:05 +02:00
function_check check_system_type
check_system_type
2016-08-10 23:16:34 +02:00
function_check set_default_onion_domains
set_default_onion_domains
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check locale_setup
locale_setup
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check parse_args
parse_args
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check check_domains
check_domains
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check install_static_network
install_static_network
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check remove_default_user
remove_default_user
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check setup_firewall
setup_firewall
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check create_repo_sources
create_repo_sources
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check configure_dns
configure_dns
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check initial_setup
initial_setup
2016-07-24 11:20:15 +02:00
2017-06-21 21:59:33 +02:00
function_check setup_grub
setup_grub
2016-08-10 23:16:34 +02:00
function_check install_tor
install_tor
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
#function_check resolve_dns_via_tor
#resolve_dns_via_tor
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check install_command_line_browser
install_command_line_browser
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check enable_ssh_via_onion
enable_ssh_via_onion
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check check_date
check_date
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check install_dynamicdns
install_dynamicdns
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check randomize_cron
randomize_cron
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check create_freedns_updater
create_freedns_updater
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check mark_admin_user_account
mark_admin_user_account
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check enforce_good_passwords
enforce_good_passwords
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check change_login_message
change_login_message
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check enable_zram
enable_zram
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check random_number_generator
random_number_generator
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check set_your_domain_name
set_your_domain_name
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check configure_internet_protocol
configure_internet_protocol
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check create_git_project
create_git_project
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check setup_wifi
setup_wifi
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check configure_ssh
configure_ssh
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check configure_ssh_onion
configure_ssh_onion
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check allow_ssh_to_onion_address
allow_ssh_to_onion_address
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check remove_instructions_from_motd
remove_instructions_from_motd
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check check_hwrng
check_hwrng
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check search_for_attached_usb_drive
search_for_attached_usb_drive
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check regenerate_ssh_keys
regenerate_ssh_keys
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check create_upgrade_script
create_upgrade_script
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check letsencrypt_renewals
letsencrypt_renewals
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check install_watchdog_script
install_watchdog_script
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check install_avahi
install_avahi
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check create_avahi_onion_domains
create_avahi_onion_domains
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
#function_check install_atheros_wifi
#install_atheros_wifi
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check route_outgoing_traffic_through_tor
route_outgoing_traffic_through_tor
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check upgrade_golang
upgrade_golang
2016-07-27 20:13:07 +02:00
2016-08-10 23:16:34 +02:00
function_check install_tomb
install_tomb
function_check admin_user_sudo
admin_user_sudo
2016-11-29 20:30:36 +01:00
function_check limit_user_logins
limit_user_logins
2016-11-30 22:00:17 +01:00
function_check schedule_stig_tests
schedule_stig_tests
2017-05-01 13:25:15 +02:00
function_check create_usb_canary
create_usb_canary
2017-05-27 15:03:52 +02:00
function_check setup_powerline
setup_powerline
2016-07-03 17:13:34 +02:00
}
function setup_email {
2016-08-10 23:16:34 +02:00
function_check create_completion_file
create_completion_file
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check install_email
install_email
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check create_procmail
create_procmail
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check handle_admin_emails
handle_admin_emails
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check spam_filtering
spam_filtering
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check configure_imap
configure_imap
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
#function_check configure_imap_client_certs
#configure_imap_client_certs
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check configure_gpg
configure_gpg
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check refresh_gpg_keys
refresh_gpg_keys
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check configure_backup_key
configure_backup_key
2016-07-24 11:20:15 +02:00
2017-06-01 18:59:28 +02:00
#function_check install_monkeysphere
#install_monkeysphere
2016-07-24 11:20:15 +02:00
2017-06-24 19:48:33 +02:00
function_check email_client
email_client
2016-08-10 23:16:34 +02:00
function_check encrypt_incoming_email
encrypt_incoming_email
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check encrypt_outgoing_email
encrypt_outgoing_email
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check email_archiving
email_archiving
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check email_from_address
email_from_address
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check create_public_mailing_list
#create_public_mailing_list
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
#function check create_private_mailing_list
#create_private_mailing_list
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check encrypt_all_email
encrypt_all_email
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check import_email
import_email
2016-07-03 17:13:34 +02:00
}
function setup_web {
2016-08-10 23:16:34 +02:00
function_check create_completion_file
create_completion_file
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check install_web_server
install_web_server
2016-07-24 11:20:15 +02:00
2016-08-10 23:16:34 +02:00
function_check install_web_server_access_control
install_web_server_access_control
2016-07-08 15:28:12 +02:00
}
function upgrade_apps {
2016-08-10 23:16:34 +02:00
function_check create_completion_file
create_completion_file
APPS_COMPLETED=()
FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
# for all the app scripts
for filename in $FILES
do
app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
2016-10-08 23:00:53 +02:00
2016-12-21 21:05:00 +01:00
item_in_array "${app_name}" "${APPS_COMPLETED[@]}"
2016-10-08 23:00:53 +02:00
if [[ $? != 0 ]]; then
2016-08-10 23:16:34 +02:00
function_check app_is_installed
2017-05-11 23:40:39 +02:00
if [[ "$(app_is_installed $app_name)" == "1" ]]; then
2016-12-21 20:28:35 +01:00
echo ''
echo ''
2017-05-11 23:40:39 +02:00
echo $"Upgrading $app_name"
2016-10-11 14:10:59 +02:00
app_load_variables ${app_name}
2016-08-10 23:16:34 +02:00
APPS_COMPLETED+=("${app_name}")
function_check upgrade_${app_name}
upgrade_${app_name}
fi
fi
done
2016-07-03 17:13:34 +02:00
}
function setup_apps {
is_interactive=$1
2016-08-10 23:16:34 +02:00
function_check create_completion_file
create_completion_file
2016-07-24 11:20:15 +02:00
2016-10-17 00:06:11 +02:00
function_check detect_installable_apps
2016-10-15 11:43:34 +02:00
detect_installable_apps
2016-08-10 23:16:34 +02:00
function_check choose_apps_for_variant
choose_apps_for_variant "$SYSTEM_TYPE"
2016-07-08 15:28:12 +02:00
2016-08-10 23:16:34 +02:00
echo $"System variant: $SYSTEM_TYPE"
2017-06-17 19:11:42 +02:00
#echo $'The following apps have been selected'
#echo ''
#function_check list_chosen_apps
#list_chosen_apps
#echo ''
2016-07-08 15:28:12 +02:00
2016-08-10 23:16:34 +02:00
function_check upgrade_apps
upgrade_apps
2016-07-08 15:28:12 +02:00
if [[ $is_interactive == "noninteractive" || $is_interactive == "headless" ]]; then
function_check install_apps
install_apps
if [ ! $APP_INSTALLED_SUCCESS ]; then
echo $'One or more apps failed to install'
fi
fi
2016-07-03 17:13:34 +02:00
}
function combine_all_scripts {
2016-08-10 23:16:34 +02:00
combined_filename=$1
# initial variables
cp $PROJECT_INSTALL_DIR/${PROJECT_NAME}-vars $combined_filename
# utilities
UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
for f in $UTILS_FILES
do
# this removes the first line, which is #!/bin/bash
tail -n +2 "$f" >> $combined_filename
done
# base system
BASE_SYSTEM_FILES=/usr/share/${PROJECT_NAME}/base/${PROJECT_NAME}-base-*
for f in $BASE_SYSTEM_FILES
do
tail -n +2 "$f" >> $combined_filename
done
# apps
APP_FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
for f in $APP_FILES
do
tail -n +2 "$f" >> $combined_filename
done
}
function check_ram_availability {
minimum_ram_MB="$1"
2017-06-20 16:07:34 +02:00
minimum_ram_bytes=$((minimum_ram_MB * 1024))
ram_available=$(grep MemTotal /proc/meminfo | awk '{print $2}')
if [ $ram_available -lt $minimum_ram_bytes ]; then
echo $"Need at least ${minimum_ram_gb}MB RAM to install this app"
exit 783524
fi
}
2016-07-03 17:13:34 +02:00
# NOTE: deliberately no exit 0