File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -46,6 +46,11 @@ get_version() {
4646 fi
4747}
4848
49+ # Function to check if a directory is writable
50+ is_writable () {
51+ [ -d " $1 " ] && [ -w " $1 " ]
52+ }
53+
4954# Function to download and install the CLI tool
5055install_cli () {
5156 DOWNLOAD_URL=" https://github.com/OpsLevel/cli/releases/download/${VERSION} /opslevel-${OS} -${ARCH} .tar.gz"
@@ -64,9 +69,26 @@ install_cli() {
6469 echo " Extracting the OpsLevel CLI..."
6570 tar -xzf " $TMP_DIR /opslevel.tar.gz" -C " $TMP_DIR "
6671
67- echo " Installing the OpsLevel CLI to /usr/local/bin ..."
68- sudo mv " $TMP_DIR /opslevel" /usr/local/bin/
6972
73+
74+ # Search for a writable directory in the PATH
75+ TARGET_DIR=" "
76+ for dir in $( echo " $PATH " | tr ' :' ' \n' ) ; do
77+ if is_writable " $dir " ; then
78+ TARGET_DIR=" $dir "
79+ break
80+ fi
81+ done
82+
83+ # If no writable directory is found, exit
84+ if [ -z " $TARGET_DIR " ]; then
85+ echo " Installation failed. User has no permissions to any directory on PATH"
86+ exit 1
87+ else
88+ echo " Installing the OpsLevel CLI to '$TARGET_DIR ' ..."
89+ fi
90+
91+ mv " $TMP_DIR /opslevel" " $TARGET_DIR "
7092 if [ $? -ne 0 ]; then
7193 echo " Installation failed."
7294 exit 1
You can’t perform that action at this time.
0 commit comments