-
Notifications
You must be signed in to change notification settings - Fork 14
/
install-script.sh
116 lines (97 loc) · 5.21 KB
/
install-script.sh
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
#!/bin/bash
# [SETUP] Install necessary packages, including git
echo -e "[SETUP] Install packages"
apt-get update -qq > /dev/null 2>&1 && apt-get install -qq > /dev/null 2>&1 -y git wget perl perl-doc fcgiwrap
# Change to server directory
cd /mnt/server
# [SETUP] Create necessary folders
echo -e "[SETUP] Create folders"
mkdir -p logs tmp www
# Clone the default repository into a temporary directory
echo "[Git] Cloning default repository 'https://github.com/Ym0T/pterodactyl-nginx-egg' into temporary directory."
git clone https://github.com/Ym0T/pterodactyl-nginx-egg /mnt/server/gtemp > /dev/null 2>&1 && echo "[Git] Repository cloned successfully." || { echo "[Git] Error: Default repository clone failed."; exit 21; }
# Copy the www folder and files from the temporary repository to the target directory
echo "[Git] Copying folder and files from default repository."
cp -r /mnt/server/gtemp/nginx /mnt/server || { echo "[Git] Error: Copying 'nginx' folder failed."; exit 22; }
cp -r /mnt/server/gtemp/php /mnt/server || { echo "[Git] Error: Copying 'php' folder failed."; exit 22; }
cp /mnt/server/gtemp/nginx.sh /mnt/server || { echo "[Git] Error: Copying 'nginx.sh' file failed."; exit 22; }
cp /mnt/server/gtemp/pull-git.sh /mnt/server || { echo "[Git] Error: Copying 'pull-git.sh' file failed."; exit 22; }
chmod +x /mnt/server/nginx.sh && chmod +x /mnt/server/pull-git.sh
# Remove the temporary cloned repository
rm -rf /mnt/server/gtemp
# Check if GIT_ADDRESS is set
if [ -z "${GIT_ADDRESS}" ]; then
echo "[Git] Info: GIT_ADDRESS is not set."
echo "[Git] Git operations are disabled. Skipping Git actions."
else
# Add .git suffix to GIT_ADDRESS if it's not present
if [[ ${GIT_ADDRESS} != *.git ]]; then
GIT_ADDRESS="${GIT_ADDRESS}.git"
echo "[Git] Added .git suffix to GIT_ADDRESS: ${GIT_ADDRESS}"
fi
# If username and access token are provided, use authenticated access
if [ -n "${USERNAME}" ] && [ -n "${ACCESS_TOKEN}" ]; then
echo "[Git] Using authenticated Git access."
# Extract the domain and the rest of the URL, ensuring the correct format
GIT_DOMAIN=$(echo "${GIT_ADDRESS}" | cut -d/ -f3)
GIT_REPO=$(echo "${GIT_ADDRESS}" | cut -d/ -f4-) # Rest of the URL after the domain
# Construct the authenticated Git URL
GIT_ADDRESS="https://${USERNAME}:${ACCESS_TOKEN}@${GIT_DOMAIN}/${GIT_REPO}"
echo "[Git] Updated GIT_ADDRESS for authenticated access: ${GIT_ADDRESS}"
else
echo "[Git] Using anonymous Git access."
fi
# Check if the 'www' directory exists, if not create it
if [ ! -d /mnt/server/www ]; then
echo "[Git] Creating /mnt/server/www directory."
mkdir -p /mnt/server/www
else
rm -R /mnt/server/www && mkdir -p /mnt/server/www
fi
cd /mnt/server/www || { echo "[Git] Error: Could not access /mnt/server/www directory."; exit 1; }
if [ "$(ls -A /mnt/server/www)" ]; then
echo "[Git] /mnt/server/www directory is not empty."
# Check if .git directory exists in 'www'
if [ -d .git ]; then
echo "[Git] .git directory exists in 'www'."
# Check if .git/config exists in 'www'
if [ -f .git/config ]; then
echo "[Git] Loading repository info from git config in 'www'."
ORIGIN=$(git config --get remote.origin.url)
else
echo "[Git] Error: .git/config not found in 'www'. The directory may contain files, but it's not a valid Git repository."
exit 10
fi
else
echo "[Git] Error: Directory contains files but no Git repository found in 'www'."
exit 11
fi
# Check if origin matches the provided GIT_ADDRESS
if [ "${ORIGIN}" == "${GIT_ADDRESS}" ]; then
echo "[Git] Repository origin matches. Pulling latest changes from ${GIT_ADDRESS} in 'www'."
git pull || { echo "[Git] Error: git pull failed for 'www'."; exit 12; }
else
echo "[Git] Error: Repository origin does not match the provided GIT_ADDRESS in 'www'."
exit 13
fi
else
# The directory is empty, clone the repository
echo "[Git] /mnt/server/www directory is empty. Cloning ${GIT_ADDRESS} into /mnt/server/www."
git clone ${GIT_ADDRESS} . > /dev/null 2>&1 && echo "[Git] Repository cloned successfully." || { echo "[Git] Error: git clone failed for 'www'."; exit 14; }
fi
fi
# Check if WordPress should be installed
if [ "${WORDPRESS}" == "true" ] || [ "${WORDPRESS}" == "1" ]; then
echo "[SETUP] Install WordPress"
cd /mnt/server/www
wget -q http://wordpress.org/latest.tar.gz > /dev/null 2>&1 || { echo "[SETUP] Error: Downloading WordPress failed."; exit 16; }
tar xzf latest.tar.gz >/dev/null 2>&1
mv wordpress/* .
rm -rf wordpress latest.tar.gz
echo "[SETUP] WordPress installed - http://ip:port/wp-admin"
elif [ -z "${GIT_ADDRESS}" ]; then
# Create a simple PHP info page if WordPress is not installed
echo "<?php phpinfo(); ?>" > "www/index.php"
fi
echo -e "[DONE] Everything has been installed successfully"
echo -e "[INFO] You can now start the nginx web server"