This commit is contained in:
hhftechnologies 2024-11-27 20:12:45 +05:30
parent d81527ec67
commit a64d0383d4

View file

@ -0,0 +1,142 @@
#!/bin/bash
#-----------------------------------#
# VARIABLES #
#-----------------------------------#
this_script_url="https://git.hhf.technology/hhf/script-management-cloudpanel/raw/branch/main/maintenance/cloudpanel-ui-mod.sh"
this_script_name="CloudPanel UI Mod Installation Script by @ccMatrix"
formatter_url="https://git.hhf.technology/hhf/TaskFormatter/raw/branch/main/bash_task_formatter/task_formatter.sh"
scriptname=$0
# Initialize success flag
success=0
# Path variables
APP_PATH="/home/clp/htdocs/app"
MOD_PATH="/home/clp/htdocs/app_mod"
CACHE_PATH="$APP_PATH/files/var/cache/prod/twig"
COMMAND_EXECUTOR="$APP_PATH/files/src/System/CommandExecutor.php"
BASH_ALIASES="/root/.bash_aliases"
INSTALL_PATH="/usr/local/bin/clp-install-mod"
#-----------------------------------#
# FORMATTER #
#-----------------------------------#
# Download and source the formatter with error handling
download_formatter() {
if [ ! -f "task_formatter.sh" ]; then
if ! wget "$formatter_url" --no-check-certificate -O task_formatter.sh > /dev/null 2>&1; then
echo "Error: Failed to download task_formatter.sh"
exit 1
fi
fi
chmod +x task_formatter.sh
source ./task_formatter.sh || { echo "Error: Failed to source task_formatter.sh"; exit 1; }
}
download_formatter
#-----------------------------------#
# FUNCTIONS #
#-----------------------------------#
# Function to copy script to bin
install_script() {
cp "$0" "$INSTALL_PATH" && \
chmod +x "$INSTALL_PATH"
if [ $? -eq 0 ]; then
echo -e "Script installed successfully $CHECK_MARK"
return 0
else
echo -e "Failed to install script $CROSS_MARK"
return 1
fi
}
# Function to setup alias
setup_alias() {
local alias_line="alias clp-update='/usr/bin/clp-update && $INSTALL_PATH'"
if [ ! -f "$BASH_ALIASES" ]; then
echo "$alias_line" > "$BASH_ALIASES"
else
grep -q "alias clp-update=" "$BASH_ALIASES" && \
sed -i "s|alias clp-update=.*|$alias_line|" "$BASH_ALIASES" || \
echo "$alias_line" >> "$BASH_ALIASES"
fi
if [ $? -eq 0 ]; then
source "$BASH_ALIASES"
echo -e "Alias setup successfully $CHECK_MARK"
return 0
else
echo -e "Failed to setup alias $CROSS_MARK"
return 1
fi
}
# Function to install UI modifications
install_ui_mods() {
if [ -d "$MOD_PATH" ]; then
cp -r "$MOD_PATH"/* "$APP_PATH"/ && \
chown -R clp:clp "$APP_PATH" && \
rm -rf "$CACHE_PATH"
if [ $? -eq 0 ]; then
echo -e "UI modifications installed successfully $CHECK_MARK"
return 0
else
echo -e "Failed to install UI modifications $CROSS_MARK"
return 1
fi
else
echo -e "Mod directory not found $CROSS_MARK"
return 1
fi
}
# Function to patch execution timeout
patch_timeout() {
if [ -f "$COMMAND_EXECUTOR" ]; then
sed -i 's/timeout = 30/timeout = 60/' "$COMMAND_EXECUTOR"
if [ $? -eq 0 ]; then
echo -e "Timeout patched successfully $CHECK_MARK"
return 0
else
echo -e "Failed to patch timeout $CROSS_MARK"
return 1
fi
else
echo -e "CommandExecutor.php not found $CROSS_MARK"
return 1
fi
}
#-----------------------------------#
# MAIN LOGIC #
#-----------------------------------#
print_header "$this_script_name" "$this_script_url"
if ! format_output install_script "Installing script to /usr/local/bin"; then
success=1
fi
if ! format_output setup_alias "Setting up clp-update alias"; then
success=1
fi
if ! format_output install_ui_mods "Installing UI modifications"; then
success=1
fi
if ! format_output patch_timeout "Patching execution timeout"; then
success=1
fi
# Print final message
final_message "$this_script_name" "$success"
exit $success