-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetup.sh
More file actions
119 lines (103 loc) · 3.96 KB
/
setup.sh
File metadata and controls
119 lines (103 loc) · 3.96 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env bash
set -euo pipefail
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
info() { echo -e "${YELLOW}[INFO]${NC} $1"; }
ok() { echo -e "${GREEN}[OK]${NC} $1"; }
fail() { echo -e "${RED}[ERROR]${NC} $1"; exit 1; }
trap 'fail "Setup failed at line $LINENO."' ERR
# Require root privileges
if [[ "${EUID}" -ne 0 ]]; then
fail "Please run as root (example: curl -fsSL <raw-setup-url> | sudo bash)"
fi
APP_NAME="Integrated-Share"
REPO_URL="https://github.com/InferiorAK/Integrated-Share.git"
TARGET_ROOT="/var/www"
TARGET_DIR="${TARGET_ROOT}/${APP_NAME}"
SERVICE_NAME="integrated-share"
SYSTEMD_FILE="/etc/systemd/system/${SERVICE_NAME}.service"
# Check required binaries
for cmd in git python3 pip3 systemctl; do
command -v "${cmd}" >/dev/null 2>&1 || fail "Missing required command: ${cmd}"
done
# Ensure service user exists
if id -u www-data >/dev/null 2>&1; then
ok "User www-data already exists."
else
info "Creating user www-data..."
useradd --system --create-home --home-dir /var/www --shell /usr/sbin/nologin www-data
ok "User www-data created."
fi
# Prepare target root
mkdir -p "${TARGET_ROOT}"
ok "${TARGET_ROOT} is ready."
# Clone or update repository
if [[ -d "${TARGET_DIR}/.git" ]]; then
info "Updating existing repository in ${TARGET_DIR}..."
git -C "${TARGET_DIR}" fetch --all --prune
git -C "${TARGET_DIR}" reset --hard origin/main
ok "Repository updated."
else
info "Cloning repository to ${TARGET_DIR}..."
rm -rf "${TARGET_DIR}"
git clone "${REPO_URL}" "${TARGET_DIR}"
ok "Repository cloned."
fi
# Ensure runtime folders
mkdir -p "${TARGET_DIR}/uploads" "${TARGET_DIR}/logs" "${TARGET_DIR}/instance"
ok "Runtime directories ensured."
# Install dependencies directly (no venv)
info "Installing Python dependencies..."
PIP_LOG="$(mktemp)"
if pip3 install --ignore-installed -r "${TARGET_DIR}/requirements.txt" 2>&1 | tee "${PIP_LOG}"; then
ok "Dependencies installed."
elif pip3 install --ignore-installed --break-system-packages -r "${TARGET_DIR}/requirements.txt" 2>&1 | tee "${PIP_LOG}"; then
ok "Dependencies installed with --ignore-installed --break-system-packages."
else
info "pip3 install failed, trying distro packages fallback..."
if command -v apt-get >/dev/null 2>&1; then
apt-get update -y
apt-get install -y python3-flask python3-flask-cors python3-flask-sqlalchemy python3-werkzeug gunicorn
ok "Dependencies installed via apt fallback."
else
echo -e "${RED}Last pip output:${NC}"
tail -n 20 "${PIP_LOG}" || true
rm -f "${PIP_LOG}" || true
fail "Could not install Python dependencies (pip3 and apt fallback unavailable)."
fi
fi
rm -f "${PIP_LOG}" || true
# Set ownership and permissions
info "Applying ownership and permissions..."
chown -R www-data:www-data "${TARGET_DIR}"
find "${TARGET_DIR}" -type d -exec chmod 755 {} \;
find "${TARGET_DIR}" -type f -exec chmod 644 {} \;
chmod 775 "${TARGET_DIR}/uploads" "${TARGET_DIR}/logs" "${TARGET_DIR}/instance"
chmod 755 "${TARGET_DIR}/setup.sh" || true
[[ -f "${TARGET_DIR}/clean.sh" ]] && chmod 755 "${TARGET_DIR}/clean.sh" || true
ok "Permissions applied."
# Validate and install service
[[ -f "${TARGET_DIR}/integrated-share.service" ]] || fail "Missing integrated-share.service in repository."
cp "${TARGET_DIR}/integrated-share.service" "${SYSTEMD_FILE}"
ok "Service file installed."
# Reload and start service
systemctl daemon-reload
systemctl enable "${SERVICE_NAME}" >/dev/null
systemctl restart "${SERVICE_NAME}"
ok "Service enabled and started."
# Verify service
if systemctl is-active --quiet "${SERVICE_NAME}"; then
ok "${SERVICE_NAME} is active."
else
fail "${SERVICE_NAME} is not active. Run: systemctl status ${SERVICE_NAME}"
fi
echo
ok "Deployment completed successfully."
echo -e "${YELLOW}Service commands:${NC}"
echo " sudo systemctl start ${SERVICE_NAME}"
echo " sudo systemctl stop ${SERVICE_NAME}"
echo " sudo systemctl restart ${SERVICE_NAME}"
echo " sudo systemctl status ${SERVICE_NAME}"
echo " sudo systemctl disable ${SERVICE_NAME}"