-
Notifications
You must be signed in to change notification settings - Fork 7
/
install.sh
156 lines (130 loc) · 4.65 KB
/
install.sh
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env bash
set -e
APP="apptokit"
LIB_DIR="/usr/local/lib/$APP"
BIN_DIR="/usr/local/bin"
function install {
command -v ruby >/dev/null 2>&1 || {
echo >&2 "apptokit requires ruby but it's not installed. Aborting."
echo >&2 "Check out https://www.ruby-lang.org/en/documentation/installation/ for ways to get it!"
exit 1
}
command -v brew >/dev/null 2>&1 || {
command -v git >/dev/null 2>&1 || {
echo >&2 "apptokit requires git but it's not installed, and brew is not installed to install it. Aborting."
echo >&2 "For help installing homebrew, visit https://brew.sh"
exit 1
}
}
command -v git >/dev/null 2>&1 || {
echo >&2 "apptokit requires git, install it using Homebrew?"
read -rp "Continue (y/n)?" choice
case "$choice" in
y|Y )
brew install git
;;
* )
echo >&2 "apptokit installer cannot proceed without git, try again once it's available."
exit 2
;;
esac
}
PROJECT_GIT_URL="https://github.com/jakewilkins/apptokit"
TAG="main"
LIB_MOVES=("completions" "libexec" "share" "LICENSE")
CLONE_DIR="./.apptokit-temp_clone"
USE_SUDO=""
[ -d "$CLONE_DIR" ] && rm -rf "$CLONE_DIR"
local use_local_copy=false
if [ $CODESPACES ]; then
remote_url=$(git remote get-url origin)
if [[ "$remote_url" == "$PROJECT_GIT_URL" ]]; then
use_local_copy=true
LIB_DIR="$(pwd)"
USE_SUDO="sudo"
fi
else
set +e
touch "$BIN_DIR/testing-writeability-for-apptokit"
if [ "$?" != "0" ]; then
echo "'$BIN_DIR' is not writable as this user, please enter your password so we may use 'sudo' to write files:"
sudo echo "Thanks!"
else
rm "$BIN_DIR/testing-writeability-for-apptokit"
fi
set -e
fi
$USE_SUDO mkdir -pv $BIN_DIR
if [[ "$use_local_copy" == "false" ]]; then
git clone $PROJECT_GIT_URL $CLONE_DIR
$USE_SUDO mkdir -pv $LIB_DIR
$USE_SUDO mkdir -pv $LIB_DIR/bin
pushd $CLONE_DIR
git fetch origin $TAG
git checkout $TAG
for move in "${LIB_MOVES[@]}"; do
$USE_SUDO mv -v "$move" "$LIB_DIR/$move"
done
popd
[ -d "$CLONE_DIR" ] && rm -rf "$CLONE_DIR" 1>/dev/null
# FIXME - this link is kind of gross - but I'm leaving it so that
# apptokit shell-setup works without changes.
$USE_SUDO ln -vs $LIB_DIR/libexec/$APP $LIB_DIR/bin/$APP
fi
local ruby_version_major=$(ruby --disable-gems -e "print RUBY_VERSION.split('.').tap {|a| a[2] = '0'}.join('.')")
export GEM_PATH="$LIB_DIR/share/ruby/vendor/ruby/${ruby_version_major}:${GEM_PATH}"
export GEM_HOME="$LIB_DIR/share/ruby/vendor/ruby/${ruby_version_major}"
gem install jwt 1>/dev/null
[ ! -f $BIN_DIR/$APP ] && $USE_SUDO ln -vs $LIB_DIR/libexec/$APP $BIN_DIR/$APP
echo "Generating global config file unless you have one..."
$BIN_DIR/$APP init initial-setup
echo
echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo "Installer complete!"
echo
echo "If /usr/bin is not in your \$PATH or you'd like tab completions, follow instructions below."
echo
$BIN_DIR/$APP shell-setup
}
function uninstall {
shell_name=$(basename "$SHELL")
echo "This uninstaller will remove"
echo " - the lib files in /usr/local/lib"
echo " - the linked executable in /usr/local/bin"
echo " - any keycache files generated"
echo
echo "Your global config and any project specific configs will remain, as well as shell-setup commands added to your ${shell_name}rc"
echo "to fully complete uninstallation please remove the shell-setup commands from your ${shell_name}rc"
echo
[ -d "$LIB_DIR" ] && { echo "removing $LIB_DIR"; rm -r "$LIB_DIR" > /dev/null; }
[ -L "$BIN_DIR/$APP" ] && { echo "removing $BIN_DIR/$APP"; rm "$BIN_DIR/$APP" > /dev/null; }
set +e
db_glob="$(ls ~/.config/.apptokit_*_keycache.db 2>/dev/null)"
set -e
[ -n "$db_glob" ] && { echo "removing key caches $db_glob"; rm "$db_glob"; }
set +e
db_glob="$(ls ~/.config/.apptokit_*_keycache 2>/dev/null)"
set -e
[ -n "$db_glob" ] && { echo "removing key caches $db_glob"; rm "$db_glob"; }
echo "uninstall complete."
}
case "$1" in
"install" )
if [[ "$2" != "--i-have-read-this-script" ]]; then
(>&2 echo "🚨🚨 Howdy! This install script is very much a WIP 🚨🚨")
(>&2 echo "I very much appreciate you trying it it. Have you read it over?")
(>&2 echo "If not I heartily recommend giving it a glance: https://git.io/fjLww")
(>&2 echo "Inside you will find the 🗝 to ~happiness~ and avoiding this message.")
exit
fi
install
;;
"uninstall" )
uninstall
;;
* )
echo >&2 "Please specifiy one of install or uninstall"
exit 3
;;
esac
#// vim: set ft=sh: