-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphase-one
More file actions
83 lines (64 loc) · 2.27 KB
/
Copy pathphase-one
File metadata and controls
83 lines (64 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
# Copyright 2025, Pouria Rezaei <Pouria.rz@outlook.com>
# Hestia initiate for full NS's takeover; Phase one.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 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 General Public License at <http://www.gnu.org/licenses/> for
# more details.
set -euo pipefail
if [ "$(id -u)" -ne 0 ]; then
echo "Run as root"
exit 1
fi
OS_ID="$(. /etc/os-release && echo "${ID:-}")"
if [ "$OS_ID" != "ubuntu" ]; then
echo "Unsupported OS! (Ubuntu only)"
exit 1
fi
read -r -p "Enter existing Hestia admin username (USER): " USER
read -r -p "Enter new primary server domain (DOMAIN): " DOMAIN
read -r -p "Enter webmail prefix alias (WEB_MAIL_ALIAS): " WEB_MAIL_ALIAS
read -r -p "Enter phpMyAdmin alias (PHP_ADMIN): " PHP_ADMIN
if [ -z "${USER:-}" ] || [ -z "${DOMAIN:-}" ] || [ -z "${WEB_MAIL_ALIAS:-}" ] || [ -z "${PHP_ADMIN:-}" ]; then
echo "All fields required"
exit 1
fi
if ! v-list-users plain | awk '{print $1}' | grep -qx "$USER"; then
echo "User does not exist"
exit 1
fi
case "$DOMAIN" in
*[!a-z0-9.-]*|"") echo "Invalid domain"; exit 1 ;;
esac
case "$WEB_MAIL_ALIAS" in
*[!a-zA-Z0-9-]*|"") echo "Invalid webmail alias"; exit 1 ;;
esac
DOMAINS="$(v-list-web-domains "$USER" plain | awk '{print $1}' || true)"
for d in $DOMAINS; do
if [ -n "$d" ]; then
v-delete-web-domain "$USER" "$d" yes
fi
done
v-change-sys-hostname "$DOMAIN"
v-change-sys-webmail "$WEB_MAIL_ALIAS"
v-change-sys-db-alias pma "$PHP_ADMIN"
v-change-sys-config-value BACKUP_SYSTEM no
v-add-domain "$USER" "$DOMAIN"
PUBLIC_IP=$(ip -4 route get 8.8.8.8 | awk '/src/ {print $7; exit}')
case "$PUBLIC_IP" in
*[!0-9.]*|"")
read -r -p "Enter public IPv4 manually: " PUBLIC_IP
;;
esac
v-add-dns-record "$USER" "$DOMAIN" ns1 A "$PUBLIC_IP"
v-add-dns-record "$USER" "$DOMAIN" ns2 A "$PUBLIC_IP"
v-restart-service hestia || true
read -r -p "Reboot now? [Y/n]: " RB
if [ "${RB:-Y}" != "n" ] && [ "${RB:-Y}" != "N" ]; then
reboot
fi