From 2a5357e06081fa49145b203627dc75da07b1c43a Mon Sep 17 00:00:00 2001 From: Dillon <35014341+dljm@users.noreply.github.com> Date: Sat, 9 Dec 2023 13:59:59 -0500 Subject: [PATCH] task: Script renaming and variable quoting to work on windows and handle paths with spaces. Signed-off-by: Dillon <35014341+dljm@users.noreply.github.com> --- .github/ISSUE_TEMPLATE/bug_report.md | 19 +++++++---------- launcher | 24 ++++++++++----------- ob/cmd/{api:gen => api_gen} | 0 ob/cmd/bootstrap | 31 +++++++++++++--------------- ob/cmd/{debug:send => debug_send} | 0 ob/cmd/env | 4 +++- ob/cmd/{pkg:update => pkg_update} | 0 ob/cmd/{setup:dev => setup_dev} | 0 ob/cmd/ui_dev | 2 +- ob/cmd/utils | 19 +++++++++++++++++ 10 files changed, 57 insertions(+), 42 deletions(-) rename ob/cmd/{api:gen => api_gen} (100%) mode change 100755 => 100644 rename ob/cmd/{debug:send => debug_send} (100%) mode change 100755 => 100644 rename ob/cmd/{pkg:update => pkg_update} (100%) mode change 100755 => 100644 rename ob/cmd/{setup:dev => setup_dev} (100%) mode change 100755 => 100644 create mode 100644 ob/cmd/utils diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 98372c0..fee0f6b 100755 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -1,10 +1,9 @@ --- name: Bug report about: Create a report to help us improve -title: '[BUG] ' -labels: 'Type: Bug' +title: "[BUG] " +labels: "Type: Bug" assignees: jerlendds - --- **Bug Description:** @@ -13,10 +12,9 @@ A clear and concise description of what the bug is... **How to Reproduce:** -1. -2. -3. - +1. +2. +3. **Expected behavior:** @@ -24,15 +22,14 @@ A clear and concise description of what the bug is... **Screenshots & Logs:** -Please run `./launcher debug:send` to upload and get a public link to your log files. +Please run `./launcher debug_send` to upload and get a public link to your log files. This will help us with debugging and solving any issues. **Environment:** - - OS: Linux - - Browser: Firefox +- OS: Linux +- Browser: Firefox **Additional context:** ... - diff --git a/launcher b/launcher index ae63c5c..09ecd63 100755 --- a/launcher +++ b/launcher @@ -44,10 +44,10 @@ usage () { echo -e " $(c YsB)stop$(c): Stop the OSINTBuddy app (or a specific container ./launcher stop janus)." echo -e " $(c YsB)build$(c): Build the OSINTBuddy app (or a specific container ./launcher build ui)." echo -e " $(c YsB)restart$(c): Restart the app (or a specific container: ./launcher restart janus)." - echo -e " $(c YsB)api:gen$(c): Generate API client SDK from the backend OpenAPI spec; launch the UI outside of the container" - echo -e " $(c YsB)setup:dev$(c): Create python3 venv and install dev dependencies" + echo -e " $(c YsB)api_gen$(c): Generate API client SDK from the backend OpenAPI spec; launch the UI outside of the container" + echo -e " $(c YsB)setup_dev$(c): Create python3 venv and install dev dependencies" echo -e " $(c YsB)bootstrap$(c): Initialize and download dependencies and check for environment misconfigurations" - echo -e " $(c YsB)debug:send$(c): Upload all logs to https://paste.c-net.org for help with debugging" + echo -e " $(c YsB)debug_send$(c): Upload all logs to https://paste.c-net.org for help with debugging" echo -e " $(c YsB)cleanup$(c): Remove docker volumes." echo -e " $(c YsB)exec$(c): Execute commands for a container." echo -e " $(c YsB)migrate$(c): Generate a migration." @@ -55,7 +55,7 @@ usage () { echo -e " $(c YsB)ui$(c): Stop the UI container and launch the frontend locally." echo -e " $(c YsB)kill$(c): Kill containers; down the stack." echo -e " $(c YsB)containers$(c): List the names you can access the containers by" - echo -e " $(c YsB)pkg:update$(c): Update the osintbuddy package locally and in docker from the osintbuddy-plugins repo (used in dev)" + echo -e " $(c YsB)pkg_update$(c): Update the osintbuddy package locally and in docker from the osintbuddy-plugins repo (used in dev)" usage_containers exit 1 @@ -85,8 +85,8 @@ case "$OB_CMD" in logs) ./cmd/logs ;; - api:gen) - ./cmd/api:gen + api_gen) + ./cmd/api_gen ;; kill) ./cmd/downkill @@ -94,8 +94,8 @@ case "$OB_CMD" in ui) ./cmd/ui_dev ;; - debug:send) - ./cmd/debug:send + debug_send) + ./cmd/debug_send ;; cleanup) ./cmd/stop @@ -110,11 +110,11 @@ case "$OB_CMD" in migrate) ./cmd/migrate ;; - setup:dev) - ./cmd/setup:dev + setup_dev) + ./cmd/setup_dev ;; - pkg:update) - ./cmd/pkg:update + pkg_update) + ./cmd/pkg_update ;; ps) ./cmd/ps diff --git a/ob/cmd/api:gen b/ob/cmd/api_gen old mode 100755 new mode 100644 similarity index 100% rename from ob/cmd/api:gen rename to ob/cmd/api_gen diff --git a/ob/cmd/bootstrap b/ob/cmd/bootstrap index 14beca6..6afe977 100755 --- a/ob/cmd/bootstrap +++ b/ob/cmd/bootstrap @@ -90,30 +90,29 @@ check_prereqs() { python_min_version='3.11.0' python_rec_version='3.11.4' - # 0. TODO: Install windows and test git crlf config... - # (Please, someone else do this, I really don't want to install windows..) - if [[ $(grep -i Microsoft /proc/version) ]]; then + # Test git crlf config for windows devices + if [ $is_windows ]; then heading "Windows detected! Checking for environment issues..." prepare_windows fi - - if [ -z $docker_path ]; then + + if [ -z "$docker_path" ]; then install_docker fi - + # 1. docker daemon running? # we send stderr to /dev/null cause we don't care about warnings, # it usually complains about swap which does not matter - test=`$docker_path info 2> /dev/null` + test=`"$docker_path" info 2> /dev/null` if [[ $? -ne 0 ]] ; then error "Cannot connect to the docker daemon - verify it is running and you have access" exit 1 fi # 2. running recommended docker version - test=($($docker_path --version)) # Get docker version string + test=($("$docker_path" --version)) # Get docker version string test=${test[2]//,/} # Get version alone and strip comma if exists - + # At least minimum docker version if compare_version "${docker_min_version}" "${test}"; then echo "ERROR: Docker version ${test} not supported, please upgrade to at least ${docker_min_version}, or recommended ${docker_rec_version}" @@ -122,19 +121,17 @@ check_prereqs() { # 3. has node and running recommended node version - if [ -z "$(which $node)" ]; then + if [ -z "$node" ]; then warning "Node environment not detected! We recommend installing Node 18.18.2 for this project." warning "Some ./launcher commands may not work without a node environment." heading "Attempting to continue without Node..." fi - test=($($node --version)) + test=($("$node" --version)) test=${test[0]//v/} # Get version alone and strip the prefixed v - - if compare_version "${node_min_version}" "${test}"; then - echo "WARNING: Node version ${test} not supported, please upgrade to at least ${node_min_version}, or recommended ${node_rec_version}" + warning "WARNING: Node version ${test} not supported, please upgrade to at least ${node_min_version}, or recommended ${node_rec_version}" fi # Recommend best Node version @@ -143,7 +140,7 @@ check_prereqs() { fi # 4. running recommended Python version - test=($($python3 --version)) + test=($("$python3" --version)) test=${test[1]///} # Get version alone and strip the prefixed v if compare_version "${python_min_version}" "${test}"; then @@ -180,7 +177,7 @@ check_prereqs() { esac # 4. running recommended git version - test=($($git_path --version)) # Get git version string + test=($("$git_path" --version)) # Get git version string test=${test[2]//,/} # Get version alone and strip comma if exists # At least minimum version @@ -216,7 +213,7 @@ setup_python_env() { setup_ui_env() { cd ../frontend/ && yarn && yarn install:hooks - info "Generate the UI API client with: ./launcher api:gen" + info "Generate the UI API client with: ./launcher api_gen" cd "$OB_DIR" } diff --git a/ob/cmd/debug:send b/ob/cmd/debug_send old mode 100755 new mode 100644 similarity index 100% rename from ob/cmd/debug:send rename to ob/cmd/debug_send diff --git a/ob/cmd/env b/ob/cmd/env index 8ce86ff..d01abb7 100755 --- a/ob/cmd/env +++ b/ob/cmd/env @@ -1,11 +1,13 @@ #!/usr/bin/bash # used by ./ob/cmd/* scripts ran by this ./launcher . ./cmd/_colors +. ./cmd/utils export node=`which node` export python3=`which python` export docker_path=`which docker` export git_path=`which git` +export is_windows=get_is_windows # https://docs.docker.com/compose/environment-variables/envvars/ @@ -16,7 +18,7 @@ export COMPOSE_FILE="$(pwd)/alpha-compose.yml" export OB_COMPOSE_OVERRIDE="$(pwd)/alpha-compose.override.yml" ob_compose() { - $docker_path compose -f $COMPOSE_FILE -f $OB_COMPOSE_OVERRIDE "$@" + "$docker_path" compose -f $COMPOSE_FILE -f $OB_COMPOSE_OVERRIDE "$@" } # Colored logs... diff --git a/ob/cmd/pkg:update b/ob/cmd/pkg_update old mode 100755 new mode 100644 similarity index 100% rename from ob/cmd/pkg:update rename to ob/cmd/pkg_update diff --git a/ob/cmd/setup:dev b/ob/cmd/setup_dev old mode 100755 new mode 100644 similarity index 100% rename from ob/cmd/setup:dev rename to ob/cmd/setup_dev diff --git a/ob/cmd/ui_dev b/ob/cmd/ui_dev index e76e5f9..2b4e001 100755 --- a/ob/cmd/ui_dev +++ b/ob/cmd/ui_dev @@ -3,7 +3,7 @@ run_uidev() { unset ERR - cmd/api:gen || ERR=$? + cmd/api_gen || ERR=$? if [[ $ERR > 0 ]]; then error "We ran into an error generating the frontends API client. Is the backend running?" fi diff --git a/ob/cmd/utils b/ob/cmd/utils new file mode 100644 index 0000000..c806ef6 --- /dev/null +++ b/ob/cmd/utils @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +# Helpful utility functions used by various scripts + +function get_is_windows() { + # Check if the OSTYPE variable is null or unset + if [ -z "$OSTYPE" ]; then + return 1 # Not Windows + else + # Check the operating system to determine if it is Windows + case "$OSTYPE" in + msys*|cygwin*|mingw*|win32*) + return 0 # Windows + ;; + *) + return 1 # Not Windows + ;; + esac + fi +}