1
+ #! /bin/bash
2
+
3
+ # [SETUP] Install necessary packages, including git
4
+ echo -e " [SETUP] Install packages"
5
+ apt-get update -qq > /dev/null 2>&1 && apt-get install -qq > /dev/null 2>&1 -y git wget perl perl-doc fcgiwrap
6
+
7
+ # Change to server directory
8
+ cd /mnt/server
9
+
10
+ # [SETUP] Create necessary folders
11
+ echo -e " [SETUP] Create folders"
12
+ mkdir -p logs tmp www
13
+
14
+ # Clone the default repository into a temporary directory
15
+ echo " [Git] Cloning default repository 'https://github.com/Ym0T/pterodactyl-nginx-egg' into temporary directory."
16
+ 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; }
17
+
18
+ # Copy the www folder and files from the temporary repository to the target directory
19
+ echo " [Git] Copying folder and files from default repository."
20
+ cp -r /mnt/server/gtemp/nginx /mnt/server || { echo " [Git] Error: Copying 'nginx' folder failed." ; exit 22; }
21
+ cp -r /mnt/server/gtemp/php /mnt/server || { echo " [Git] Error: Copying 'php' folder failed." ; exit 22; }
22
+ cp /mnt/server/gtemp/nginx.sh /mnt/server || { echo " [Git] Error: Copying 'nginx.sh' file failed." ; exit 22; }
23
+ chmod +x /mnt/server/nginx.sh
24
+
25
+ # Remove the temporary cloned repository
26
+ rm -rf /mnt/server/gtemp
27
+
28
+ # Check if GIT_STATUS is set to 1 (enabled) or 0 (disabled) as the first step
29
+ if [ " ${GIT_STATUS} " == " 1" ] || [ " ${GIT_STATUS} " == " true" ]; then
30
+ echo " [Git] Git operations are enabled."
31
+
32
+ # Check if GIT_ADDRESS is set
33
+ if [ -z " ${GIT_ADDRESS} " ]; then
34
+ echo " [Git] Info: GIT_ADDRESS is not set."
35
+ else
36
+ # Add .git suffix to GIT_ADDRESS if it's not present
37
+ if [[ ${GIT_ADDRESS} != * .git ]]; then
38
+ GIT_ADDRESS=" ${GIT_ADDRESS} .git"
39
+ echo " [Git] Added .git suffix to GIT_ADDRESS: ${GIT_ADDRESS} "
40
+ fi
41
+
42
+ # If username and access token are provided, use authenticated access
43
+ if [ -n " ${USERNAME} " ] && [ -n " ${ACCESS_TOKEN} " ]; then
44
+ echo " [Git] Using authenticated Git access."
45
+ GIT_DOMAIN=$( echo " ${GIT_ADDRESS} " | cut -d/ -f3)
46
+ GIT_ADDRESS=" https://${USERNAME} :${ACCESS_TOKEN} @${GIT_DOMAIN} $( echo ${GIT_ADDRESS} | cut -d/ -f4-) "
47
+ echo " [Git] Updated GIT_ADDRESS for authenticated access: ${GIT_ADDRESS} "
48
+ else
49
+ echo " [Git] Using anonymous Git access."
50
+ fi
51
+
52
+ # Check if the 'www' directory exists, if not create it
53
+ if [ ! -d /mnt/server/www ]; then
54
+ echo " [Git] Creating /mnt/server/www directory."
55
+ mkdir -p /mnt/server/www
56
+ else
57
+ rm -R /mnt/server/www && mkdir -p /mnt/server/www
58
+ fi
59
+
60
+ cd /mnt/server/www || { echo " [Git] Error: Could not access /mnt/server/www directory." ; exit 1; }
61
+
62
+ if [ " $( ls -A /mnt/server/www) " ]; then
63
+ echo " [Git] /mnt/server/www directory is not empty."
64
+
65
+ # Check if .git directory exists in 'www'
66
+ if [ -d .git ]; then
67
+ echo " [Git] .git directory exists in 'www'."
68
+
69
+ # Check if .git/config exists in 'www'
70
+ if [ -f .git/config ]; then
71
+ echo " [Git] Loading repository info from git config in 'www'."
72
+ ORIGIN=$( git config --get remote.origin.url)
73
+ else
74
+ echo " [Git] Error: .git/config not found in 'www'. The directory may contain files, but it's not a valid Git repository."
75
+ exit 10
76
+ fi
77
+ else
78
+ echo " [Git] Error: Directory contains files but no Git repository found in 'www'."
79
+ exit 11
80
+ fi
81
+
82
+ # Check if origin matches the provided GIT_ADDRESS
83
+ if [ " ${ORIGIN} " == " ${GIT_ADDRESS} " ]; then
84
+ echo " [Git] Repository origin matches. Pulling latest changes from ${GIT_ADDRESS} in 'www'."
85
+ git pull || { echo " [Git] Error: git pull failed for 'www'." ; exit 12; }
86
+ else
87
+ echo " [Git] Error: Repository origin does not match the provided GIT_ADDRESS in 'www'."
88
+ exit 13
89
+ fi
90
+ else
91
+ # The directory is empty, clone the repository
92
+ echo " [Git] /mnt/server/www directory is empty. Cloning ${GIT_ADDRESS} into /mnt/server/www."
93
+ git clone ${GIT_ADDRESS} . > /dev/null 2>&1 && echo " [Git] Repository cloned successfully." || { echo " [Git] Error: git clone failed for 'www'." ; exit 14; }
94
+ fi
95
+ fi
96
+ else
97
+ echo " [Git] Git operations are disabled. Skipping Git actions."
98
+ fi
99
+
100
+
101
+ # Check if WordPress should be installed
102
+ if [ " ${WORDPRESS} " == " true" ] || [ " ${WORDPRESS} " == " 1" ]; then
103
+ echo " [SETUP] Install WordPress"
104
+ cd /mnt/server/www
105
+ wget -q http://wordpress.org/latest.tar.gz > /dev/null 2>&1 || { echo " [SETUP] Error: Downloading WordPress failed." ; exit 16; }
106
+ tar xzf latest.tar.gz > /dev/null 2>&1
107
+ mv wordpress/* .
108
+ rm -rf wordpress latest.tar.gz
109
+ echo " [SETUP] WordPress installed - http://ip:port/wp-admin"
110
+ fi
111
+
112
+ echo -e " [DONE] Everything has been installed successfully"
113
+ echo -e " [STATUS] You can now start nginx"
0 commit comments