Last active
June 30, 2024 18:49
-
-
Save jreniel/a65791f6bbe8ee4e8563d92342616c9c to your computer and use it in GitHub Desktop.
tt-tecchspec install
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Exit immediately if a command exits with a non-zero status | |
set -e | |
gituser="jreniel" | |
namespace="preview" | |
name="tt-techspec" | |
REPO_URL="[email protected]:$gituser/$name.git" | |
# Function to fetch the version from the typst.toml file | |
fetch_version() { | |
local version | |
version=$(cat typst.toml | grep '^version' | awk -F\" '{print $2}') | |
if [[ -z "$version" ]]; then | |
echo "Failed to fetch version from typst.toml" >&2 | |
exit 1 | |
fi | |
echo "$version" | |
} | |
# Function to determine the installation directory based on the operating system | |
get_git_dir() { | |
if [[ "$OSTYPE" == "linux-gnu"* ]]; then | |
echo "${XDG_DATA_HOME:-$HOME/.local/share/typst/packages}/$namespace/$name/latest" | |
elif [[ "$OSTYPE" == "darwin"* ]]; then | |
echo "$HOME/Library/Application Support/typst/packages/$namespace/$name/latest" | |
else | |
echo "Unsupported OS: $OSTYPE" >&2 | |
exit 1 | |
fi | |
} | |
# Function to clone or update the repository | |
clone_or_update_repo() { | |
local git_dir=$1 | |
if [ -d "$git_dir" ]; then | |
echo "Directory $git_dir already exists. Updating the repository..." | |
cd "$git_dir" && git pull | |
else | |
echo "Cloning the repository from $REPO_URL... " | |
git clone "$REPO_URL" "$git_dir" | |
fi | |
} | |
# Function to run setup commands | |
run_setup() { | |
local git_dir=$1 | |
cd "$git_dir" | |
echo "Running setup..." | |
local version | |
version=$(fetch_version) | |
install_dir=$(dirname "$git_dir")/$version | |
echo "Install directory: $install_dir" | |
cp -rf $git_dir $install_dir | |
echo "Installation complete!" | |
} | |
main() { | |
local git_dir | |
git_dir=$(get_git_dir) | |
clone_or_update_repo "$git_dir" | |
run_setup "$git_dir" | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment