58 lines
1.7 KiB
Bash
Executable File
58 lines
1.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Swap version index numbers in config. This might be helpful when changing the
|
|
# order of your php-fpm index numbers in the DirectAdmin configuration.
|
|
# In case version "1" has been requested, change configs with no version
|
|
# set, as "1" is the default.
|
|
|
|
set -euo pipefail
|
|
# helper functions
|
|
die() { echo "$*" >&2; exit 1;}
|
|
warn() { echo "$*" >&2; }
|
|
|
|
usage="Usage: $0 <version 1-4> <version 1-4>"
|
|
|
|
[ `id -nu` != "root" ] && die "Please execute as root"
|
|
|
|
[ "$#" -ne 2 ] && die $usage
|
|
! [[ "$1" =~ ^[1-4]$ ]] && die $usage
|
|
! [[ "$2" =~ ^[1-4]$ ]] && die $usage
|
|
|
|
version_swap1=$1
|
|
version_swap2=$2
|
|
|
|
swap_version() {
|
|
local conf=$1
|
|
local version_current
|
|
|
|
[ -f "$conf" ] || die "File does not exist: $conf"
|
|
|
|
# Get current version if set in config
|
|
set +e
|
|
version_current=$(grep -soP "php1_select=\K[0-9]" $conf)
|
|
set -e
|
|
[ $? -eq 2 ] && die "grep encountered a fatal error"
|
|
|
|
if [ -z $version_current ]; then
|
|
# current version not found in config. assume "1"
|
|
version_current=1
|
|
fi
|
|
|
|
# Is this the version we're looking for?
|
|
if [ $version_current -eq $version_swap1 ]; then
|
|
# replace or add line
|
|
sed -i '/^php1_select=/{h;s/=.*/='$version_swap2'/};${x;/^$/{s//php1_select='$version_swap2'/;H};x}' "$conf"
|
|
echo "$conf: changed"
|
|
elif [ $version_current -eq $version_swap2 ]; then
|
|
# replace or add line
|
|
sed -i '/^php1_select=/{h;s/=.*/='$version_swap1'/};${x;/^$/{s//php1_select='$version_swap1'/;H};x}' "$conf"
|
|
echo "$conf: changed"
|
|
fi
|
|
}
|
|
|
|
for f in /usr/local/directadmin/data/users/*/domains/*.conf; do
|
|
swap_version $f
|
|
done
|
|
|
|
echo "To update the running configuration, please run: /usr/local/directadmin/custombuild/build rewrite_confs"
|