install.fairie/home/dot_local/bin/post-installx/executable_post-nginx.sh

52 lines
2.4 KiB
Bash
Raw Normal View History

2024-05-03 19:40:44 -07:00
#!/usr/bin/env bash
# @file NGINX Amplify Join
# @brief Set up NGINX Amplify and joins the cloud monitoring service dashboard
# @description
# This script installs NGINX Amplify and connects with the user's NGINX Amplify instance, assuming the `NGINX_AMPLIFY_API_KEY`
# is defined. NGINX Amplify is a free web application that serves as a way of browsing through metrics of all your connected
# NGINX instances.
#
# ## Links
#
# * [NGINX Amplify login](https://amplify.nginx.com/login)
# * [NGINX Amplify documentation](https://docs.nginx.com/nginx-amplify/#)
2024-05-27 20:45:14 -07:00
set -Eeuo pipefail
2024-05-27 20:50:11 -07:00
trap "gum log -sl error 'Script encountered an error!'" ERR
2024-05-27 04:15:03 -07:00
2024-05-03 19:40:44 -07:00
if command -v nginx > /dev/null; then
2024-05-18 00:11:55 -07:00
if [ -d /Applications ] && [ -d /System ]; then
2024-05-12 21:51:08 -07:00
### macOS
2024-05-27 20:50:11 -07:00
gum log -sl info 'Skipping installation of NGINX Amplify because macOS is not supported'
2024-05-12 21:51:08 -07:00
NGINX_CONFIG_DIR=/usr/local/etc/nginx
2024-05-09 19:53:38 -07:00
else
2024-05-12 21:51:08 -07:00
### Linux
NGINX_CONFIG_DIR=/etc/nginx
2024-05-27 04:15:03 -07:00
if get-secret --exists NGINX_AMPLIFY_API_KEY; then
### Download NGINX Amplify script
2024-05-27 20:50:11 -07:00
gum log -sl info 'Downloading the NGINX Amplify installer script'
2024-05-27 04:15:03 -07:00
TMP="$(mktemp)"
curl -sSL https://github.com/nginxinc/nginx-amplify-agent/raw/master/packages/install.sh > "$TMP"
### NGINX Amplify registration
2024-05-27 20:50:11 -07:00
gum log -sl info 'Running the NGINX Amplify setup script'
2024-05-27 04:15:03 -07:00
API_KEY="$(get-secret NGINX_AMPLIFY_API_KEY)" sh "$TMP"
2024-05-18 00:17:57 -07:00
else
2024-05-27 20:50:11 -07:00
gum log -sl warn "Skipping NGINX Amplify setup because the NGINX_AMPLIFY_API_KEY was unavailable"
2024-05-18 00:17:57 -07:00
fi
2024-05-09 19:53:38 -07:00
fi
2024-05-27 20:50:11 -07:00
gum log -sl info "Ensuring $NGINX_CONFIG_DIR is present" && sudo mkdir -p "$NGINX_CONFIG_DIR"
gum log -sl info "Copying configuration files from $HOME/.local/etc/nginx to $NGINX_CONFIG_DIR"
2024-05-19 23:06:00 -07:00
sudo rsync -av "$HOME/.local/etc/nginx/" "$NGINX_CONFIG_DIR"
2024-05-12 21:51:08 -07:00
if [ -d /Applications ] && [ -d /System ]; then
### macOS
if [ -d "${HOMEBREW_PREFIX:-/opt/homebrew}/etc/nginx" ] && [ ! -L "${HOMEBREW_PREFIX:-/opt/homebrew}/etc/nginx" ]; then
2024-05-27 20:50:11 -07:00
gum log -sl info "Removing ${HOMEBREW_PREFIX:-/opt/homebrew}/etc/nginx directory and its contents in favor of symlink to /usr/local/etc/nginx"
2024-05-27 04:15:03 -07:00
rm -rf "${HOMEBREW_PREFIX:-/opt/homebrew}/etc/nginx"
2024-05-12 21:51:08 -07:00
ln -s /usr/local/etc/nginx "${HOMEBREW_PREFIX:-/opt/homebrew}/etc/nginx"
else
2024-05-27 20:50:11 -07:00
gum log -sl info "Skipping symlinking of /usr/local/etc/nginx to ${HOMEBREW_PREFIX:-/opt/homebrew}/etc/nginx because directory symlink already appears to be there"
2024-05-12 21:51:08 -07:00
fi
fi
2024-05-03 19:40:44 -07:00
fi