|
#!/bin/bash
|
|
|
|
echo "####################################################################"
|
|
echo "# docker_drone_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=""
|
|
|
|
DRONE_PROJECT_NAME="drone_${DATE}"
|
|
DRONE_PROJECT_NAME_SUFFIX=""
|
|
DRONE_CONTAINER_NAME="${DRONE_PROJECT_NAME}_core"
|
|
DRONE_VERSION=""
|
|
DRONE_HOST_IP_ADDRESS=""
|
|
DRONE_HOST_PORT=""
|
|
DRONE_GITEA_SERVER=""
|
|
DRONE_GITEA_CLIENT_ID=""
|
|
DRONE_GITEA_CLIENT_SECRET=""
|
|
DRONE_RPC_SECRET=""
|
|
|
|
read -p "Enter drone project name suffix (leave empty for none): " DRONE_PROJECT_NAME_SUFFIX
|
|
|
|
if [ -n "$DRONE_PROJECT_NAME_SUFFIX" ]; then
|
|
DRONE_PROJECT_NAME="${DRONE_PROJECT_NAME}_${DRONE_PROJECT_NAME_SUFFIX}"
|
|
DRONE_CONTAINER_NAME="${DRONE_CONTAINER_NAME}_${DRONE_PROJECT_NAME_SUFFIX}"
|
|
fi
|
|
|
|
rm -f .env
|
|
touch .env
|
|
echo "COMPOSE_PROJECT_NAME="$DRONE_PROJECT_NAME >> .env
|
|
echo "DRONE_CONTAINER_NAME="$DRONE_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 drone version which should be used: " DRONE_VERSION
|
|
read -p "Enter host (vm) ip address on which drone should be accessible: " DRONE_HOST_IP_ADDRESS
|
|
read -p "Enter host (vm) port on which drone should be accessible: " DRONE_HOST_PORT
|
|
read -p "Enter gitea host name/ip (http(s):// is important!): " DRONE_GITEA_SERVER
|
|
read -p "Enter gitea oauth client id: " DRONE_GITEA_CLIENT_ID
|
|
read -p "Enter gitea oauth client secret: " DRONE_GITEA_CLIENT_SECRET
|
|
|
|
DRONE_RPC_SECRET=$(openssl rand -hex 16)
|
|
|
|
echo "DRONE_RPC_SECRET is "$DRONE_RPC_SECRET
|
|
|
|
rm -f config
|
|
touch config
|
|
echo "DRONE_VERSION="$DRONE_VERSION >> config
|
|
echo "DRONE_HOST_IP_ADDRESS="$DRONE_HOST_IP_ADDRESS >> config
|
|
echo "DRONE_HOST_PORT="$DRONE_HOST_WEB_PORT >> config
|
|
echo "DRONE_GITEA_SERVER="$DRONE_GITEA_SERVER >> config
|
|
echo "DRONE_GITEA_CLIENT_ID="$DRONE_GITEA_CLIENT_ID >> config
|
|
echo "DRONE_GITEA_CLIENT_SECRET="$DRONE_GITEA_CLIENT_SECRET >> config
|
|
echo "DRONE_RPC_SECRET="$DRONE_RPC_SECRET >> config
|
|
|
|
echo "Config file 'config' created!"
|
|
else
|
|
echo "Use existing config file 'config'!"
|
|
|
|
while read line; do
|
|
if [[ $line == *"DRONE_HOST_IP_ADDRESS="* ]]; then
|
|
DRONE_HOST_IP_ADDRESS=$(echo $line | cut -c 23-)
|
|
elif [[ $line == *"DRONE_HOST_WEB_PORT="* ]]; then
|
|
DRONE_HOST_WEB_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 drone is ready ..."
|
|
|
|
#while [[ "$(curl -fLs -w ''%{http_code}'' $GITEA_HOST_IP_ADDRESS:$GITEA_HOST_WEB_PORT -o /dev/null)" != "200" ]] ; do
|
|
#echo -n "."
|
|
#sleep 1
|
|
#done
|
|
|
|
echo -e "\nDrone is ready!"
|
|
|
|
if [ $DELETE_CONFIG == "y" ]; then
|
|
rm -f config
|
|
|
|
echo "Config file 'config' deleted!"
|
|
fi
|
|
|
|
rm -f .env
|
|
|
|
echo "Done!"
|