You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

92 lines
3.1 KiB

#!/bin/bash
echo "####################################################################"
echo "# docker_portainer_setup_script #"
echo "# Dennis Buchhorn - bucde@b-eit.de #"
echo "####################################################################"
echo "# WARNING: password is plain text input! #"
echo "# #"
echo "# Config will be saved in 'config' file. #"
echo "# (everything in plain text, even the password) #"
#echo "# #"
echo "####################################################################"
echo ""
DATE=$(date +'%y%m%d%H%M%S')
CONFIG_EXISTS="false"
USE_EXISTING_CONFIG=""
DELETE_CONFIG=""
PORTAINER_PROJECT_NAME="portainer_${DATE}"
PORTAINER_PROJECT_NAME_SUFFIX=""
PORTAINER_CONTAINER_NAME="${PORTAINER_PROJECT_NAME}"
PORTAINER_VERSION=""
PORTAINER_HOST_IP_ADDRESS=""
PORTAINER_HOST_PORT=""
read -p "Enter portainer project name suffix (leave empty for none): " PORTAINER_PROJECT_NAME_SUFFIX
if [ -n "$PORTAINER_PROJECT_NAME_SUFFIX" ]; then
PORTAINER_PROJECT_NAME="${PORTAINER_PROJECT_NAME}_${PORTAINER_PROJECT_NAME_SUFFIX}"
PORTAINER_CONTAINER_NAME="${PORTAINER_CONTAINER_NAME}_${PORTAINER_PROJECT_NAME_SUFFIX}"
fi
rm -f .env
touch .env
echo "COMPOSE_PROJECT_NAME="$PORTAINER_PROJECT_NAME >> .env
echo "PORTAINER_CONTAINER_NAME="$PORTAINER_CONTAINER_NAME >> .env
if [ -f "config" ]; then
CONFIG_EXISTS="true"
read -p "Config file 'config' already exists! Would you like to use this? (y/n)" USE_EXISTING_CONFIG
fi
if [ $CONFIG_EXISTS == "false" ] || [ $USE_EXISTING_CONFIG == "n" ]; then
read -p "Enter portainer version which should be used: " PORTAINER_VERSION
read -p "Enter host (vm) ip address on which portainer should be accessible: " PORTAINER_HOST_IP_ADDRESS
read -p "Enter host (vm) port on which portainer should be accessible: " PORTAINER_HOST_PORT
rm -f config
touch config
echo "PORTAINER_VERSION="$PORTAINER_VERSION >> config
echo "PORTAINER_HOST_IP_ADDRESS="$PORTAINER_HOST_IP_ADDRESS >> config
echo "PORTAINER_HOST_PORT="$PORTAINER_HOST_PORT >> config
echo "Config file 'config' created!"
else
echo "Use existing config file 'config'!"
while read line; do
if [[ $line == *"PORTAINER_HOST_IP_ADDRESS="* ]]; then
PORTAINER_HOST_IP_ADDRESS=$(echo $line | cut -c 27-)
elif [[ $line == *"PORTAINER_HOST_PORT="* ]]; then
PORTAINER_HOST_PORT=$(echo $line | cut -c 21-)
fi
done < "config"
fi
cat "config" >> ".env"
read -p "Should the config file 'config' be deleted after creating the container? (y/n)" DELETE_CONFIG
docker-compose up -d
echo -n "Wait until portainer is ready ..."
while [[ "$(curl -fLs -w ''%{http_code}'' $PORTAINER_HOST_IP_ADDRESS:$PORTAINER_HOST_PORT -o /dev/null)" != "200" ]] ; do
echo -n "."
sleep 1
done
echo -e "\nPortainer is ready!"
if [ $DELETE_CONFIG == "y" ]; then
rm -f config
echo "Config file 'config' deleted!"
fi
rm -f .env
echo "Done!"