Skip to content
Snippets Groups Projects
Commit 0d32883d authored by Bartek Wrona's avatar Bartek Wrona
Browse files

issue #251 - defined script to launch clive-TUI.

parent 37cbd702
No related branches found
No related tags found
2 merge requests!455V1.27.5.15 release,!442issue #251 - defined script to launch clive-TUI.
...@@ -35,6 +35,7 @@ share/python-wheels/ ...@@ -35,6 +35,7 @@ share/python-wheels/
.installed.cfg .installed.cfg
*.egg *.egg
MANIFEST MANIFEST
scripts/start_clive.sh
# PyInstaller # PyInstaller
# Usually these files are written by a python script from a template # Usually these files are written by a python script from a template
......
#!/bin/bash
set -euo pipefail
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 || exit 1; pwd -P )"
IMAGE_NAME=${1:?"Missing arg #1 to specify built docker image name"}
ESCAPED_IMAGE_NAME=${IMAGE_NAME//\//\\/}
cp -f "${SCRIPTPATH}/../start_clive.sh.template" "${SCRIPTPATH}/../start_clive.sh"
sed -i -e "s/<IMG_PLACEHOLDER>/${ESCAPED_IMAGE_NAME}/g" "${SCRIPTPATH}/../start_clive.sh"
#!/bin/bash
set -euo pipefail
# Script responsible for starting a docker container built for given image (optionally specified at command line).
print_help () {
echo "Usage: $0 [<docker_img>] [OPTION[=VALUE]]... [<clive_option>]..."
echo
echo "Allows to start clive application in TUI mode."
echo "OPTIONS:"
echo " --data-dir=DIRECTORY_PATH Points a clive data directory to store profile data. Defaults to ${HOME}/.clive directory"
echo " --docker-option=OPTION Allows to specify additional docker option, to be passed to underlying docker run spawn."
echo " --help Display this help screen and exit"
echo
}
DOCKER_ARGS=()
CLIVE_ARGS=()
IMAGE_NAME="<IMG_PLACEHOLDER>"
CLIVE_DATA_DIR="${HOME}/.clive"
add_docker_arg() {
local arg="$1"
DOCKER_ARGS+=("$arg")
}
add_clive_arg() {
local arg="$1"
CLIVE_ARGS+=("$arg")
}
while [ $# -gt 0 ]; do
case "$1" in
--docker-option=*)
options_string="${1#*=}"
IFS=" " read -ra options <<< "$options_string"
for option in "${options[@]}"; do
add_docker_arg "$option"
done
;;
--docker-option)
shift
options_string="${1}"
IFS=" " read -ra options <<< "$options_string"
for option in "${options[@]}"; do
add_docker_arg "$option"
done
;;
--data-dir=*)
CLIVE_DATA_DIR="${1#*=}"
;;
--data-dir)
shift
CLIVE_DATA_DIR="${1}"
;;
--help)
print_help
exit 0
;;
-*)
add_clive_arg "$1"
;;
*)
IMAGE_NAME="${1}"
echo "Using image name: $IMAGE_NAME"
;;
esac
shift
done
# Collect remaining command line args to pass to the container to run
CMD_ARGS=("$@")
CMD_ARGS+=("${CLIVE_ARGS[@]}")
if ! command -v docker &> /dev/null
then
echo "Error: Missing docker tools"
echo "Please consult documentation describing docker installation steps: https://docs.docker.com/engine/install/ubuntu/"
exit 1
fi
if [ -z "${CLIVE_DATA_DIR}" ]
then
echo "Error: Missing --data-dir argument"
exit 2
fi
# try to create a profile directory, to correctly resolve realpath
mkdir -p "${CLIVE_DATA_DIR}"
chmod -R 700 "${CLIVE_DATA_DIR}"
CLIVE_DATA_ABS_DIR=$(realpath "${CLIVE_DATA_DIR}")
# Supplement docker args by volume mapping
add_docker_arg "--volume"
add_docker_arg "${CLIVE_DATA_ABS_DIR}:/clive/.clive/"
CLIVE_DATA_LOCATION_DIR=$(realpath "${CLIVE_DATA_DIR}/../")
HOME_ABS_DIR=$(realpath "${HOME}")
if [[ "${CLIVE_DATA_LOCATION_DIR}/" = ${HOME_ABS_DIR}/* ]]
then
# if specified location of clive dir is inside user's home, lets add additional volume mapping to make it accessible to internally spawned clive
add_docker_arg "--volume"
add_docker_arg "${CLIVE_DATA_LOCATION_DIR}:${CLIVE_DATA_LOCATION_DIR}"
fi
docker run --detach-keys='ctrl-@,ctrl-q' --rm -it -e HIVED_UID="$(id -u)" --stop-timeout=180 "${DOCKER_ARGS[@]}" "${IMAGE_NAME}" "${CMD_ARGS[@]}"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment