171 lines
6.4 KiB
Bash
Executable File
171 lines
6.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Hostora installer (all-in-one) — kode orisinal, lisensi GPL-3.0.
|
|
#
|
|
# curl -fsSL https://raw.githubusercontent.com/maspend/hostora/main/install.sh | sudo bash
|
|
# curl -fsSL https://raw.githubusercontent.com/maspend/hostora/main/install.sh | sudo bash -s -- --check
|
|
# sudo ./install.sh --local # instal dari repo lokal (untuk pengembangan)
|
|
# sudo ./install.sh --version 0.6.1 # instal versi tertentu
|
|
# sudo ./install.sh --with-dns --with-mail # instal juga stack DNS + mail
|
|
#
|
|
# Cara kerja: unduh bundle release, verifikasi SHA256, jalankan preflight,
|
|
# lalu instal. Bila belum ada release untuk versi yang diminta (v0.2 masih
|
|
# tahap awal), installer otomatis jatuh ke "build from source": clone repo
|
|
# dan build dengan Go (unduhan modul Go pertama kali butuh internet;
|
|
# dependensi di-pin: golang.org/x/crypto v0.31.0 untuk Go 1.23).
|
|
# Menjalankan ulang akan upgrade in-place.
|
|
set -euo pipefail
|
|
umask 022
|
|
|
|
REPO="https://github.com/maspend/hostora"
|
|
GO_VERSION="1.23.4"
|
|
|
|
die() { echo "install.sh: $*" >&2; exit 1; }
|
|
say() { echo "==> $*"; }
|
|
|
|
usage() {
|
|
cat <<'EOF'
|
|
Usage: install.sh [--version X.Y.Z] [--local] [--check] [--yes] [opsi instalasi]
|
|
|
|
--version X.Y.Z instal release ini (default: terbaru)
|
|
--local build & instal dari repo di direktori saat ini
|
|
--check hanya jalankan preflight, jangan instal
|
|
--yes lanjutkan meski ada peringatan
|
|
|
|
Opsi instalasi (diteruskan ke `hostora install`):
|
|
-admin-user NAME admin pertama (default admin)
|
|
-admin-email EMAIL email admin pertama
|
|
-panel-port N port HTTPS panel (default 8443)
|
|
--with-dns instal juga PowerDNS + pdns-backend-sqlite3
|
|
(plus mariadb-server + PHP 8.3 eksplisit, lalu dns-setup otomatis)
|
|
--with-mail instal juga Postfix + Dovecot IMAP/Sieve
|
|
(plus mariadb-server + PHP 8.3 eksplisit)
|
|
Tanpa kedua flag ini, instalasi default TIDAK
|
|
menginstal paket DNS/mail/database/PHP apa pun.
|
|
EOF
|
|
}
|
|
|
|
ensure_go() {
|
|
if command -v go >/dev/null 2>&1; then
|
|
return 0
|
|
fi
|
|
say "Go belum ada — mengunduh Go $GO_VERSION" >&2
|
|
arch=$(uname -m)
|
|
case "$arch" in
|
|
x86_64|amd64) goarch=amd64 ;;
|
|
aarch64|arm64) goarch=arm64 ;;
|
|
*) die "arsitektur tidak didukung: $arch" ;;
|
|
esac
|
|
tmp=$(mktemp -d)
|
|
trap "rm -rf '$tmp'" EXIT
|
|
curl -fsSL "https://go.dev/dl/go${GO_VERSION}.linux-${goarch}.tar.gz" -o "$tmp/go.tgz"
|
|
rm -rf /usr/local/go
|
|
tar -C /usr/local -xzf "$tmp/go.tgz"
|
|
export PATH="$PATH:/usr/local/go/bin"
|
|
go version >&2
|
|
}
|
|
|
|
build_from_source() {
|
|
# $1 = direktori sumber (sudah berisi go.mod)
|
|
local src="$1"
|
|
ensure_go
|
|
say "build Hostora dari source ($src) — unduhan modul Go pertama kali butuh internet" >&2
|
|
(cd "$src" && go build -trimpath -o /tmp/hostora-build .)
|
|
mkdir -p /opt/hostora/bin
|
|
cp /tmp/hostora-build /opt/hostora/bin/hostora
|
|
chmod 755 /opt/hostora/bin/hostora
|
|
echo "/opt/hostora/bin/hostora"
|
|
}
|
|
|
|
main() {
|
|
local version="" local_build=0 check_only=0 assume_yes=0 panel_port=8443
|
|
local pass=()
|
|
while [ $# -gt 0 ]; do
|
|
case "$1" in
|
|
--version) [ $# -ge 2 ] || die "--version butuh nilai"; version=${2#v}; shift 2 ;;
|
|
--version=*) version=${1#*=}; version=${version#v}; shift ;;
|
|
--local) local_build=1; shift ;;
|
|
--check) check_only=1; shift ;;
|
|
--yes|-y) assume_yes=1; shift ;;
|
|
-panel-port) [ $# -ge 2 ] || die "-panel-port butuh nilai"; panel_port=$2; pass+=("$1" "$2"); shift 2 ;;
|
|
-panel-port=*) panel_port=${1#*=}; pass+=("$1"); shift ;;
|
|
--with-dns|--with-mail) pass+=("$1"); shift ;;
|
|
-h|--help) usage; exit 0 ;;
|
|
*) pass+=("$1"); shift ;;
|
|
esac
|
|
done
|
|
|
|
[ "$(id -u)" -eq 0 ] || die "jalankan sebagai root (mis. ... | sudo bash)"
|
|
[ "$(uname -s)" = Linux ] || die "Hostora hanya untuk Linux"
|
|
case "$(uname -m)" in
|
|
x86_64|amd64) arch=amd64 ;;
|
|
aarch64|arm64) arch=arm64 ;;
|
|
*) die "arsitektur tidak didukung: $(uname -m)" ;;
|
|
esac
|
|
for tool in curl tar sha256sum; do
|
|
command -v "$tool" >/dev/null 2>&1 || die "$tool wajib ada"
|
|
done
|
|
|
|
local bin=""
|
|
if [ "$local_build" -eq 1 ] || { [ "$check_only" -eq 1 ] && [ -f go.mod ]; }; then
|
|
# --check dari dalam repo: build lokal saja, tidak perlu release.
|
|
[ -f go.mod ] || die "--local harus dijalankan dari root repo Hostora (go.mod tidak ditemukan)"
|
|
bin=$(build_from_source "$PWD")
|
|
else
|
|
# Coba release dulu; bila belum ada, build dari source.
|
|
if [ -z "$version" ]; then
|
|
version=$(curl -fsSL "$REPO/releases/latest/download/LATEST" 2>/dev/null | tr -d '[:space:]' || true)
|
|
version=${version:-0.6.1}
|
|
fi
|
|
[[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.]+)?$ ]] || die "versi tidak valid: \"$version\""
|
|
local name="hostora-$version-linux-$arch.tar.gz"
|
|
local work
|
|
work=$(mktemp -d)
|
|
trap "rm -rf '$work'" EXIT
|
|
say "mengunduh Hostora $version ($arch)"
|
|
if curl -fsSL "$REPO/releases/download/v$version/SHA256SUMS" -o "$work/SHA256SUMS" &&
|
|
curl -fsSL "$REPO/releases/download/v$version/$name" -o "$work/$name"; then
|
|
(cd "$work" && sha256sum -c SHA256SUMS --ignore-missing) || die "checksum release tidak cocok"
|
|
say "checksum terverifikasi"
|
|
tar -xzf "$work/$name" -C "$work"
|
|
bin="$work/hostora"
|
|
[ -x "$bin" ] || die "bundle tidak berisi biner hostora"
|
|
else
|
|
say "belum ada release v$version — beralih ke build from source"
|
|
local src="$work/src"
|
|
git clone --depth 1 "$REPO.git" "$src" || die "gagal clone $REPO (butuh git)"
|
|
bin=$(build_from_source "$src")
|
|
fi
|
|
fi
|
|
|
|
# Preflight dulu; 0 siap, 2 siap dengan peringatan, selain itu berhenti.
|
|
set +e
|
|
"$bin" preflight --port "$panel_port"
|
|
local status=$?
|
|
set -e
|
|
if [ "$check_only" -eq 1 ]; then
|
|
exit "$status"
|
|
fi
|
|
case "$status" in
|
|
0) ;;
|
|
2)
|
|
if [ "$assume_yes" -ne 1 ]; then
|
|
if [ -r /dev/tty ] && [ -w /dev/tty ]; then
|
|
printf 'Lanjutkan instalasi meski ada peringatan di atas? [y/N] ' >/dev/tty
|
|
read -r answer </dev/tty || answer=""
|
|
case "$answer" in
|
|
y|Y|yes|YES|ya|Ya) ;;
|
|
*) die "instalasi dibatalkan" ;;
|
|
esac
|
|
else
|
|
die "ada peringatan di atas; jalankan lagi dengan --yes untuk tetap instal"
|
|
fi
|
|
fi
|
|
;;
|
|
*) die "server belum siap untuk Hostora: perbaiki masalah di atas lalu jalankan lagi" ;;
|
|
esac
|
|
|
|
"$bin" install "${pass[@]}"
|
|
}
|
|
|
|
main "$@"
|