alessandro trinca tornidor commited on
Commit ·
f2a3b75
1
Parent(s): 6a4a012
ci: add an installation script (python required)
Browse files- scripts/install.sh +134 -0
scripts/install.sh
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
GITHUB_USER="trincadev"
|
| 4 |
+
GITHUB_REPO="my_ghost_writer"
|
| 5 |
+
|
| 6 |
+
export API_MODE=TRUE
|
| 7 |
+
export ALLOWED_ORIGIN=http://localhost:7860,http://localhost:8000
|
| 8 |
+
python_executable=$(which python3)
|
| 9 |
+
ORIGIN_PYTHON=SYSTEM
|
| 10 |
+
VERSION="0.1.0"
|
| 11 |
+
VIRTUALENV_FOLDER="venv_mgw"
|
| 12 |
+
ROOT_FOLDER=$0
|
| 13 |
+
REPOSITORY_URL="https://github.com/${GITHUB_USER}/${GITHUB_REPO}.git"
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
display_help() {
|
| 17 |
+
echo
|
| 18 |
+
echo "Script version $VERSION"
|
| 19 |
+
echo "A tool for installing and/or executing My Ghost Writer (${REPOSITORY_URL})."
|
| 20 |
+
echo 'Usage: install.sh <option>'
|
| 21 |
+
echo 'Options:'
|
| 22 |
+
echo ' -h --help Show help'
|
| 23 |
+
echo ' -i --only-install Only install the python package and its dependencies (optional, without this option the script will install the package and run it)'
|
| 24 |
+
echo " -p --python-executable <python_executable> Specifies the python executable to use (optional, without this option the default python3 executable (${python_executable}) will be used)"
|
| 25 |
+
echo " -o --allowed-origin <allowed_origin> Specifies the allowed origin for the webserver (optional, without this option the default value (${ALLOWED_ORIGIN}) will be used)"
|
| 26 |
+
echo ' -V --package-version <package> Specifies package version to install (optional, without this option the latest version will be installed)'
|
| 27 |
+
echo
|
| 28 |
+
echo 'Submit a GitHub issue if you are encountering problems or want to suggest new features.'
|
| 29 |
+
echo
|
| 30 |
+
exit 1
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
while [[ $# -gt 0 ]]
|
| 35 |
+
do
|
| 36 |
+
key="$1"
|
| 37 |
+
|
| 38 |
+
case $key in
|
| 39 |
+
-o|--allowed-origin)
|
| 40 |
+
export ALLOWED_ORIGIN="$2"
|
| 41 |
+
shift # past argument
|
| 42 |
+
shift # past value
|
| 43 |
+
;;
|
| 44 |
+
-h|--help)
|
| 45 |
+
help=YES
|
| 46 |
+
shift # past argument
|
| 47 |
+
;;
|
| 48 |
+
-V|--package-version)
|
| 49 |
+
package_version="$2"
|
| 50 |
+
echo "package_version: '${package_version}'"
|
| 51 |
+
shift # past argument
|
| 52 |
+
shift # past value
|
| 53 |
+
;;
|
| 54 |
+
-p|--python-executable)
|
| 55 |
+
python_executable="$2"
|
| 56 |
+
ORIGIN_PYTHON=CUSTOM
|
| 57 |
+
echo "# custom python_executable: '${python_executable}'"
|
| 58 |
+
${python_executable} --version
|
| 59 |
+
shift # past argument
|
| 60 |
+
shift # past value
|
| 61 |
+
;;
|
| 62 |
+
-i|--only-install)
|
| 63 |
+
only_install=YES
|
| 64 |
+
shift # past argument
|
| 65 |
+
;;
|
| 66 |
+
*) echo "Unknown parameter passed: '$1'";
|
| 67 |
+
display_help
|
| 68 |
+
exit 1
|
| 69 |
+
;;
|
| 70 |
+
esac
|
| 71 |
+
done
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
installer(){
|
| 75 |
+
echo -e "\n# using python executable ${python_executable} (python origin is ${ORIGIN_PYTHON}) with version:"
|
| 76 |
+
${python_executable} --version
|
| 77 |
+
|
| 78 |
+
echo -e "\n# Installing virtualenv:"
|
| 79 |
+
${python_executable} -m venv ${VIRTUALENV_FOLDER}
|
| 80 |
+
|
| 81 |
+
echo -e "\n# Activating venv_mgw:"
|
| 82 |
+
source ${VIRTUALENV_FOLDER}/bin/activate
|
| 83 |
+
|
| 84 |
+
echo -e "\n# virtualenv folder:"
|
| 85 |
+
echo ${VIRTUAL_ENV}
|
| 86 |
+
|
| 87 |
+
python -m pip install --upgrade pip
|
| 88 |
+
|
| 89 |
+
echo -e "\n# virtualenv python version:"
|
| 90 |
+
which python
|
| 91 |
+
python --version
|
| 92 |
+
|
| 93 |
+
echo -e "\n# installing my-ghost-writer"
|
| 94 |
+
if [ -z ${package_version} ]; then
|
| 95 |
+
echo -e "\n# Installing latest version of my-ghost-writer..."
|
| 96 |
+
python -m pip install my-ghost-writer
|
| 97 |
+
else
|
| 98 |
+
echo -e "\n# Installing version my-ghost-writer==${package_version}..."
|
| 99 |
+
python -m pip install my-ghost-writer==${package_version}
|
| 100 |
+
fi
|
| 101 |
+
|
| 102 |
+
MGW_VERSION=$(python -m pip freeze|grep -E "my_ghost_writer|my-ghost-writer"|cut -d'=' -f3)
|
| 103 |
+
# gitlab prefix: https://gitlab.com/{GITLAB_USER}/{GITLAB_REPO}/-/raw
|
| 104 |
+
URL_REPOSITORY_PREFIX="https://raw.githubusercontent.com/${GITHUB_USER}/${GITHUB_REPO}/refs/tags/${MGW_VERSION}"
|
| 105 |
+
python -m pip install my-ghost-writer -r "${URL_REPOSITORY_PREFIX}/requirements-webserver.txt"
|
| 106 |
+
echo -e "\n# installed my-ghost-writer version: ${MGW_VERSION}!"
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
runner(){
|
| 110 |
+
echo -e "\n# running my-ghost-writer, API_MODE: ${API_MODE}, version: ${MGW_VERSION}..."
|
| 111 |
+
python -m my_ghost_writer.app
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
if [ "$help" = "YES" ]; then
|
| 115 |
+
display_help
|
| 116 |
+
exit 0
|
| 117 |
+
fi
|
| 118 |
+
|
| 119 |
+
if [ -z "${only_install}" ]; then
|
| 120 |
+
installer
|
| 121 |
+
echo -e "\n# my-ghost-writer installed successfully..."
|
| 122 |
+
runner
|
| 123 |
+
exit 0
|
| 124 |
+
fi
|
| 125 |
+
|
| 126 |
+
if [ "$only_install" = "YES" ]; then
|
| 127 |
+
installer
|
| 128 |
+
echo -e "\n# my-ghost-writer installed successfully, exit!"
|
| 129 |
+
exit 0
|
| 130 |
+
fi
|
| 131 |
+
|
| 132 |
+
echo -e "\n# Invalid option(s)."
|
| 133 |
+
display_help
|
| 134 |
+
exit 1
|