changeset 921:02b31a76e2c4

get DEST from command line
author Jeff Hammel <k0scist@gmail.com>
date Sun, 02 Jun 2024 16:35:01 -0700
parents 531a7200649f
children 74dc16f074be
files bin/install-k0s-web.sh
diffstat 1 files changed, 29 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/bin/install-k0s-web.sh	Sun Jun 02 15:18:51 2024 -0700
+++ b/bin/install-k0s-web.sh	Sun Jun 02 16:35:01 2024 -0700
@@ -1,11 +1,36 @@
 #!/usr/bin/env bash
 
-set -exuo pipefail
+# This script installs the k0s.org web server in a virtual environment
+# in the directory specified by the first argument.
+
+# Example usage:
+# install-k0s-web.sh "${HOME}"/web2
+
+set -euo pipefail
 
 PYTHON_VERSION="3.7"
 
-# TODO: take this from "$1"
-DEST="${HOME}/web3"
+# Get DEST from "$1"
+# DEST="${HOME}/web3"
+if [ "$#" -ne 1 ]; then
+    echo "Usage: $0 <destination>"
+    exit 1
+fi
+DEST="$1"
+if [ "${DEST:0:1}" != "/" ]
+then
+    echo "Destination must be an absolute path"
+    exit 1
+fi
+beginswith() { case $2 in "$1"*) true;; *) false;; esac; }
+if ! beginswith "${HOME}" "${DEST}"
+then
+    echo "Destination must be under your home directory"
+    exit 1
+fi
+
+set -x
+
 rm -rf "${DEST}"
 
 # Make a directory for k0s.org web
@@ -29,6 +54,7 @@
 bin/pip install -r "${HOME}"/web/requirements.txt
 
 # echo command to run the server
+set +x
 command="sudo ${DEST}/bin/paster serve /home/jhammel/web/paster-wsgintegrate.ini"
 echo "Run with:"
 echo "${command}"