-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_forknow.sh
180 lines (151 loc) · 5.21 KB
/
install_forknow.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/bin/bash
# Path to the configuration file
CONFIG_FILE="/pg/config/pgfork.cfg"
CONFIG_VERSION="/pg/config/config.cfg"
COMMANDS_SCRIPT="/pg/installer/commands.sh"
# ANSI color codes
LIGHT_RED="\033[1;31m"
LIGHT_YELLOW="\033[1;33m"
LIGHT_GREEN="\033[1;32m"
LIGHT_BLUE="\033[1;34m"
PURPLE="\033[0;35m"
HOT_PINK="\033[1;35m"
NC="\033[0m" # No color
# Default values
user="plexguide"
repo="plexguide.com"
branch="v11"
# Function to validate GitHub repository and branch
validate_github_repo_and_branch() {
local api_url="https://api.github.com/repos/${user}/${repo}/branches/${branch}"
if curl --output /dev/null --silent --head --fail "$api_url"; then
return 0
else
return 1
fi
}
# Function to set or update the VERSION in the config file
set_config_version() {
if [[ ! -f "$CONFIG_VERSION" ]]; then
echo "Creating config file at $CONFIG_VERSION"
echo 'VERSION="PG Alpha"' > "$CONFIG_VERSION"
fi
version_string="Fork - $user/$repo ($branch)"
# Use awk to replace the entire line containing VERSION
awk -v new_version="$version_string" '/^VERSION=/{$0="VERSION=\"" new_version "\""} 1' "$CONFIG_VERSION" > "${CONFIG_VERSION}.tmp" && mv "${CONFIG_VERSION}.tmp" "$CONFIG_VERSION"
echo "VERSION has been updated to \"$version_string\" in $CONFIG_VERSION"
}
# Check if the configuration file exists, if not, create it
if [[ ! -f "$CONFIG_FILE" ]]; then
echo "Creating config file at $CONFIG_FILE"
mkdir -p "$(dirname "$CONFIG_FILE")"
touch "$CONFIG_FILE"
echo "user=\"$user\"" > "$CONFIG_FILE"
echo "repo=\"$repo\"" >> "$CONFIG_FILE"
echo "branch=\"$branch\"" >> "$CONFIG_FILE"
else
# Source the configuration file to load existing values
source "$CONFIG_FILE"
fi
# Function to ensure commands.sh exists and is executable
ensure_commands_script() {
if [[ ! -f "$COMMANDS_SCRIPT" ]]; then
echo "commands.sh not found. Downloading from GitHub..."
mkdir -p "$(dirname "$COMMANDS_SCRIPT")"
curl -o "$COMMANDS_SCRIPT" https://raw.githubusercontent.com/plexguide/Installer/v11/commands.sh
chmod +x "$COMMANDS_SCRIPT"
chown 1000:1000 "$COMMANDS_SCRIPT"
fi
}
# Function to create command symlinks
create_command_symlinks() {
ensure_commands_script
source "$COMMANDS_SCRIPT"
create_command_symlinks
}
# Function to create directories with the correct permissions
create_directories() {
echo "Creating necessary directories..."
directories=(
"/pg/config"
"/pg/scripts"
"/pg/apps"
"/pg/stage"
"/pg/installer"
)
for dir in "${directories[@]}"; do
if [[ ! -d "$dir" ]]; then
mkdir -p "$dir"
echo "Created $dir"
else
echo "$dir already exists"
fi
chown -R 1000:1000 "$dir"
chmod -R +x "$dir"
done
}
# Function to download and place files into /pg/stage/
download_repository() {
echo "Preparing /pg/stage/ directory..."
if [[ -d "/pg/stage/" ]]; then
rm -rf /pg/stage/*
rm -rf /pg/stage/.* 2>/dev/null || true
echo "Cleared /pg/stage/ directory."
fi
# Download the repository using the user, repo, and branch variables
echo "Downloading repository from ${user}/${repo} on branch ${branch}..."
git clone -b "$branch" "https://github.com/${user}/${repo}.git" /pg/stage/
if [[ $? -eq 0 ]]; then
echo "Repository successfully downloaded to /pg/stage/."
else
echo "Failed to download the repository. Please check your network connection and repository details."
exit 1
fi
}
# Function to move content from /pg/stage/mods/ to /pg/
move_folders() {
echo "Moving folders from /pg/stage/mods/ to /pg/..."
if [[ -d "/pg/stage/mods" ]]; then
for folder in /pg/stage/mods/*; do
foldername=$(basename "$folder")
# Remove the existing folder in /pg/$foldername
if [[ -d "/pg/$foldername" ]]; then
rm -rf "/pg/$foldername"
echo "Removed existing folder: /pg/$foldername"
fi
# Copy the folder from /pg/stage/mods/ to /pg/
cp -r "/pg/stage/mods/$foldername" "/pg/$foldername"
echo "Copied $foldername to /pg/"
# Set permissions and ownership for the folder and its contents
chown -R 1000:1000 "/pg/$foldername"
chmod -R +x "/pg/$foldername"
echo "Set permissions and ownership for /pg/$foldername and its contents"
done
else
echo "Source directory /pg/stage/mods does not exist. No folders to move."
exit 1
fi
}
# New Function: Deploy PG Fork with updated 4-digit PIN format
deploy_pg_fork() {
create_directories
download_repository
move_folders
set_config_version # Call set_config_version here
create_command_symlinks
show_exit
exit 0
}
show_exit() {
sudo plexguide
exit 0
}
menu_commands() {
echo "Returning to the main menu..."
bash /pg/installer/menu_commands.sh
}
# Ensure commands.sh exists and create symlinks at the start
ensure_commands_script
create_command_symlinks
# Start the PG Fork menu
deploy_pg_fork