Skip to content

Commit

Permalink
avoiding sudo (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
emanuel-quix authored May 21, 2024
1 parent 50ae13e commit 2a1c06b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 22 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,27 @@ To install the Quix CLI, users have multiple methods depending on their operatin
- **Install latest version:**

```bash
curl -fsSL https://github.com/quixio/quix-cli/raw/main/install.sh | sudo bash
curl -fsSL https://github.com/quixio/quix-cli/raw/main/install.sh | bash
```

- **Install with explicit version:**

```bash
curl -fsSL https://github.com/quixio/quix-cli/raw/main/install.sh | sudo bash -s -- -v={version}
curl -fsSL https://github.com/quixio/quix-cli/raw/main/install.sh | bash -s -- -v={version}
```

### For Linux:

- **Install latest version:**

```bash
curl -fsSL https://github.com/quixio/quix-cli/raw/main/install.sh | sudo bash
curl -fsSL https://github.com/quixio/quix-cli/raw/main/install.sh | bash
```

- **Install with explicit version:**

```bash
curl -fsSL https://github.com/quixio/quix-cli/raw/main/install.sh | sudo bash -s -- -v={version}
curl -fsSL https://github.com/quixio/quix-cli/raw/main/install.sh | bash -s -- -v={version}
```

### For Windows (PowerShell):
Expand Down
55 changes: 37 additions & 18 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
# inherited from https://github.com/release-lab/install
# Inspired by https://github.com/release-lab/install

echo "Installing Quix CLI"

Expand All @@ -17,26 +17,33 @@ get_arch() {
echo "arm64"
;;
*)
echo ${NIL}
echo "unsupported"
;;
esac
}

get_os(){
os=$(uname -s | awk '{print tolower($0)}')
if [ "$os" == "darwin" ]; then
if [ "$os" = "darwin" ]; then
echo "osx"
else
echo "$os"
fi
}

# Function to sign the binary
sign_binary() {
os=$1
executable=$2
if [ "$os" == "osx" ]; then
use_sudo=${3:-false} # Set default value to false if not provided explicitly

if [ "$os" = "osx" ]; then
echo "Signing '${executable}'"
codesign -s - "${executable}"
if [ "$use_sudo" = "true" ]; then
sudo codesign -s - "${executable}"
else
codesign -s - "${executable}"
fi
fi
}

Expand All @@ -62,10 +69,16 @@ downloadFolder="${TMPDIR:-/tmp}"
mkdir -p ${downloadFolder} # make sure download folder exists
os=$(get_os)
arch=$(get_arch)

if [ "$arch" = "unsupported" ]; then
echo "Unsupported architecture: ${arch}"
exit 1
fi

file_extension="tar.gz"
file_name="${os}-${arch}.${file_extension}" # the file name should be download
file_name="${os}-${arch}.${file_extension}" # the file name to download

downloaded_file="${downloadFolder}/${file_name}" # the file path should be download
downloaded_file="${downloadFolder}/${file_name}" # the file path to download
executable_folder="/usr/local/bin" # Eventually, the executable file will be placed here

# if version is empty
Expand All @@ -76,28 +89,34 @@ else
fi

echo "[1/5] Detected '${os}-${arch}' architecture"
echo "[2/5] Downloading '${asset_uri}' to '${downloadFolder}'"
echo "[2/5] Downloading '${asset_uri}' to '${downloaded_file}'"
curl --fail --location --output "${downloaded_file}" "${asset_uri}"

echo "[3/5] Installing '${exe_name}' to '${executable_folder}'"
tar -xzf "${downloaded_file}" -C "${executable_folder}"

exe="${executable_folder}/${exe_name}"
chmod +x "${exe}"

sign_binary "$os" "$exe" # Sign the binary for macOS
if [ ! -w "${executable_folder}" ]; then
echo "Permission denied for ${executable_folder}. Trying with sudo..."
sudo tar -xzf "${downloaded_file}" -C "${executable_folder}"
exe="${executable_folder}/${exe_name}"
sudo chmod +x "${exe}"
sign_binary "$os" "$exe" "true"
else
tar -xzf "${downloaded_file}" -C "${executable_folder}"
exe="${executable_folder}/${exe_name}"
chmod +x "${exe}"
sign_binary "$os" "$exe"
fi

echo "[4/5] Cleaning '${downloaded_file}'"
rm -f ${downloaded_file}
rm -f "${downloaded_file}"

echo "[5/5] Adding '${exe_name}' to the environment variables"
if command -v $exe_name --version >/dev/null; then
echo "Quix CLI was installed successfully"
else
echo "We couldn't add '${exe_name}' to the environment variables"
echo "Manually add the directory to your \$HOME/.bash_profile (or similar)"
echo "We couldn't add '${exe_name}' to the environment variables automatically."
echo "Please add the directory to your \$HOME/.bash_profile (or similar):"
echo " export PATH=${executable_folder}:\$PATH"
fi

echo "Run '${exe_name} --help' to get started"
exit 0
exit 0

0 comments on commit 2a1c06b

Please sign in to comment.