diff options
author | szaimen <szaimen@e.mail.de> | 2020-09-04 10:05:47 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-04 10:05:47 +0300 |
commit | c42ec1d992d4ac995c6700affe05ba74cdb99c4c (patch) | |
tree | b53ae82a9916e7e66e064e08b5c124eb89c6dcb8 /old | |
parent | 80dc7b6293f260f6261a6757ead1cfe717fa5ed6 (diff) |
add SCRIPT_NAME to all scripts and standardize whiptail-titles (#1400)
Signed-off-by: enoch85 <github@hanssonit.se>
Co-authored-by: enoch85 <github@hanssonit.se>
Diffstat (limited to 'old')
-rw-r--r-- | old/format-sda-nuc-server.sh | 163 | ||||
-rw-r--r-- | old/modsecurity.sh | 1 | ||||
-rw-r--r-- | old/ntpdate.sh | 1 | ||||
-rw-r--r-- | old/spreedme.sh | 1 | ||||
-rw-r--r-- | old/test_connection.sh | 1 |
5 files changed, 167 insertions, 0 deletions
diff --git a/old/format-sda-nuc-server.sh b/old/format-sda-nuc-server.sh new file mode 100644 index 00000000..967f94d3 --- /dev/null +++ b/old/format-sda-nuc-server.sh @@ -0,0 +1,163 @@ +#!/bin/bash + +# T&M Hansson IT AB © - 2020, https://www.hanssonit.se/ + +# shellcheck disable=2034,2059 +true +SCRIPT_NAME="Format sda NUC Server" +# shellcheck source=lib.sh +. <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) + +# Check if root +root_check + +# Needs to be Ubuntu 18.04 and Multiverse +check_distro_version +check_multiverse + +MOUNT_=/mnt/$POOLNAME + +# Needed for partprobe +install_if_not parted + +format() { +# umount if mounted +umount /mnt/* &> /dev/null + +# mkdir if not existing +mkdir -p "$MOUNT_" + +DEVTYPE=sda + +# Get the name of the drive +DISKTYPE=$(fdisk -l | grep $DEVTYPE | awk '{print $2}' | cut -d ":" -f1 | head -1) +if [ "$DISKTYPE" != "/dev/$DEVTYPE" ] +then +msg_box "It seems like your $SYSNAME secondary volume (/dev/$DEVTYPE) does not exist. +This script requires that you mount a second drive to hold the data. + +Please shutdown the server and mount a second drive, then start this script again. + +If you want help you can buy support in our shop: +https://shop.hanssonit.se/product/premium-support-per-30-minutes/" +exit 1 +fi + +# Check if ZFS utils are installed +install_if_not zfsutils-linux + +# Check still not mounted +#These functions return exit codes: 0 = found, 1 = not found +isMounted() { findmnt -rno SOURCE,TARGET "$1" >/dev/null;} #path or device +isDevMounted() { findmnt -rno SOURCE "$1" >/dev/null;} #device only +isPathMounted() { findmnt -rno TARGET "$1" >/dev/null;} #path only +isDevPartOfZFS() { zpool status | grep "$1" >/dev/null;} #device memeber of a zpool + +if isPathMounted "/mnt/ncdata"; #Spaces in path names are ok. +then +msg_box "/mnt/ncdata is mounted and need to be unmounted before you can run this script." + exit 1 +fi + +if isDevMounted "/dev/$DEVTYPE"; +then +msg_box "/dev/$DEVTYPE is mounted and need to be unmounted before you can run this script." + exit 1 +fi + +# Universal: +if isMounted "/mnt/ncdata"; +then +msg_box "/mnt/ncdata is mounted and need to be unmounted before you can run this script." + exit 1 +fi + +if isMounted "/dev/${DEVTYPE}1"; +then +msg_box "/dev/${DEVTYPE}1 is mounted and need to be unmounted before you can run this script." + exit 1 +fi + +if isDevPartOfZFS "$DEVTYPE"; +then +msg_box "/dev/$DEVTYPE is a member of a ZFS pool and needs to be removed from any zpool before you can run this script." + exit 1 +fi + +if lsblk -l -n | grep -v mmcblk | grep disk | awk '{ print $1 }' | tail -1 > /dev/null +then +msg_box "Formatting your $SYSNAME secondary volume ($DISKTYPE) when you hit OK. + +*** WARNING: ALL YOUR DATA WILL BE ERASED! ***" + if zpool list | grep "$POOLNAME" > /dev/null + then + check_command zpool destroy "$POOLNAME" + fi + check_command wipefs -a -f "$DISKTYPE" + sleep 0.5 + check_command zpool create -f -o ashift=12 "$POOLNAME" "$DISKTYPE" + check_command zpool set failmode=continue "$POOLNAME" + check_command zfs set mountpoint="$MOUNT_" "$POOLNAME" + check_command zfs set compression=lz4 "$POOLNAME" + check_command zfs set sync=standard "$POOLNAME" + check_command zfs set xattr=sa "$POOLNAME" + check_command zfs set primarycache=all "$POOLNAME" + check_command zfs set atime=off "$POOLNAME" + check_command zfs set recordsize=128k "$POOLNAME" + check_command zfs set logbias=latency "$POOLNAME" + +else +msg_box "It seems like /dev/$DEVTYPE does not exist. +This script requires that you mount a second drive to hold the data. + +Please shutdown the server and mount a second drive, then start this script again. + +If you want help you can buy support in our shop: +https://shop.hanssonit.se/product/premium-support-per-30-minutes/" +exit 1 +fi +} +format + +# Do a backup of the ZFS mount +if is_this_installed libzfs2linux +then + if grep -r $POOLNAME /etc/mtab + then + install_if_not zfs-auto-snapshot + sed -i "s|date --utc|date|g" /usr/sbin/zfs-auto-snapshot + fi +fi + +# Check if UUID is used +if zpool list -v | grep "$DEVTYPE" +then + # Get UUID + check_command partprobe -s + if fdisk -l /dev/"$DEVTYPE"1 >/dev/null 2>&1 + then + UUID_SDB1=$(blkid -o value -s UUID /dev/"DEVTYPE"1) + fi + # Export / import the correct way (based on UUID) + check_command zpool export "$POOLNAME" + check_command zpool import -d /dev/disk/by-uuid/"$UUID_SDB1" "$POOLNAME" +fi + +# Success! +if grep "$POOLNAME" /etc/mtab +then +msg_box "$MOUNT_ mounted successfully as a ZFS volume. + +Automatic scrubbing is done monthly via a cronjob that you can find here: +/etc/cron.d/zfsutils-linux + +Automatic snapshots are taken with 'zfs-auto-snapshot'. You can list current snapshots with: +'sudo zfs list -t snapshot'. +Manpage is here: +http://manpages.ubuntu.com/manpages/focal/man8/zfs-auto-snapshot.8.html + +CURRENT STATUS: +$(zpool status $POOLNAME) + +$(zpool list)" +fi diff --git a/old/modsecurity.sh b/old/modsecurity.sh index f6601aa8..0ff061ff 100644 --- a/old/modsecurity.sh +++ b/old/modsecurity.sh @@ -4,6 +4,7 @@ # shellcheck disable=2034,2059 true +SCRIPT_NAME="Modsecurity" # shellcheck source=lib.sh . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) diff --git a/old/ntpdate.sh b/old/ntpdate.sh index 43645ef3..a5836b80 100644 --- a/old/ntpdate.sh +++ b/old/ntpdate.sh @@ -4,6 +4,7 @@ # shellcheck disable=2034,2059 true +SCRIPT_NAME="Ntpdate" # shellcheck source=lib.sh . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) diff --git a/old/spreedme.sh b/old/spreedme.sh index 2d4ffde2..b1e5f536 100644 --- a/old/spreedme.sh +++ b/old/spreedme.sh @@ -4,6 +4,7 @@ # shellcheck disable=2034,2059 true +SCRIPT_NAME="Spreedme" # shellcheck source=lib.sh NC_UPDATE=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) unset NC_UPDATE diff --git a/old/test_connection.sh b/old/test_connection.sh index dbb590d9..205bfaea 100644 --- a/old/test_connection.sh +++ b/old/test_connection.sh @@ -1,6 +1,7 @@ #!/bin/bash # shellcheck disable=2034,2059 true +SCRIPT_NAME="Test connection" # shellcheck source=lib.sh . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh) |