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
|
#!/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 #
|
# VARIABLES #
|
||||||
|
@ -10,7 +7,7 @@
|
||||||
|
|
||||||
this_script_url="https://git.hhf.technology/hhf/script-management-cloudpanel/raw/branch/main/Testing/test.sh"
|
this_script_url="https://git.hhf.technology/hhf/script-management-cloudpanel/raw/branch/main/Testing/test.sh"
|
||||||
this_script_name="Test Script"
|
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
|
scriptname=$0
|
||||||
|
|
||||||
# Initialize success flag
|
# Initialize success flag
|
||||||
|
@ -20,36 +17,17 @@ success=0
|
||||||
USER_TO_RUN_AS="${1:-$SUDO_USER}"
|
USER_TO_RUN_AS="${1:-$SUDO_USER}"
|
||||||
USER_HOME=$(eval echo ~$USER_TO_RUN_AS)
|
USER_HOME=$(eval echo ~$USER_TO_RUN_AS)
|
||||||
|
|
||||||
|
|
||||||
#-----------------------------------#
|
#-----------------------------------#
|
||||||
# FORMATTER #
|
# FORMATTER #
|
||||||
#-----------------------------------#
|
#-----------------------------------#
|
||||||
|
|
||||||
# Download and source the formatter with error handling
|
if [ ! -f "task_formatter.sh" ]; then
|
||||||
download_formatter() {
|
wget $formatter_url --no-check-certificate -O task_formatter.sh > /dev/null 2>&1
|
||||||
if [ ! -f "task_formatter.sh" ]; then
|
fi
|
||||||
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
|
source ./task_formatter.sh
|
||||||
echo "Error: task_formatter.sh not found after download attempt"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# 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 #
|
# FUNCTIONS #
|
||||||
|
@ -68,7 +46,6 @@ update_upgrade_packages() {
|
||||||
example_function_1() {
|
example_function_1() {
|
||||||
echo -e "This is example function 1. $CHECK_MARK"
|
echo -e "This is example function 1. $CHECK_MARK"
|
||||||
sleep 2
|
sleep 2
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Example function 2
|
# Example function 2
|
||||||
|
@ -77,7 +54,6 @@ example_function_2() {
|
||||||
sleep 2
|
sleep 2
|
||||||
echo -e "Done $CHECK_MARK"
|
echo -e "Done $CHECK_MARK"
|
||||||
sleep 2
|
sleep 2
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Example function 3 with an error
|
# Example function 3 with an error
|
||||||
|
@ -88,12 +64,12 @@ example_function_3() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ask_reconfigure() {
|
ask_reconfigure() {
|
||||||
read -p "Question? (y/n): " choice
|
read -p "Question? (y/n): " choice
|
||||||
case "$choice" in
|
case "$choice" in
|
||||||
y|Y ) return 0;;
|
y|Y ) return 0;;
|
||||||
n|N ) return 1;;
|
n|N ) return 1;;
|
||||||
* ) echo "Invalid choice."; ask_reconfigure;;
|
* ) echo "Invalid choice."; ask_reconfigure;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
# remove artifacts
|
# remove artifacts
|
||||||
|
@ -106,30 +82,48 @@ remove_script() {
|
||||||
rm task_formatter.sh
|
rm task_formatter.sh
|
||||||
fi
|
fi
|
||||||
echo -e "Cleaned up $CHECK_MARK"
|
echo -e "Cleaned up $CHECK_MARK"
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Remove created files on Failure
|
# Remove created files on Failure
|
||||||
cleanup_files() {
|
cleanup_files() {
|
||||||
echo -e "Cleaned up $CHECK_MARK"
|
echo -e "Cleaned up $CHECK_MARK"
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#-----------------------------------#
|
#-----------------------------------#
|
||||||
# MAIN LOGIC #
|
# MAIN LOGIC #
|
||||||
#-----------------------------------#
|
#-----------------------------------#
|
||||||
|
|
||||||
# Check if print_header function exists
|
'''
|
||||||
if ! command -v print_header >/dev/null 2>&1; then
|
Run functions with this format:
|
||||||
echo "Error: print_header function not found. Formatter may not be properly sourced."
|
|
||||||
exit 1
|
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
|
fi
|
||||||
|
|
||||||
|
if ! format_output {function_name} "Function Description"; then
|
||||||
|
cleanup_files
|
||||||
|
success=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
||||||
# Print header
|
# Print header
|
||||||
print_header "$this_script_name" "$this_script_url"
|
print_header "$this_script_name" "$this_script_url"
|
||||||
|
|
||||||
echo -e "Running as User: $USER_TO_RUN_AS\nUser Home: $USER_HOME\n"
|
echo -e "Running as User: $USER_TO_RUN_AS\nUser Home: $USER_HOME\n"
|
||||||
|
|
||||||
|
|
||||||
# Run the functions with formatted output
|
# Run the functions with formatted output
|
||||||
if ! format_output example_function_1 "Example Function 1"; then
|
if ! format_output example_function_1 "Example Function 1"; then
|
||||||
cleanup_files
|
cleanup_files
|
||||||
|
@ -153,12 +147,6 @@ fi
|
||||||
|
|
||||||
format_output remove_script "Cleaning up"
|
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
|
# Print final message
|
||||||
final_message "$this_script_name" $success
|
final_message "$this_script_name" $success
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue