-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup
More file actions
executable file
·115 lines (106 loc) · 3.76 KB
/
setup
File metadata and controls
executable file
·115 lines (106 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env bash
set -euo pipefail
APP_NAME=${APP_NAME:-deploio}
INSTALL_DIR=${INSTALL_DIR:-"${HOME}/.local/bin"}
RAW_BASE=${RAW_BASE:-"https://raw.githubusercontent.com/CuddlyBunion341/deploio-cli/main"}
CLI_URL="${RAW_BASE}/deploio"
MAN_URL="${RAW_BASE}/deploio.1"
COMPLETION_URL="${RAW_BASE}/_deploio"
COLOR_RESET='\033[0m'
COLOR_GREEN='\033[0;32m'
COLOR_YELLOW='\033[0;33m'
COLOR_CYAN='\033[0;36m'
COLOR_RED='\033[0;31m'
print() { printf "%b\n" "$*"; }
info() { print "${COLOR_CYAN}$*${COLOR_RESET}"; }
success() { print "${COLOR_GREEN}$*${COLOR_RESET}"; }
warn() { print "${COLOR_YELLOW}$*${COLOR_RESET}"; }
err() { print "${COLOR_RED}$*${COLOR_RESET}" 1>&2; }
have_cmd() { command -v "$1" >/dev/null 2>&1; }
fetch() {
local url="$1" dest="$2"
if have_cmd curl; then
curl -fsSL "$url" -o "$dest"
elif have_cmd wget; then
wget -qO "$dest" "$url"
else
err "Need curl or wget to download: $url"
return 1
fi
}
main() {
info "Installing ${APP_NAME} (deplo.io app CLI)"
mkdir -p "$INSTALL_DIR"
tmp_file="$(mktemp -t ${APP_NAME}.XXXXXX)"
tmp_man="$(mktemp -t ${APP_NAME}-man.XXXXXX)"
tmp_completion="$(mktemp -t ${APP_NAME}-completion.XXXXXX)"
trap 'rm -f "$tmp_file" "$tmp_man" "$tmp_completion"' EXIT
info "Downloading CLI from: $CLI_URL"
if ! fetch "$CLI_URL" "$tmp_file"; then
err "Failed to download ${APP_NAME} from $CLI_URL"
exit 1
fi
info "Downloading man page from: $MAN_URL"
if ! fetch "$MAN_URL" "$tmp_man"; then
warn "Failed to download man page from $MAN_URL (continuing without man page)"
fi
info "Downloading zsh completion from: $COMPLETION_URL"
if ! fetch "$COMPLETION_URL" "$tmp_completion"; then
warn "Failed to download completion script from $COMPLETION_URL (continuing without completions)"
fi
install_path="${INSTALL_DIR}/${APP_NAME}"
mv "$tmp_file" "$install_path"
chmod +x "$install_path"
# Install man page if download succeeded
if [[ -s "$tmp_man" ]]; then
man_dir="${HOME}/.local/share/man/man1"
mkdir -p "$man_dir"
mv "$tmp_man" "${man_dir}/${APP_NAME}.1"
success "Installed man page to ${man_dir}/${APP_NAME}.1"
fi
# Install zsh completion if download succeeded
if [[ -s "$tmp_completion" ]]; then
completion_dir="${HOME}/.local/share/zsh/site-functions"
mkdir -p "$completion_dir"
mv "$tmp_completion" "${completion_dir}/_${APP_NAME}"
success "Installed zsh completion to ${completion_dir}/_${APP_NAME}"
fi
# Create shorthand symlink 'depl'
(cd "$INSTALL_DIR" && ln -sf "$APP_NAME" depl)
success "Installed ${APP_NAME} to ${install_path}"
case ":${PATH}:" in
*":${INSTALL_DIR}:"*) ;;
*)
warn "${INSTALL_DIR} is not on your PATH. Add this to your ~/.zshrc:"
echo ""
echo " export PATH=\"$INSTALL_DIR:\$PATH\""
echo ""
echo "Then reload your shell:"
echo " source ~/.zshrc"
;;
esac
# Check if man page directory is in MANPATH
man_dir="${HOME}/.local/share/man"
if [[ -f "${man_dir}/man1/${APP_NAME}.1" ]] && [[ ":${MANPATH}:" != *":${man_dir}:"* ]]; then
warn "Man page installed but ${man_dir} is not in MANPATH."
echo "Add this to your ~/.zshrc to access man pages:"
echo ""
echo " export MANPATH=\"${man_dir}:\$MANPATH\""
echo ""
fi
# Check if completion directory is in fpath
completion_dir="${HOME}/.local/share/zsh/site-functions"
if [[ -f "${completion_dir}/_${APP_NAME}" ]]; then
echo "Zsh completion installed. To enable it, add this to your ~/.zshrc:"
echo ""
echo " fpath=(\"${completion_dir}\" \$fpath)"
echo " autoload -Uz compinit && compinit"
echo ""
echo "Then restart your shell or run: source ~/.zshrc"
fi
echo ""
info "Test the installation:"
echo " ${APP_NAME} --dry-run list"
echo " man ${APP_NAME}"
}
main "$@"