This commit is contained in:
hhftechnologies 2024-11-27 21:17:10 +05:30
parent f3f688f3a7
commit 6219ce697b
2 changed files with 181 additions and 1 deletions

View file

@ -4,7 +4,7 @@
# VARIABLES #
#-----------------------------------#
this_script_url="https://example.com/docker-install.sh"
this_script_url="https://git.hhf.technology/hhf/script-management-cloudpanel/raw/branch/main/install/docker-install.sh"
this_script_name="Docker Installation Script"
formatter_url="https://git.hhf.technology/hhf/TaskFormatter/raw/branch/main/bash_task_formatter/task_formatter.sh"
scriptname=$0

180
install/portainer-setup.sh Normal file
View file

@ -0,0 +1,180 @@
#!/bin/bash
#-----------------------------------#
# VARIABLES #
#-----------------------------------#
this_script_url="https://git.hhf.technology/hhf/script-management-cloudpanel/raw/branch/main/install/portainer-setup.sh"
this_script_name="Portainer Setup Script"
formatter_url="https://git.hhf.technology/hhf/TaskFormatter/raw/branch/main/bash_task_formatter/task_formatter.sh"
scriptname=$0
# Initialize success flag
success=0
# Determine the user (use the first argument if provided, otherwise fallback)
USER_TO_RUN_AS="${1:-$SUDO_USER}"
USER_HOME=$(eval echo ~$USER_TO_RUN_AS)
# Portainer specific variables
PORTAINER_DATA_DIR="/docker/Portainer"
#-----------------------------------#
# COMPATIBILITY CHECK #
#-----------------------------------#
# Check Ubuntu version and architecture
check_compatibility() {
if ! grep -q "Ubuntu 24.04" /etc/os-release; then
echo "This script is only compatible with Ubuntu 24.04"
return 1
fi
if [ "$(uname -m)" = "aarch64" ] || [ "$(uname -m)" = "armv7l" ]; then
echo "This script is not compatible with ARM architecture"
return 1
fi
return 0
}
#-----------------------------------#
# 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
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
source ./task_formatter.sh || { echo "Error: Failed to source task_formatter.sh"; exit 1; }
# Check if print_header is available after sourcing
if ! declare -f print_header > /dev/null; then
echo "Error: print_header function not found after sourcing."
exit 1
fi
}
#-----------------------------------#
# FUNCTIONS #
#-----------------------------------#
# Check if Docker is installed
check_docker() {
if ! command -v docker &> /dev/null; then
echo "Docker is not installed."
echo "Please run the docker-install.sh script from the install folder first."
echo "After installing Docker, you can run this script again."
return 1
fi
# Check if Docker service is running
if ! systemctl is-active --quiet docker; then
echo "Docker service is not running."
echo "Please start Docker service with: sudo systemctl start docker"
return 1
fi
return 0
}
# Create Portainer data directory
create_portainer_directory() {
sudo mkdir -p $PORTAINER_DATA_DIR
if [ ! -d "$PORTAINER_DATA_DIR" ]; then
echo "Failed to create Portainer data directory"
return 1
fi
return 0
}
# Setup Portainer
setup_portainer() {
# Create Portainer volume
cd $PORTAINER_DATA_DIR
if ! docker volume create portainer_data; then
echo "Failed to create Portainer volume"
return 1
fi
# Run Portainer container
if ! docker run -d \
-p 8000:8000 \
-p 9443:9443 \
--name portainer \
--restart=always \
-v /var/run/docker.sock:/var/run/docker.sock \
-v portainer_data:/data \
portainer/portainer-ce:latest; then
echo "Failed to start Portainer container"
return 1
fi
return 0
}
# Remove created files on cleanup
cleanup_files() {
rm -f task_formatter.sh
echo -e "Cleaned up temporary files $CHECK_MARK"
return 0
}
#-----------------------------------#
# MAIN LOGIC #
#-----------------------------------#
# Download and source the formatter
download_formatter
# Print header
print_header "$this_script_name" "$this_script_url"
echo -e "Running as User: $USER_TO_RUN_AS\nUser Home: $USER_HOME\n"
echo -e "WARNING: This script is only compatible with Ubuntu 24.04 on non-ARM machines\n"
# Check compatibility
if ! format_output check_compatibility "Checking system compatibility"; then
cleanup_files
exit 1
fi
# Check Docker installation
if ! format_output check_docker "Checking Docker installation"; then
cleanup_files
exit 1
fi
# Create Portainer directory and setup Portainer
if ! format_output create_portainer_directory "Creating Portainer data directory"; then
cleanup_files
exit 1
fi
if ! format_output setup_portainer "Setting up Portainer"; then
cleanup_files
exit 1
fi
format_output cleanup_files "Cleaning up temporary files"
# Print final message
echo -e "\nPortainer has been successfully installed!"
echo -e "You can access Portainer at: https://your-server-ip:9443"
echo -e "Please create your admin account on first login."
exit $success