Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update lib.sh to change variables to functions #1247

Merged
merged 16 commits into from
May 27, 2020
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions apps/collabora.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ then
count=$((count+1))
fi
done

msg_box "Collabora was successfully uninstalled."
exit
;;
"Reinstall Collabora")
print_text_in_color "$ICyan" "Reinstalling Collabora..."

# Check if Collabora is previously installed
# If yes, then stop and prune the docker container
docker_prune_this 'collabora/code'
Expand Down Expand Up @@ -138,12 +138,9 @@ then
occ_command app:remove onlyoffice
fi

# shellcheck disable=2034,2059
true
# shellcheck source=lib.sh
NC_UPDATE=1 && COLLABORA_INSTALL=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh)
unset NC_UPDATE
unset COLLABORA_INSTALL
# Get needed variables
nc_update
collabora_install

# Notification
msg_box "Before you start, please make sure that port 80+443 is directly forwarded to this machine!"
Expand Down
6 changes: 4 additions & 2 deletions apps/fail2ban.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
# shellcheck disable=2034,2059
true
# shellcheck source=lib.sh
NC_UPDATE=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh)
unset NC_UPDATE
. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh)

# Get needed variables
nc_update

# Check for errors + debug code and abort if something isn't right
# 1 = ON
Expand Down
10 changes: 6 additions & 4 deletions apps/fulltextsearch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
# shellcheck disable=2034,2059
true
# shellcheck source=lib.sh
NCDB=1 && NC_UPDATE=1 && ES_INSTALL=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh)
unset NC_UPDATE
unset ES_INSTALL
unset NCDB
. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh)

# Get needed variables
ncdb
nc_update
es_install

# Check for errors + debug code and abort if something isn't right
# 1 = ON
Expand Down
6 changes: 4 additions & 2 deletions apps/onlyoffice.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
# shellcheck disable=2034,2059
true
# shellcheck source=lib.sh
NC_UPDATE=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh)
unset NC_UPDATE
. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh)

# Get needed variables
nc_update

# Check for errors + debug code and abort if something isn't right
# 1 = ON
Expand Down
14 changes: 8 additions & 6 deletions apps/talk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
# shellcheck disable=2034,2059
true
# shellcheck source=lib.sh
NC_UPDATE=1 && TURN_INSTALL=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh)
unset NC_UPDATE
unset TURN_INSTALL
. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh)

# Get needed variables
nc_update
turn_install

# Check for errors + debug code and abort if something isn't right
# 1 = ON
Expand All @@ -31,7 +33,7 @@ then
choice=$(whiptail --radiolist "It seems like 'Nextcloud Talk' is already installed.\nChoose what you want to do.\nSelect by pressing the spacebar and ENTER" "$WT_HEIGHT" "$WT_WIDTH" 4 \
"Uninstall Nextcloud Talk" "" OFF \
"Reinstall Nextcloud Talk" "" ON 3>&1 1>&2 2>&3)

case "$choice" in
"Uninstall Nextcloud Talk")
print_text_in_color "$ICyan" "Uninstalling Nextcloud Talk and resetting all settings..."
Expand Down Expand Up @@ -79,8 +81,8 @@ NONO_PORTS=(22 25 53 80 443 3306 5432 7983 8983 10000)
msg_box "The default port for Talk used in this script is port $TURN_PORT.
You can read more about that port here: https://www.speedguide.net/port.php?port=$TURN_PORT

You will now be given the option to change this port to something of your own.
Please keep in mind NOT to use the following ports as they are likley to be in use already:
You will now be given the option to change this port to something of your own.
Please keep in mind NOT to use the following ports as they are likley to be in use already:
${NONO_PORTS[*]}"

if [[ "yes" == $(ask_yes_or_no "Do you want to change port?") ]]
Expand Down
8 changes: 2 additions & 6 deletions lets-encrypt/activate-tls.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,8 @@ fi

while true
do
print_text_in_color "$ICyan" "Updating lib.sh..."
# shellcheck disable=2034,2059
true
# shellcheck source=lib.sh
TLS_INSTALL=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh)
unset TLS_INSTALL
# Get needed variables
tls_install

