Compare commits
No commits in common. "3d47dcec083c7c2438e1b7507d8bd8f2946f6b0a" and "b0f3b9cf22b6f7d57b403d4490c4ee9c2b093a10" have entirely different histories.
3d47dcec08
...
b0f3b9cf22
1 changed files with 36 additions and 48 deletions
|
@ -1,8 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Run this script with:
|
||||
# wget https://raw.githubusercontent.com/pitterpatter22/Script-Repo/main/Testing/test.sh --no-check-certificate && sudo bash script-template.sh
|
||||
|
||||
|
||||
#-----------------------------------#
|
||||
# VARIABLES #
|
||||
|
@ -10,7 +7,7 @@
|
|||
|
||||
this_script_url="https://git.hhf.technology/hhf/script-management-cloudpanel/raw/branch/main/Testing/test.sh"
|
||||
this_script_name="Test Script"
|
||||
formatter_url="https://git.hhf.technology/hhf/TaskFormatter/raw/branch/main/bash_task_formatter/task_formatter.sh"
|
||||
formatter_url="https://git.hhf.technology/hhf/script-management-cloudpanel/raw/branch/main/bash_task_formatter/task_formatter.sh"
|
||||
scriptname=$0
|
||||
|
||||
# Initialize success flag
|
||||
|
@ -20,36 +17,17 @@ success=0
|
|||
USER_TO_RUN_AS="${1:-$SUDO_USER}"
|
||||
USER_HOME=$(eval echo ~$USER_TO_RUN_AS)
|
||||
|
||||
|
||||
#-----------------------------------#
|
||||
# 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
|
||||
if [ ! -f "task_formatter.sh" ]; then
|
||||
wget $formatter_url --no-check-certificate -O task_formatter.sh > /dev/null 2>&1
|
||||
fi
|
||||
|
||||
if [ ! -f "task_formatter.sh" ]; then
|
||||
echo "Error: task_formatter.sh not found after download attempt"
|
||||
exit 1
|
||||
fi
|
||||
source ./task_formatter.sh
|
||||
|
||||
# Make the formatter executable
|
||||
chmod +x task_formatter.sh
|
||||
|
||||
# Source the formatter with error checking
|
||||
if ! source ./task_formatter.sh; then
|
||||
echo "Error: Failed to source task_formatter.sh"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Call the download_formatter function
|
||||
download_formatter
|
||||
|
||||
#-----------------------------------#
|
||||
# FUNCTIONS #
|
||||
|
@ -68,7 +46,6 @@ update_upgrade_packages() {
|
|||
example_function_1() {
|
||||
echo -e "This is example function 1. $CHECK_MARK"
|
||||
sleep 2
|
||||
return 0
|
||||
}
|
||||
|
||||
# Example function 2
|
||||
|
@ -77,7 +54,6 @@ example_function_2() {
|
|||
sleep 2
|
||||
echo -e "Done $CHECK_MARK"
|
||||
sleep 2
|
||||
return 0
|
||||
}
|
||||
|
||||
# Example function 3 with an error
|
||||
|
@ -106,30 +82,48 @@ remove_script() {
|
|||
rm task_formatter.sh
|
||||
fi
|
||||
echo -e "Cleaned up $CHECK_MARK"
|
||||
return 0
|
||||
}
|
||||
|
||||
# Remove created files on Failure
|
||||
cleanup_files() {
|
||||
echo -e "Cleaned up $CHECK_MARK"
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
#-----------------------------------#
|
||||
# MAIN LOGIC #
|
||||
#-----------------------------------#
|
||||
|
||||
# Check if print_header function exists
|
||||
if ! command -v print_header >/dev/null 2>&1; then
|
||||
echo "Error: print_header function not found. Formatter may not be properly sourced."
|
||||
exit 1
|
||||
'''
|
||||
Run functions with this format:
|
||||
|
||||
format_output {function_name} "Function Description"
|
||||
|
||||
Example:
|
||||
|
||||
format_output update_upgrade_packages "Update and Upgrade Packages"
|
||||
|
||||
|
||||
To add in success monitoring when script is run from master.sh, run like this:
|
||||
|
||||
if ! format_output {function_name} "Function Description"; then
|
||||
cleanup_files
|
||||
success=1
|
||||
fi
|
||||
|
||||
if ! format_output {function_name} "Function Description"; then
|
||||
cleanup_files
|
||||
success=1
|
||||
fi
|
||||
|
||||
'''
|
||||
|
||||
# Print header
|
||||
print_header "$this_script_name" "$this_script_url"
|
||||
|
||||
echo -e "Running as User: $USER_TO_RUN_AS\nUser Home: $USER_HOME\n"
|
||||
|
||||
|
||||
# Run the functions with formatted output
|
||||
if ! format_output example_function_1 "Example Function 1"; then
|
||||
cleanup_files
|
||||
|
@ -153,12 +147,6 @@ fi
|
|||
|
||||
format_output remove_script "Cleaning up"
|
||||
|
||||
# Check if final_message function exists
|
||||
if ! command -v final_message >/dev/null 2>&1; then
|
||||
echo "Error: final_message function not found. Formatter may not be properly sourced."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Print final message
|
||||
final_message "$this_script_name" $success
|
||||
|
||||
|
|
Loading…
Reference in a new issue