mirror of
https://github.com/guezoloic/serverconfig.git
synced 2026-01-25 09:34:23 +00:00
feat: finish install scripts
all .sh scripts -> /usr/local/bin/ all .yml / .env -> /etc/serverconfig/ add [y/n] to override information add --true argument to ignore [y/n] input
This commit is contained in:
113
install.sh
113
install.sh
@@ -2,12 +2,115 @@
|
|||||||
|
|
||||||
source "./scripts/common.sh"
|
source "./scripts/common.sh"
|
||||||
|
|
||||||
|
SCRIPT_FILE="/usr/local/bin"
|
||||||
|
|
||||||
|
AUTO_CONFIRM=false
|
||||||
|
[[ "$1" == "--true" ]] && AUTO_CONFIRM=true
|
||||||
|
|
||||||
if [[ $EUID -ne 0 ]]; then
|
if [[ $EUID -ne 0 ]]; then
|
||||||
echo "the script needs to be as root."
|
echo "The script needs to run as root."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# if [ ! -d "$ENV_DIR" ]; then
|
touch "$LOG" || { echo "Cannot create log file $LOG"; exit 1; }
|
||||||
# echo "$ENV_DIR is missing..., "
|
chmod 644 "$LOG"
|
||||||
# mkdir -p $ENV_DIR
|
|
||||||
# fi
|
datetime_print "-- Starting ServerConfig installation v(1.0.0) --"
|
||||||
|
|
||||||
|
mkdir -p "$ETC_DIR" && \
|
||||||
|
datetime_print "$ETC_DIR ensured."
|
||||||
|
|
||||||
|
datetime_print "Installing scripts to $SCRIPT_FILE..."
|
||||||
|
|
||||||
|
install_file() {
|
||||||
|
local filename="$1"
|
||||||
|
local pathname="$2"
|
||||||
|
local argument="${3:--Dm755}"
|
||||||
|
|
||||||
|
datetime_print "Installing $filename to $pathname..."
|
||||||
|
|
||||||
|
if [[ ! -f "scripts/$filename" ]]; then
|
||||||
|
datetime_print "Source file scripts/$filename not found." "ERROR"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -e "$pathname/$filename" ]]; then
|
||||||
|
if $AUTO_CONFIRM; then
|
||||||
|
yn="y"
|
||||||
|
else
|
||||||
|
read -p "$pathname/$filename already set, overwrite? (y/N): " yn
|
||||||
|
fi
|
||||||
|
case "$yn" in
|
||||||
|
[Yy]*)
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
datetime_print "$pathname/$filename not changed."
|
||||||
|
return
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
install $argument "scripts/$filename" "$pathname/$filename" && \
|
||||||
|
datetime_print "$filename installed." || \
|
||||||
|
{ datetime_print "Error while installing $filename" "ERROR"; exit 1; }
|
||||||
|
}
|
||||||
|
echo
|
||||||
|
datetime_print "------------- install files -------------"
|
||||||
|
install_file "aws-backup.sh" "$SCRIPT_FILE" -Dm755
|
||||||
|
install_file "disk-monitor.sh" "$SCRIPT_FILE" -Dm755
|
||||||
|
install_file "sshd-login.sh" "$SCRIPT_FILE" -Dm755
|
||||||
|
install_file "telegram.sh" "$SCRIPT_FILE" -Dm755
|
||||||
|
install_file "docker-compose.yml" "$ETC_DIR" -Dm644
|
||||||
|
|
||||||
|
create_env_variable() {
|
||||||
|
local key="$1"
|
||||||
|
local value="$2"
|
||||||
|
|
||||||
|
if [[ -z "$value" ]]; then
|
||||||
|
datetime_print "$key not set (empty input)."
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
if grep -q "^$key=" "$ENV_FILE" 2>/dev/null; then
|
||||||
|
if $AUTO_CONFIRM; then
|
||||||
|
yn="y"
|
||||||
|
else
|
||||||
|
read -p "$key already set, overwrite? (y/N): " yn
|
||||||
|
fi
|
||||||
|
case "$yn" in
|
||||||
|
[Yy]*)
|
||||||
|
sed -i "s/^$key=.*/$key=$value/" "$ENV_FILE"
|
||||||
|
datetime_print "$key updated."
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
datetime_print "$key not changed."
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
else
|
||||||
|
echo "$key=$value" >> "$ENV_FILE"
|
||||||
|
datetime_print "$key set."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
echo
|
||||||
|
datetime_print "--------- define .env variables ---------"
|
||||||
|
|
||||||
|
ENV_LIST=("AWS" "TELEGRAM_CHAT_ID" "TELEGRAM_TOKEN" "EMAIL" "WG_HOSTNAME_VPN")
|
||||||
|
|
||||||
|
for env in "${ENV_LIST[@]}"; do
|
||||||
|
read -p "Enter value for $env: " value
|
||||||
|
create_env_variable "$env" "$value"
|
||||||
|
done
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
read -p "Add another env variable? (key or leave empty to quit): " key
|
||||||
|
[[ -z "$key" ]] && break
|
||||||
|
read -p "Enter value for $key: " value
|
||||||
|
create_env_variable "$key" "$value"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo
|
||||||
|
datetime_print "--------- Installation complete ---------"
|
||||||
|
datetime_print "All config files are in $ETC_DIR"
|
||||||
|
datetime_print "All scripts are in $SCRIPT_FILE"
|
||||||
|
echo "Log file written at: $LOG"
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
FILENAME="serverconfig"
|
FILENAME="serverconfig"
|
||||||
|
|
||||||
ENV_DIR="/etc/$FILENAME"
|
ETC_DIR="/etc/$FILENAME"
|
||||||
ENV_FILE="$ENV_DIR/.env"
|
ENV_FILE="$ENV_DIR/.env"
|
||||||
LOG="/var/log/$FILENAME.log"
|
LOG="/var/log/$FILENAME.log"
|
||||||
|
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ services:
|
|||||||
- net.ipv6.conf.all.forwarding=1
|
- net.ipv6.conf.all.forwarding=1
|
||||||
- net.ipv6.conf.default.forwarding=1
|
- net.ipv6.conf.default.forwarding=1
|
||||||
environment:
|
environment:
|
||||||
- VIRTUAL_HOST=${HOSTNAME_VPN}
|
- VIRTUAL_HOST=${WG_HOSTNAME_VPN}
|
||||||
- LETSENCRYPT_HOST=${HOSTNAME_VPN}
|
- LETSENCRYPT_HOST=${WG_HOSTNAME_VPN}
|
||||||
- LETSENCRYPT_EMAIL=${EMAIL}
|
- LETSENCRYPT_EMAIL=${EMAIL}
|
||||||
- VIRTUAL_PORT=51821
|
- VIRTUAL_PORT=51821
|
||||||
depends_on:
|
depends_on:
|
||||||
|
|||||||
0
scripts/telegram.sh
Normal file
0
scripts/telegram.sh
Normal file
Reference in New Issue
Block a user