2023-10-23 10:26:19 +00:00
#!/bin/bash
2023-11-17 06:21:54 +00:00
BRANCH = master
2023-10-23 10:26:19 +00:00
SCRIPT_DIR = $PWD
PLANE_INSTALL_DIR = $PWD /plane-app
2024-01-17 13:33:57 +00:00
export APP_RELEASE = $BRANCH
export DOCKERHUB_USER = makeplane
export PULL_POLICY = always
USE_GLOBAL_IMAGES = 1
2023-10-23 10:26:19 +00:00
2024-01-17 13:33:57 +00:00
RED = '\033[0;31m'
YELLOW = '\033[1;33m'
GREEN = '\033[0;32m'
NC = '\033[0m' # No Color
function buildLocalImage( ) {
if [ " $1 " = = "--force-build" ] ; then
DO_BUILD = "1"
elif [ " $1 " = = "--skip-build" ] ; then
DO_BUILD = "2"
else
printf "\n" >& 2
printf " ${ YELLOW } You are on ${ ARCH } cpu architecture. ${ NC } \n " >& 2
printf " ${ YELLOW } Since the prebuilt ${ ARCH } compatible docker images are not available for, we will be running the docker build on this system. ${ NC } \n " >& 2
printf " ${ YELLOW } This might take ${ YELLOW } 5-30 min based on your system's hardware configuration. \n ${ NC } \n " >& 2
printf "\n" >& 2
printf " ${ GREEN } Select an option to proceed: ${ NC } \n " >& 2
printf " 1) Build Fresh Images \n" >& 2
printf " 2) Skip Building Images \n" >& 2
printf " 3) Exit \n" >& 2
printf "\n" >& 2
read -p "Select Option [1]: " DO_BUILD
until [ [ -z " $DO_BUILD " || " $DO_BUILD " = ~ ^[ 1-3] $ ] ] ; do
echo " $DO_BUILD : invalid selection. " >& 2
read -p "Select Option [1]: " DO_BUILD
done
echo "" >& 2
fi
if [ " $DO_BUILD " = = "1" ] || [ " $DO_BUILD " = = "" ] ;
then
REPO = https://github.com/makeplane/plane.git
CURR_DIR = $PWD
PLANE_TEMP_CODE_DIR = $( mktemp -d)
git clone $REPO $PLANE_TEMP_CODE_DIR --branch $BRANCH --single-branch
cp $PLANE_TEMP_CODE_DIR /deploy/selfhost/build.yml $PLANE_TEMP_CODE_DIR /build.yml
cd $PLANE_TEMP_CODE_DIR
if [ " $BRANCH " = = "master" ] ;
then
APP_RELEASE = latest
fi
docker compose -f build.yml build --no-cache >& 2
# cd $CURR_DIR
# rm -rf $PLANE_TEMP_CODE_DIR
echo "build_completed"
elif [ " $DO_BUILD " = = "2" ] ;
then
printf " ${ YELLOW } Build action skipped by you in lieu of using existing images. ${ NC } \n " >& 2
echo "build_skipped"
elif [ " $DO_BUILD " = = "3" ] ;
then
echo "build_exited"
else
printf "INVALID OPTION SUPPLIED" >& 2
fi
}
function install( ) {
echo "Installing Plane.........."
2023-10-23 10:26:19 +00:00
download
}
2024-01-17 13:33:57 +00:00
function download( ) {
2023-10-23 10:26:19 +00:00
cd $SCRIPT_DIR
TS = $( date +%s)
if [ -f " $PLANE_INSTALL_DIR /docker-compose.yaml " ]
then
mv $PLANE_INSTALL_DIR /docker-compose.yaml $PLANE_INSTALL_DIR /archive/$TS .docker-compose.yaml
fi
curl -H 'Cache-Control: no-cache, no-store' -s -o $PLANE_INSTALL_DIR /docker-compose.yaml https://raw.githubusercontent.com/makeplane/plane/$BRANCH /deploy/selfhost/docker-compose.yml?$( date +%s)
curl -H 'Cache-Control: no-cache, no-store' -s -o $PLANE_INSTALL_DIR /variables-upgrade.env https://raw.githubusercontent.com/makeplane/plane/$BRANCH /deploy/selfhost/variables.env?$( date +%s)
if [ -f " $PLANE_INSTALL_DIR /.env " ] ;
then
cp $PLANE_INSTALL_DIR /.env $PLANE_INSTALL_DIR /archive/$TS .env
else
mv $PLANE_INSTALL_DIR /variables-upgrade.env $PLANE_INSTALL_DIR /.env
fi
2023-11-17 06:21:54 +00:00
if [ " $BRANCH " != "master" ] ;
then
cp $PLANE_INSTALL_DIR /docker-compose.yaml $PLANE_INSTALL_DIR /temp.yaml
2023-11-29 09:28:31 +00:00
sed -e 's@${APP_RELEASE:-latest}@' " $BRANCH " '@g' \
2023-11-17 06:21:54 +00:00
$PLANE_INSTALL_DIR /temp.yaml > $PLANE_INSTALL_DIR /docker-compose.yaml
2023-10-23 10:26:19 +00:00
2023-11-17 06:21:54 +00:00
rm $PLANE_INSTALL_DIR /temp.yaml
fi
2024-01-17 13:33:57 +00:00
if [ $USE_GLOBAL_IMAGES = = 0 ] ; then
local res = $( buildLocalImage)
# echo $res
if [ " $res " = = "build_exited" ] ;
then
echo
echo "Install action cancelled by you. Exiting now."
echo
exit 0
fi
else
docker compose -f $PLANE_INSTALL_DIR /docker-compose.yaml pull
fi
2023-11-17 06:21:54 +00:00
2023-10-23 10:26:19 +00:00
echo ""
echo "Latest version is now available for you to use"
echo ""
2023-12-18 06:47:15 +00:00
echo "In case of Upgrade, your new setting file is available as 'variables-upgrade.env'. Please compare and set the required values in '.env 'file."
2023-10-23 10:26:19 +00:00
echo ""
}
2024-01-17 13:33:57 +00:00
function startServices( ) {
2023-10-23 10:26:19 +00:00
cd $PLANE_INSTALL_DIR
2024-01-17 13:33:57 +00:00
docker compose up -d --quiet-pull
2023-10-23 10:26:19 +00:00
cd $SCRIPT_DIR
}
2024-01-17 13:33:57 +00:00
function stopServices( ) {
2023-10-23 10:26:19 +00:00
cd $PLANE_INSTALL_DIR
docker compose down
cd $SCRIPT_DIR
}
2024-01-17 13:33:57 +00:00
function restartServices( ) {
2023-10-23 10:26:19 +00:00
cd $PLANE_INSTALL_DIR
docker compose restart
cd $SCRIPT_DIR
}
2024-01-17 13:33:57 +00:00
function upgrade( ) {
2023-10-23 10:26:19 +00:00
echo "***** STOPPING SERVICES ****"
stopServices
echo
echo "***** DOWNLOADING LATEST VERSION ****"
download
echo "***** PLEASE VALIDATE AND START SERVICES ****"
}
2024-01-17 13:33:57 +00:00
function askForAction( ) {
2023-10-23 10:26:19 +00:00
echo
echo "Select a Action you want to perform:"
2024-01-17 13:33:57 +00:00
echo " 1) Install ( ${ ARCH } ) "
2023-10-23 10:26:19 +00:00
echo " 2) Start"
echo " 3) Stop"
echo " 4) Restart"
echo " 5) Upgrade"
echo " 6) Exit"
echo
read -p "Action [2]: " ACTION
until [ [ -z " $ACTION " || " $ACTION " = ~ ^[ 1-6] $ ] ] ; do
echo " $ACTION : invalid selection. "
read -p "Action [2]: " ACTION
done
echo
if [ " $ACTION " = = "1" ]
then
install
askForAction
elif [ " $ACTION " = = "2" ] || [ " $ACTION " = = "" ]
then
startServices
askForAction
elif [ " $ACTION " = = "3" ]
then
stopServices
askForAction
elif [ " $ACTION " = = "4" ]
then
restartServices
askForAction
elif [ " $ACTION " = = "5" ]
then
upgrade
askForAction
elif [ " $ACTION " = = "6" ]
then
exit 0
else
echo "INVALID ACTION SUPPLIED"
fi
}
2024-01-17 13:33:57 +00:00
# CPU ARCHITECHTURE BASED SETTINGS
ARCH = $( uname -m)
if [ $ARCH = = "amd64" ] || [ $ARCH = = "x86_64" ] ;
then
USE_GLOBAL_IMAGES = 1
DOCKERHUB_USER = makeplane
PULL_POLICY = always
else
USE_GLOBAL_IMAGES = 0
DOCKERHUB_USER = myplane
PULL_POLICY = never
fi
# REMOVE SPECIAL CHARACTERS FROM BRANCH NAME
2023-11-17 06:21:54 +00:00
if [ " $BRANCH " != "master" ] ;
then
PLANE_INSTALL_DIR = $PWD /plane-app-$( echo $BRANCH | sed -r 's@(\/|" "|\.)@-@g' )
fi
mkdir -p $PLANE_INSTALL_DIR /archive
2023-10-23 10:26:19 +00:00
askForAction