# Ask for domain name
echo
Expand Down
88 changes: 54 additions & 34 deletions lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,19 @@ gen_passwd() {
DISTRO=$(lsb_release -sr)
KEYBOARD_LAYOUT=$(localectl status | grep "Layout" | awk '{print $3}')
# Network
[ -n "$FIRST_IFACE" ] && IFACE=$(lshw -c network | grep "logical name" | awk '{print $3; exit}')
first_iface() {
IFACE=$(lshw -c network | grep "logical name" | awk '{print $3; exit}')
}
[ -n "$FIRST_IFACE" ] && first_iface && unset FIRST_IFACE
IFACE2=$(ip -o link show | awk '{print $2,$9}' | grep 'UP' | cut -d ':' -f 1)
REPO=$(grep deb-src /etc/apt/sources.list | grep http | awk '{print $3}' | head -1)
ADDRESS=$(hostname -I | cut -d ' ' -f 1)
# WANIP4=$(dig +short myip.opendns.com @resolver1.opendns.com) # as an alternative
WANIP4=$(curl -s -k -m 5 https://ipv4bot.whatismyipaddress.com)
[ -n "$LOAD_IP6" ] && WANIP6=$(curl -s -k -m 5 https://ipv6bot.whatismyipaddress.com)
load_ip6() {
WANIP6=$(curl -s -k -m 5 https://ipv6bot.whatismyipaddress.com)
}
[ -n "$LOAD_IP6" ] && load_ip6 && unset LOAD_IP6
INTERFACES="/etc/netplan/01-netcfg.yaml"
GATEWAY=$(ip route | grep default | awk '{print $3}')
DNS1="9.9.9.9"
Expand All @@ -63,26 +69,41 @@ ROOT_PROFILE="/root/.bash_profile"
SHUF=$(shuf -i 25-29 -n 1)
PGDB_PASS=$(gen_passwd "$SHUF" "a-zA-Z0-9@#*=")
NEWPGPASS=$(gen_passwd "$SHUF" "a-zA-Z0-9@#*=")
[ -n "$NCDB" ] && NCCONFIGDB=$(grep "dbname" $NCPATH/config/config.php | awk '{print $3}' | sed "s/[',]//g")
[ -n "$NCDBPASS" ] && NCCONFIGDBPASS=$(grep "dbpassword" $NCPATH/config/config.php | awk '{print $3}' | sed "s/[',]//g")
ncdb() {
NCCONFIGDB=$(grep "dbname" $NCPATH/config/config.php | awk '{print $3}' | sed "s/[',]//g")
}
[ -n "$NCDB" ] && ncdb && unset NCDB
ncdbpass() {
NCCONFIGDBPASS=$(grep "dbpassword" $NCPATH/config/config.php | awk '{print $3}' | sed "s/[',]//g")
}
[ -n "$NCDBPASS" ] && ncdbpass && unset NCDBPASS
# Path to specific files
SECURE="$SCRIPTS/setup_secure_permissions_nextcloud.sh"
# Nextcloud version
[ -n "$NC_UPDATE" ] && CURRENTVERSION=$(sudo -u www-data php $NCPATH/occ status | grep "versionstring" | awk '{print $3}')
[ -n "$NC_UPDATE" ] && NCVERSION=$(curl -s -m 900 $NCREPO/ | sed --silent 's/.*href="nextcloud-\([^"]\+\).zip.asc".*/\1/p' | sort --version-sort | tail -1)
[ -n "$NC_UPDATE" ] && STABLEVERSION="nextcloud-$NCVERSION"
[ -n "$NC_UPDATE" ] && NCMAJOR="${NCVERSION%%.*}"
[ -n "$NC_UPDATE" ] && NCBAD=$((NCMAJOR-2))
nc_update() {
CURRENTVERSION=$(sudo -u www-data php $NCPATH/occ status | grep "versionstring" | awk '{print $3}')
NCVERSION=$(curl -s -m 900 $NCREPO/ | sed --silent 's/.*href="nextcloud-\([^"]\+\).zip.asc".*/\1/p' | sort --version-sort | tail -1)
STABLEVERSION="nextcloud-$NCVERSION"
NCMAJOR="${NCVERSION%%.*}"
NCBAD=$((NCMAJOR-2))
}
[ -n "$NC_UPDATE" ] && nc_update && unset NC_UPDATE
# Set the hour for automatic updates. This would be 18:00 as only the hour is configurable.
AUT_UPDATES_TIME="18"
# Keys
OpenPGP_fingerprint='28806A878AE423A28372792ED75899B9A724937A'
# Collabora Docker URL (collabora.sh
[ -n "$COLLABORA_INSTALL" ] && SUBDOMAIN=$(whiptail --title "T&M Hansson IT - Collabora" --inputbox "Collabora subdomain eg: office.yourdomain.com\n\nNOTE: This domain must be different than your Nextcloud domain. They can however be hosted on the same server, but would require seperate DNS entries." "$WT_HEIGHT" "$WT_WIDTH" 3>&1 1>&2 2>&3)
collabora_install() {
SUBDOMAIN=$(whiptail --title "T&M Hansson IT - Collabora" --inputbox "Collabora subdomain eg: office.yourdomain.com\n\nNOTE: This domain must be different than your Nextcloud domain. They can however be hosted on the same server, but would require seperate DNS entries." "$WT_HEIGHT" "$WT_WIDTH" 3>&1 1>&2 2>&3)
# Nextcloud Main Domain (collabora.sh)
[ -n "$COLLABORA_INSTALL" ] && NCDOMAIN=$(whiptail --title "T&M Hansson IT - Collabora" --inputbox "Nextcloud domain, make sure it looks like this: cloud\\.yourdomain\\.com" "$WT_HEIGHT" "$WT_WIDTH" cloud\\.yourdomain\\.com 3>&1 1>&2 2>&3)
NCDOMAIN=$(whiptail --title "T&M Hansson IT - Collabora" --inputbox "Nextcloud domain, make sure it looks like this: cloud\\.yourdomain\\.com" "$WT_HEIGHT" "$WT_WIDTH" cloud\\.yourdomain\\.com 3>&1 1>&2 2>&3)
}
[ -n "$COLLABORA_INSTALL" ] && collabora_install && unset COLLABORA_INSTALL
# Nextcloud Main Domain (activate-tls.sh)
[ -n "$TLS_INSTALL" ] && TLSDOMAIN=$(whiptail --title "T&M Hansson IT - Let's Encrypt" --inputbox "Please enter the domain name you will use for Nextcloud.\n\nMake sure it looks like this:\nyourdomain.com, or cloud.yourdomain.com" "$WT_HEIGHT" "$WT_WIDTH" cloud.yourdomain.com 3>&1 1>&2 2>&3)
tls_install() {
TLSDOMAIN=$(whiptail --title "T&M Hansson IT - Let's Encrypt" --inputbox "Please enter the domain name you will use for Nextcloud.\n\nMake sure it looks like this:\nyourdomain.com, or cloud.yourdomain.com" "$WT_HEIGHT" "$WT_WIDTH" cloud.yourdomain.com 3>&1 1>&2 2>&3)
}
[ -n "$TLS_INSTALL" ] && tls_install && unset TLS_INSTALL
# Letsencrypt
SITES_AVAILABLE="/etc/apache2/sites-available"
LETSENCRYPTPATH="/etc/letsencrypt"
Expand Down Expand Up @@ -112,17 +133,22 @@ SPAMHAUS=/etc/spamhaus.wl
ENVASIVE=/etc/apache2/mods-available/mod-evasive.load
APACHE2=/etc/apache2/apache2.conf
# Full text Search
[ -n "$ES_INSTALL" ] && INDEX_USER=$(gen_passwd "$SHUF" '[:lower:]')
[ -n "$ES_INSTALL" ] && ROREST=$(gen_passwd "$SHUF" "A-Za-z0-9")
[ -n "$ES_INSTALL" ] && nc_fts="ark74/nc_fts"
[ -n "$ES_INSTALL" ] && fts_es_name="fts_esror"
es_install() {
INDEX_USER=$(gen_passwd "$SHUF" '[:lower:]')
ROREST=$(gen_passwd "$SHUF" "A-Za-z0-9")
nc_fts="ark74/nc_fts"
fts_es_name="fts_esror"
}
[ -n "$ES_INSTALL" ] && es_install && unset ES_INSTALL
# Talk
[ -n "$TURN_INSTALL" ] && TURN_CONF="/etc/turnserver.conf"
[ -n "$TURN_INSTALL" ] && TURN_PORT=5349
[ -n "$TURN_INSTALL" ] && TURN_DOMAIN=$(sudo -u www-data /var/www/nextcloud/occ config:system:get overwrite.cli.url | sed 's#https://##;s#/##')
[ -n "$TURN_INSTALL" ] && SHUF=$(shuf -i 25-29 -n 1)
[ -n "$TURN_INSTALL" ] && TURN_SECRET=$(gen_passwd "$SHUF" "a-zA-Z0-9@#*=")

turn_install() {
TURN_CONF="/etc/turnserver.conf"
TURN_PORT=5349
TURN_DOMAIN=$(sudo -u www-data /var/www/nextcloud/occ config:system:get overwrite.cli.url | sed 's#https://##;s#/##')
SHUF=$(shuf -i 25-29 -n 1)
TURN_SECRET=$(gen_passwd "$SHUF" "a-zA-Z0-9@#*=")
}
[ -n "$TURN_INSTALL" ] && turn_install && unset TURN_INSTALL

## FUNCTIONS

Expand Down Expand Up @@ -940,11 +966,9 @@ any_key() {
}

lowest_compatible_nc() {
if [ -z "$NC_UPDATE" ]
if [ -z "$CURRENTVERSION" ]
enoch85 marked this conversation as resolved.
Show resolved Hide resolved
then
# shellcheck source=lib.sh
NC_UPDATE=1 . <(curl -sL $GITHUB_REPO/lib.sh)
unset NC_UPDATE
nc_update
fi
if [ "${CURRENTVERSION%%.*}" -lt "$1" ]
then
Expand Down Expand Up @@ -980,11 +1004,9 @@ fi

# Check new version
# shellcheck source=lib.sh
if [ -z "$NC_UPDATE" ]
if [ -z "$CURRENTVERSION" ]
then
# shellcheck source=lib.sh
NC_UPDATE=1 . <(curl -sL $GITHUB_REPO/lib.sh)
unset NC_UPDATE
nc_update
fi
if [ "${CURRENTVERSION%%.*}" -ge "$1" ]
then
Expand Down Expand Up @@ -1123,11 +1145,9 @@ printf "%b%s%b\n" "$1" "$2" "$Color_Off"
# 2 = repository
# Nextcloud version
git_apply_patch() {
if [ -z "$NC_UPDATE" ]
if [ -z "$CURRENTVERSION" ]
then
# shellcheck source=lib.sh
NC_UPDATE=1 . <(curl -sL $GITHUB_REPO/lib.sh)
unset NC_UPDATE
nc_update
fi
if [[ "$CURRENTVERSION" = "$3" ]]
then
Expand Down
25 changes: 15 additions & 10 deletions nextcloud-startup-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,23 @@ then
# shellcheck disable=2034,2059
true
# shellcheck source=lib.sh
NCDB=1 && FIRST_IFACE=1 source /var/scripts/lib.sh
unset NCDB
unset FIRST_IFACE
source /var/scripts/lib.sh

# Get needed variables
ncdb
first_iface

# If we have internet, then use the latest variables from the lib remote file
elif print_text_in_color "$ICyan" "Testing internet connection..." && ping github.com -c 2
then
true
# shellcheck source=lib.sh
NCDB=1 && FIRST_IFACE=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh)
unset FIRST_IFACE
unset NCDB
. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh)

# Get needed variables
ncdb
first_iface

else
print_text_in_color "$IRed" "You don't seem to have a working internet connection, and /var/scripts/lib.sh is missing so you can't run this script."
print_text_in_color "$ICyan" "Please report this to https://github.com/nextcloud/vm/issues/"
Expand Down Expand Up @@ -131,10 +137,9 @@ Please also post this issue on: https://github.com/nextcloud/vm/issues"
exit 1
fi

# shellcheck source=lib.sh
NCDB=1 && NC_UPDATE=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh)
unset NC_UPDATE
unset NCDB
# Get needed variables
ncdb
nc_update

# Check for errors + debug code and abort if something isn't right
# 1 = ON
Expand Down
15 changes: 6 additions & 9 deletions nextcloud_install_production.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,8 @@ else
apt install whiptail -y
fi

# shellcheck disable=2034,2059
true
# shellcheck source=lib.sh
FIRST_IFACE=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh)
unset FIRST_IFACE
# Get needed variables
first_iface

# Check for errors + debug code and abort if something isn't right
# 1 = ON
Expand Down Expand Up @@ -398,9 +395,9 @@ occ_command config:system:set trashbin_retention_obligation --value="auto, 180"
occ_command config:system:set versions_retention_obligation --value="auto, 365"

# Remove simple signup
occ_command config:system:set simpleSignUpLink.shown --value="false"
occ_command config:system:set simpleSignUpLink.shown --value="false"

# Enable OPCache for PHP
# Enable OPCache for PHP
# https://docs.nextcloud.com/server/14/admin_manual/configuration_server/server_tuning.html#enable-php-opcache
phpenmod opcache
{
Expand Down Expand Up @@ -606,13 +603,13 @@ then
# just in case if .htaccess gets disabled
Require all denied
</Directory>

# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
<Files ".ht*">
Require all denied
</Files>

# Disable HTTP TRACE method.
TraceEnable off

Expand Down
Loading