Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F/install script without sudo #7

Merged
merged 11 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@ jobs:
steps:
- uses: actions/checkout@v4
- shell: bash
run: |
bash scripts/install.sh
terrac --help
run: bash scripts/install.sh
- shell: bash
run: terrac --help
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ You can simply download a binary and put it in a directoy included in the `PATH`

### bash

The following script automates the manual installation with a bash script in Linux and MacOS. `sudo` permission is required.
The following script automates the manual installation with a bash script in Linux and MacOS.

``` bash
curl https://raw.githubusercontent.com/haoliangyu/terrac/main/scripts/install.sh | bash
Expand Down
62 changes: 45 additions & 17 deletions scripts/install.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
# A bash scrip to automate the terrac installation

#!/bin/bash

set -e

# Get the user's home directory
home_dir=$HOME

# Determine the shell configuration file based on the user's shell
if [ -n "$BASH_VERSION" ]; then
# Bash shell
shell_rc=".bashrc"
elif [ -n "$ZSH_VERSION" ]; then
# Zsh shell
shell_rc=".zshrc"
else
echo "Unsupported shell. Please configure the PATH manually."
exit 1
fi

# GitHub API URL for the latest release
api_url="https://api.github.com/repos/haoliangyu/terrac/releases/latest"

Expand All @@ -22,25 +35,40 @@ latest_release=$(echo "$response" | jq -r '.name')
os=$(uname -s)

# Check the operating system and print a message
if [ "$os" = "Darwin" ]; then
download_url="https://github.com/haoliangyu/terrac/releases/download/$latest_release/terrac-macos"
curl -o "terrac" -J -L -H "Accept: application/octet-stream" "$download_url"
sudo mv -f terrac /usr/local/bin/terrac
sudo chmod +x /usr/local/bin/terrac
elif [ "$os" = "Linux" ]; then
download_url="https://github.com/haoliangyu/terrac/releases/download/$latest_release/terrac-linux"
curl -o "terrac" -J -L -H "Accept: application/octet-stream" "$download_url"
sudo mv -f terrac /usr/local/bin/terrac
sudo chmod +x /usr/local/bin/terrac
# Windows support is not added yet
# elif [ "$os" = "MINGW64_NT-10.0" ]; then
# download_url="https://github.com/haoliangyu/terrac/releases/download/$latest_release/terrac-win"
# curl -o "terrac" -J -L -H "Accept: application/octet-stream" "$download_url"
# mv -f terrac /usr/local/bin/
if [ "$os" = "Darwin" ] || [ "$os" = "Linux" ]; then
# Determine the download URL based on the operating system
case "$os" in
Darwin)
install_dir=$home_dir/bin
download_url="https://github.com/haoliangyu/terrac/releases/download/$latest_release/terrac-macos"
;;
Linux)
install_dir=$home_dir/.local/bin
download_url="https://github.com/haoliangyu/terrac/releases/download/$latest_release/terrac-linux"
;;
esac

# Download the binary
mkdir $install_dir
curl -o "$install_dir/terrac" -J -L -H "Accept: application/octet-stream" "$download_url"
chmod +x "$install_dir/terrac"
else
echo "Unsupported operating system: $os"
exit 1
fi

echo ''
echo 'Terrac is installed successfully. You can run "terrac --help" to verify.'

# Check if ~/bin is already in PATH
if echo "$PATH" | grep -q "$install_dir"; then
echo "Path '$install_dir' is already in PATH."
else
# Add ~/bin to PATH and update shell configuration file
echo "export PATH=\"$install_dir:\$PATH\"" >> "$home_dir/$shell_rc"
echo "Added '$install_dir' to PATH in $shell_rc."

# Apply the changes to the current shell session
source "$home_dir/$shell_rc"
echo "Changes applied to the current shell session."
fi
Loading