-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.sh
130 lines (105 loc) · 4.09 KB
/
commands.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
#!/bin/bash
# ANSI color codes
RED='\033[0;31m'
GOLD='\033[0;33m'
BOLD='\033[1m'
NC='\033[0m' # No Color
info() {
echo -e "${BOLD}${GOLD}[INFO] $1${NC}"
}
warn() {
echo -e "${BOLD}${RED}[WARN] $1${NC}"
}
error() {
echo -e "${BOLD}${RED}[ERROR] $1${NC}"
}
# Function to execute the adduser.sh script with better control
execute_adduser_script() {
local config_file="/pg/config/username.cfg"
local adduser_script_url="https://raw.githubusercontent.com/plexguide/Installer/refs/heads/v11/adduser.sh"
local tmp_script="/tmp/adduser_tmp.sh"
# Check if the config file exists and contains the word "username"
if [[ -f "$config_file" ]] && grep -q "username" "$config_file"; then
# echo "Existing user configuration found. Skipping user setup."
return 0
fi
echo "Downloading the adduser script from URL..."
# Download the script to a temporary file
if curl -sL "$adduser_script_url" -o "$tmp_script"; then
echo "Download successful."
# Make sure the script is executable
chmod +x "$tmp_script"
# Execute the script
if bash "$tmp_script"; then
echo "User setup completed successfully."
else
echo "Error: Failed to execute the adduser script."
exit 1
fi
# Remove the temporary script
rm -f "$tmp_script"
else
echo "Error: Failed to download the adduser script. Please check your internet connection and try again."
exit 1
fi
}
# Function to create symbolic links for command scripts
create_command_symlinks() {
# info "Creating command symlinks..."
# Define an associative array with command names as keys and script paths as values
declare -A commands=(
["plexguide"]="/pg/scripts/menu.sh"
["pg"]="/pg/scripts/menu.sh"
["pgdev"]="/pg/installer/install_dev.sh"
["pgbeta"]="/pg/installer/install_beta.sh"
["pgfork"]="/pg/installer/install_fork.sh"
["pgforknow"]="/pg/installer/install_forknow.sh"
["pgstable"]="/pg/installer/install_stable.sh"
["pgreinstall"]="/pgreinstall/pgreinstall.sh"
)
# Loop over the associative array to create symbolic links and set executable permissions
for cmd in "${!commands[@]}"; do
# Create the symbolic link with force option to overwrite if it exists
sudo ln -sf "${commands[$cmd]}" "/usr/local/bin/$cmd"
# Set ownership to 1000:1000
sudo chown 1000:1000 "/usr/local/bin/$cmd"
# Set the executable permission to 755 (read and execute for everyone)
sudo chmod 755 "/usr/local/bin/$cmd"
# info "Created symlink: $cmd -> ${commands[$cmd]}"
done
# info "Command symlinks created successfully."
}
# Function to ensure all created commands are 1000:1000 and executable
ensure_command_permissions() {
# info "Ensuring correct permissions for all created commands..."
local commands=("plexguide" "pg" "pgdev" "pgbeta" "pgfork" "pgstable" "pgforknow" "pgreinstall")
for cmd in "${commands[@]}"; do
if [[ -L "/usr/local/bin/$cmd" ]]; then
sudo chown 1000:1000 "/usr/local/bin/$cmd"
sudo chmod 755 "/usr/local/bin/$cmd"
# info "Set permissions for $cmd: owner 1000:1000, mode 755"
else
warn "Command $cmd not found or not a symlink in /usr/local/bin"
fi
done
# info "Permissions check and update completed."
}
# Function to update permissions for /pg directory
update_pg_permissions() {
# info "Updating permissions for /pg directory..."
if [[ -d "/pg" ]]; then
sudo chown -R 1000:1000 /pg
sudo find /pg -type d -exec chmod 755 {} +
sudo find /pg -type f -exec chmod 644 {} +
sudo chmod +x /pg/scripts/*.sh /pg/installer/*.sh /pgreinstall/*.sh 2>/dev/null
# info "Permissions updated for /pg directory"
else
warn "/pg directory not found"
fi
}
# Main script execution
execute_adduser_script
create_command_symlinks
ensure_command_permissions
update_pg_permissions
# info "Setup complete. You can now use the pginstall command to run the installer."