mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-06-06 13:14:11 +00:00
fix(install): write env file to per-distro path and handle pg-install failure
The env file was hardcoded to /etc/default/x-ui, but RHEL/Fedora units read /etc/sysconfig/x-ui, Arch reads /etc/conf.d/x-ui, and Alpine OpenRC auto- sources /etc/conf.d/x-ui. PostgreSQL selection was silently dropped on every distro except Debian. Also initdb on openSUSE (service wouldn't start) and prompt the operator on local-install failure instead of silently demoting to SQLite.
This commit is contained in:
parent
08b16f0ce5
commit
3b95bf8f42
1 changed files with 53 additions and 21 deletions
44
install.sh
44
install.sh
|
|
@ -140,6 +140,10 @@ install_postgres_local() {
|
||||||
;;
|
;;
|
||||||
opensuse-tumbleweed | opensuse-leap)
|
opensuse-tumbleweed | opensuse-leap)
|
||||||
zypper -q install -y postgresql-server postgresql-contrib >&2 || return 1
|
zypper -q install -y postgresql-server postgresql-contrib >&2 || return 1
|
||||||
|
if [[ ! -f /var/lib/pgsql/data/PG_VERSION ]]; then
|
||||||
|
install -d -o postgres -g postgres -m 700 /var/lib/pgsql/data >&2 || return 1
|
||||||
|
su - postgres -c "initdb -D /var/lib/pgsql/data" >&2 || return 1
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
alpine)
|
alpine)
|
||||||
apk add --no-cache postgresql postgresql-contrib >&2 || return 1
|
apk add --no-cache postgresql postgresql-contrib >&2 || return 1
|
||||||
|
|
@ -824,12 +828,27 @@ config_after_install() {
|
||||||
read -rp "Choose [1]: " db_choice
|
read -rp "Choose [1]: " db_choice
|
||||||
db_choice="${db_choice:-1}"
|
db_choice="${db_choice:-1}"
|
||||||
if [[ "$db_choice" == "2" ]]; then
|
if [[ "$db_choice" == "2" ]]; then
|
||||||
|
local xui_env_file
|
||||||
|
case "${release}" in
|
||||||
|
ubuntu | debian | armbian)
|
||||||
|
xui_env_file="/etc/default/x-ui"
|
||||||
|
;;
|
||||||
|
arch | manjaro | parch | alpine)
|
||||||
|
xui_env_file="/etc/conf.d/x-ui"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
xui_env_file="/etc/sysconfig/x-ui"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
local xui_dsn=""
|
||||||
|
local pg_mode=""
|
||||||
|
while [[ -z "$xui_dsn" ]]; do
|
||||||
echo ""
|
echo ""
|
||||||
echo -e " 1) Install PostgreSQL locally and create a dedicated user/db (recommended)"
|
echo -e " 1) Install PostgreSQL locally and create a dedicated user/db (recommended)"
|
||||||
echo -e " 2) Use an existing PostgreSQL server (enter DSN)"
|
echo -e " 2) Use an existing PostgreSQL server (enter DSN)"
|
||||||
read -rp "Choose [1]: " pg_mode
|
read -rp "Choose [1]: " pg_mode
|
||||||
pg_mode="${pg_mode:-1}"
|
pg_mode="${pg_mode:-1}"
|
||||||
local xui_dsn=""
|
|
||||||
if [[ "$pg_mode" == "2" ]]; then
|
if [[ "$pg_mode" == "2" ]]; then
|
||||||
while [[ -z "$xui_dsn" ]]; do
|
while [[ -z "$xui_dsn" ]]; do
|
||||||
read -rp "Enter PostgreSQL DSN (postgres://user:pass@host:port/dbname?sslmode=disable): " xui_dsn
|
read -rp "Enter PostgreSQL DSN (postgres://user:pass@host:port/dbname?sslmode=disable): " xui_dsn
|
||||||
|
|
@ -841,18 +860,31 @@ config_after_install() {
|
||||||
if xui_dsn=$(install_postgres_local); then
|
if xui_dsn=$(install_postgres_local); then
|
||||||
db_label="PostgreSQL (xui@127.0.0.1:5432/xui)"
|
db_label="PostgreSQL (xui@127.0.0.1:5432/xui)"
|
||||||
else
|
else
|
||||||
echo -e "${red}PostgreSQL installation failed; falling back to SQLite.${plain}"
|
echo ""
|
||||||
xui_dsn=""
|
echo -e "${red}PostgreSQL installation failed.${plain}"
|
||||||
|
echo -e " 1) Retry local install"
|
||||||
|
echo -e " 2) Enter an external DSN instead"
|
||||||
|
echo -e " 3) Abort install"
|
||||||
|
echo -e " 4) Fall back to SQLite"
|
||||||
|
read -rp "Choose [1]: " pg_fail
|
||||||
|
pg_fail="${pg_fail:-1}"
|
||||||
|
case "$pg_fail" in
|
||||||
|
2) pg_mode="2" ;;
|
||||||
|
3) echo -e "${red}Install aborted.${plain}"; exit 1 ;;
|
||||||
|
4) db_choice="1"; xui_dsn=""; break ;;
|
||||||
|
*) xui_dsn="" ;;
|
||||||
|
esac
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
done
|
||||||
if [[ -n "$xui_dsn" ]]; then
|
if [[ -n "$xui_dsn" ]]; then
|
||||||
install -d -m 755 /etc/default
|
install -d -m 755 "$(dirname "$xui_env_file")"
|
||||||
umask 077
|
umask 077
|
||||||
cat > /etc/default/x-ui << EOF
|
cat > "$xui_env_file" << EOF
|
||||||
XUI_DB_TYPE=postgres
|
XUI_DB_TYPE=postgres
|
||||||
XUI_DB_DSN=${xui_dsn}
|
XUI_DB_DSN=${xui_dsn}
|
||||||
EOF
|
EOF
|
||||||
chmod 600 /etc/default/x-ui
|
chmod 600 "$xui_env_file"
|
||||||
umask 022
|
umask 022
|
||||||
export XUI_DB_TYPE=postgres
|
export XUI_DB_TYPE=postgres
|
||||||
export XUI_DB_DSN="${xui_dsn}"
|
export XUI_DB_DSN="${xui_dsn}"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue