Skip to content

Instantly share code, notes, and snippets.

@gbutt
Created January 17, 2026 01:30
Show Gist options
  • Select an option

  • Save gbutt/dc430f7bf9685eafd29f628a0ca95aa6 to your computer and use it in GitHub Desktop.

Select an option

Save gbutt/dc430f7bf9685eafd29f628a0ca95aa6 to your computer and use it in GitHub Desktop.
Bash script to install/update aer
#!/bin/bash
set -euo pipefail
AER_HOME="${HOME}/.aer"
BIN_DIR="${AER_HOME}/bin"
TARGET="${BIN_DIR}/aer"
BACKUP="${BIN_DIR}/aer.bak"
REPO_BASE_URL="https://github.com/octoberswimmer/aer-dist"
create_backup() {
if [[ -f "${TARGET}" ]]; then
mv -f "${TARGET}" "${BACKUP}"
fi
}
restore_backup() {
if [[ -f "${BACKUP}" ]]; then
echo "Restoring backup..."
mv -f "${BACKUP}" "${TARGET}"
echo "Restore complete."
else
echo "No backup found to restore."
fi
}
delete_backup() {
if [[ -f "${BACKUP}" ]]; then
rm -f "${BACKUP}"
fi
}
install_aer() {
create_backup
FILE_NAME="aer_darwin_amd64_${VERSION}.zip"
# Download asset
cd "${AER_HOME}"
wget -q "${REPO_BASE_URL}/releases/download/${VERSION}/${FILE_NAME}" -O "${FILE_NAME}"
# Unzip into bin directory
unzip -o "${FILE_NAME}" -d "${BIN_DIR}"
chmod +x "${TARGET}"
echo "$VERSION" > "${AER_HOME}/version.txt"
# Remove archive
rm -f "${FILE_NAME}"
if "${BIN_DIR}/aer" --version &> /dev/null; then
echo "AER installed successfully (version ${VERSION})."
delete_backup
else
echo "AER installation failed."
restore_backup
exit 1
fi
}
on_error() {
echo "Update failed. Attempting to restore previous version..."
restore_backup
exit 1
}
trap on_error ERR
# Check required commands
for cmd in curl wget unzip; do
if ! command -v "$cmd" &> /dev/null; then
echo "$cmd could not be found. Please install $cmd to proceed."
exit 1
fi
done
# Ensure AER_HOME and BIN_DIR exist
if [[ ! -d "${AER_HOME}" ]]; then
mkdir -p "${BIN_DIR}"
fi
# Determine latest version
VERSION="$(curl -sI "${REPO_BASE_URL}/releases/latest" | grep '^location:' | awk '{print $2}' | tr -d $'\r\n' | awk -F'/' '{print $NF}')"
CURRENT_VERSION=""
if [[ -f "${AER_HOME}/version.txt" ]]; then
CURRENT_VERSION="$(cat "${AER_HOME}/version.txt")"
fi
if [[ "${VERSION}" == "${CURRENT_VERSION}" ]]; then
echo "AER is already up to date (version ${VERSION})."
elif [[ -z "${CURRENT_VERSION}" ]]; then
echo "AER is not installed. Installing version ${VERSION}."
install_aer
else
echo "Updating AER from version ${CURRENT_VERSION} to ${VERSION}."
install_aer
fi
# Add BIN_DIR to PATH if not already present
if ! command -v aer &> /dev/null; then
# detect which shell is being used
SHELL_NAME="$(basename "$SHELL")"
PROFILE_FILE=""
case "${SHELL_NAME}" in
bash)
PROFILE_FILE="${HOME}/.bashrc"
;;
zsh)
PROFILE_FILE="${HOME}/.zshrc"
;;
*)
echo "Unsupported shell: ${SHELL_NAME}. Please add ${BIN_DIR} to your PATH manually."
exit 1
;;
esac
# update path in profile file
if ! grep -q "${BIN_DIR}" "${PROFILE_FILE}"; then
echo "" >> "${PROFILE_FILE}"
echo "# Added by AER installer" >> "${PROFILE_FILE}"
echo "export PATH=\"${BIN_DIR}:\$PATH\"" >> "${PROFILE_FILE}"
echo "Updated ${PROFILE_FILE} to include ${BIN_DIR} in PATH."
case "${SHELL_NAME}" in
bash)
set +u
source "${PROFILE_FILE}"
set -u
;;
zsh)
PATH="${BIN_DIR}:${PATH}"
echo "Please run 'source ~/.zshrc' or restart your terminal to update your PATH."
;;
esac
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment