77# Options (via environment variables):
88# VERSION - specific version to install (e.g. v0.1.0). Defaults to latest.
99# INSTALL_DIR - directory to install to. Defaults to ~/.local/bin.
10+ # OPENAPI_AGGREGATOR_HOME - if set (and INSTALL_DIR is unset), installs to
11+ # $OPENAPI_AGGREGATOR_HOME/bin.
1012
1113set -e
1214
1315REPO=" includeamin/openapi-aggregator"
1416BINARY=" openapi-aggregator"
15- INSTALL_DIR=" ${INSTALL_DIR:- $HOME / .local/ bin} "
17+ INSTALL_DIR=" ${INSTALL_DIR:- } "
18+ APP_HOME=" ${OPENAPI_AGGREGATOR_HOME:- } "
19+ DEFAULT_INSTALL_DIR=" $HOME /.local/bin"
1620
1721# --- helpers ---------------------------------------------------------------
1822
1923info () { printf ' \033[1;34m[info]\033[0m %s\n' " $1 " ; }
2024error () { printf ' \033[1;31m[error]\033[0m %s\n' " $1 " >&2 ; exit 1; }
2125
2226print_path_fix_hint () {
23- shell_name=" $( basename " ${SHELL:- } " ) "
27+ shell_path=" ${SHELL:- } "
28+ case " $shell_path " in
29+ * /* ) shell_name=" ${shell_path##*/ } " ;;
30+ * ) shell_name=" $shell_path " ;;
31+ esac
32+
33+ [ -n " $shell_name " ] || shell_name=" unknown"
34+
2435 case " $shell_name " in
2536 zsh)
2637 rc_file=" $HOME /.zshrc"
@@ -55,6 +66,18 @@ need() {
5566 command -v " $1 " > /dev/null 2>&1 || error " required command not found: $1 "
5667}
5768
69+ resolve_install_dir () {
70+ if [ -n " $INSTALL_DIR " ]; then
71+ return
72+ fi
73+
74+ if [ -n " $APP_HOME " ]; then
75+ INSTALL_DIR=" ${APP_HOME} /bin"
76+ else
77+ INSTALL_DIR=" $DEFAULT_INSTALL_DIR "
78+ fi
79+ }
80+
5881# --- detect OS & arch ------------------------------------------------------
5982
6083detect_target () {
@@ -164,12 +187,21 @@ download_and_install() {
164187# --- uninstall -------------------------------------------------------------
165188
166189uninstall () {
167- if [ ! -f " ${INSTALL_DIR} /${BINARY} " ]; then
168- error " ${BINARY} not found in ${INSTALL_DIR} "
190+ if [ -n " $INSTALL_DIR " ]; then
191+ target_path=" ${INSTALL_DIR} /${BINARY} "
192+ elif [ -n " $APP_HOME " ]; then
193+ target_path=" ${APP_HOME} /bin/${BINARY} "
194+ else
195+ target_path=" $( command -v " $BINARY " 2> /dev/null || true) "
196+ [ -n " $target_path " ] || target_path=" ${DEFAULT_INSTALL_DIR} /${BINARY} "
197+ fi
198+
199+ if [ ! -f " $target_path " ]; then
200+ error " ${BINARY} not found (set INSTALL_DIR to uninstall from a custom location)"
169201 fi
170202
171- info " removing ${INSTALL_DIR} / ${BINARY }"
172- rm -f " ${INSTALL_DIR} / ${BINARY} "
203+ info " removing ${target_path } "
204+ rm -f " $target_path "
173205
174206 info " ${BINARY} has been uninstalled"
175207}
@@ -181,6 +213,7 @@ case "${1:-}" in
181213 uninstall
182214 ;;
183215 * )
216+ resolve_install_dir
184217 detect_target
185218 resolve_version
186219 download_and_install
0 commit comments