Skip to content

Commit b7fa739

Browse files
committed
- Update setup/uninstall
1 parent fb5e48f commit b7fa739

File tree

4 files changed

+69
-251
lines changed

4 files changed

+69
-251
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ jobs:
2525
uses: actions/checkout@v3
2626
- name: Run setup
2727
run: ./setup
28-
- name: Test setup artifacts
29-
run: test/setup_artifacts
3028
- name: Run uninstall
3129
run: ./uninstall
3230

@@ -40,8 +38,6 @@ jobs:
4038
run: brew install bash
4139
- name: Run setup
4240
run: ./setup
43-
- name: Test setup artifacts
44-
run: test/setup_artifacts
4541
- name: Run uninstall
4642
run: ./uninstall
4743

setup

Lines changed: 40 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,124 +1,48 @@
11
#!/usr/bin/env bash
2-
3-
print_in_color() {
4-
local color="$1"
5-
shift
6-
if [[ -z ${NO_COLOR+x} ]]; then
7-
printf "$color%b\e[0m\n" "$*"
8-
else
9-
printf "%b\n" "$*"
10-
fi
11-
}
12-
13-
red() { print_in_color "\e[31m" "$*"; }
14-
green() { print_in_color "\e[32m" "$*"; }
15-
green_bold() { print_in_color "\e[1;32m" "$*"; }
16-
blue() { print_in_color "\e[34m" "$*"; }
17-
18-
section() {
19-
printf "\n=== %s\n" "$(green_bold "$@")"
20-
}
21-
22-
sudo_copy() {
23-
printf "%s => %s\n" "$(blue "$(printf '%-25s' "$1")")" "$2"
24-
25-
if [[ -n "$3" ]]; then
26-
$sudo install -m "$3" "$1" "$2"
27-
else
28-
$sudo install "$1" "$2"
29-
fi
30-
}
31-
32-
copy_executable() {
33-
sudo_copy "$1" "/usr/local/bin/" "755"
34-
}
35-
36-
copy_man() {
37-
if [[ ! -d "/usr/local/share/man/man1/" ]]; then return; fi
38-
39-
for file in "$1"/*.1; do
40-
sudo_copy "$file" "/usr/local/share/man/man1/"
41-
done
42-
43-
if command_exist makewhatis; then
44-
$sudo makewhatis /usr/local/man
2+
set -euo pipefail
3+
4+
prepare_installer() {
5+
echo "Initializing installer..."
6+
SSI_VERSION="0.1.5"
7+
8+
# Set up tmp dir where all work is done
9+
tmpdir="$(mktemp -d)"
10+
trap 'rm -rf "$tmpdir"' EXIT
11+
cd "$tmpdir"
12+
export PATH="$tmpdir:$PATH"
13+
14+
# Download ssi if needed
15+
if ! command -v ssi >/dev/null 2>&1 || [ "$(ssi --version 2>/dev/null)" != "$SSI_VERSION" ]; then
16+
if command -v curl >/dev/null 2>&1; then
17+
curl -fSsL https://github.com/DannyBen/ssi/releases/download/v$SSI_VERSION/ssi -o ssi
18+
elif command -v wget >/dev/null 2>&1; then
19+
wget -nv -O ssi https://github.com/DannyBen/ssi/releases/download/v$SSI_VERSION/ssi
20+
else
21+
echo "Error: please install wget or curl, then try again" >&2
22+
exit 1
23+
fi
24+
chmod +x ssi
4525
fi
4626
}
4727

48-
install_completions() {
49-
cmd="$1"
50-
dir="$2"
51-
52-
if [[ -d "/usr/share/bash-completion/completions" ]]; then
53-
compdir="/usr/share/bash-completion/completions"
54-
elif [[ -d "/usr/local/etc/bash_completion.d" ]]; then
55-
compdir="/usr/local/etc/bash_completion.d"
56-
elif command -v brew &>/dev/null && [[ -d "$(brew --prefix)/etc/bash_completion.d" ]]; then
57-
compdir="$(brew --prefix)/etc/bash_completion.d"
58-
else
59-
compdir=''
60-
fi
61-
62-
if [[ -n $compdir ]]; then
63-
printf "copying to %s\n" "$compdir"
64-
echo "$cmd" | $sudo tee "${compdir}/${dir}" >/dev/null
65-
else
66-
printf "%s %s\n" "$(red WARN)" "skipping completions installation, compdir not found"
67-
echo " install it manually by adding this to your startup script:"
68-
echo " $cmd"
69-
fi
70-
}
71-
72-
command_exist() {
73-
[[ -x "$(command -v "$1")" ]]
74-
}
75-
76-
need() {
77-
command_exist "$1" || fail "Cannot run $1"
78-
printf "%s found\n" "$(blue " $1")"
79-
}
80-
81-
onerror() {
82-
local exit_status=$?
83-
printf "\n=== %s\n" "$(red "Aborted with exit status $exit_status")"
84-
exit $exit_status
85-
}
86-
87-
fail() {
88-
printf "$(red 'ERR') %s\n" "$*"
89-
return 1
90-
}
91-
92-
initialize() {
93-
set -e
94-
trap 'onerror' ERR
95-
96-
# Figure out if we need sudo or not
97-
sudo=''
98-
if [[ $EUID -ne 0 ]]; then
99-
sudo='sudo'
100-
fi
101-
102-
repo="$1"
103-
repo_url="https://github.com/${repo}.git"
104-
pushd "$(mktemp -d)" >/dev/null
105-
}
106-
107-
section "Initializing"
108-
initialize "DannyBen/rush"
109-
110-
section "Checking for pre-requisites"
111-
need git
28+
prepare_installer
11229

113-
section "Cloning $repo"
114-
git clone --depth 1 "$repo_url" .
30+
if ! command -v git >/dev/null 2>&1; then
31+
echo "Error: please install git and try again" >&2
32+
exit 1
33+
fi
11534

116-
section "Copying files"
117-
copy_executable 'rush'
118-
copy_man 'doc'
35+
ssi log info Installing rush
36+
ssi log debug Cloning github repo
37+
git clone -q --depth 1 https://github.com/DannyBen/rush.git rush
38+
ssi install bin rush/rush
39+
ssi install man rush/doc
40+
rush completions | ssi install completion - --name rush
11941

120-
section "Installing bash completions"
121-
install_completions "eval \"\$(rush completions)\"" "rush"
42+
if command -v rush >/dev/null 2>&1; then
43+
ssi log info "rush --version : $(rush --version)"
44+
else
45+
ssi log warn "rush not found on PATH after install"
46+
fi
12247

123-
section "Done"
124-
rush --version
48+
ssi log debug Installation complete

test/setup_artifacts

Lines changed: 0 additions & 40 deletions
This file was deleted.

uninstall

Lines changed: 29 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,34 @@
11
#!/usr/bin/env bash
2-
3-
print_in_color() {
4-
local color="$1"
5-
shift
6-
if [[ -z ${NO_COLOR+x} ]]; then
7-
printf "$color%b\e[0m\n" "$*"
8-
else
9-
printf "%b\n" "$*"
10-
fi
11-
}
12-
13-
red() { print_in_color "\e[31m" "$*"; }
14-
green() { print_in_color "\e[32m" "$*"; }
15-
green_bold() { print_in_color "\e[1;32m" "$*"; }
16-
blue() { print_in_color "\e[34m" "$*"; }
17-
18-
section() {
19-
printf "\n=== %s\n" "$(green_bold "$@")"
20-
}
21-
22-
command_exist() {
23-
[[ -x "$(command -v "$1")" ]]
24-
}
25-
26-
rm_executable() {
27-
if [[ -z "$1" ]]; then return; fi
28-
29-
printf "%s %s\n" "$(blue rm)" "$1"
30-
$sudo rm -f "/usr/local/bin/$1"
31-
32-
if command_exist "$1"; then
33-
fail "Command $1 still exists"
34-
fi
35-
}
36-
37-
rm_man() {
38-
if [[ ! -d "/usr/local/share/man/man1/" ]]; then return; fi
39-
if [[ -z "$1" ]]; then return; fi
40-
41-
printf "%s %s\n" "$(blue rm)" "/usr/local/share/man/man1/$1*.1"
42-
$sudo rm -f /usr/local/share/man/man1/"$1"*.1
43-
44-
if command_exist makewhatis; then
45-
$sudo makewhatis /usr/local/man
46-
fi
47-
}
48-
49-
rm_completions() {
50-
if [[ -z "$1" ]]; then return; fi
51-
52-
if [[ -d "/usr/share/bash-completion/completions" ]]; then
53-
compdir="/usr/share/bash-completion/completions"
54-
elif [[ -d "/usr/local/etc/bash_completion.d" ]]; then
55-
compdir="/usr/local/etc/bash_completion.d"
56-
else
57-
compdir=''
58-
fi
59-
60-
if [[ -n $compdir ]]; then
61-
file="$compdir/$1"
62-
printf "%s %s\n" "$(blue rm)" "$file"
63-
$sudo rm -f "$file"
2+
set -euo pipefail
3+
4+
prepare_installer() {
5+
echo "Initializing installer..."
6+
SSI_VERSION="0.1.5"
7+
8+
# Set up tmp dir where all work is done
9+
tmpdir="$(mktemp -d)"
10+
trap 'rm -rf "$tmpdir"' EXIT
11+
cd "$tmpdir"
12+
export PATH="$tmpdir:$PATH"
13+
14+
# Download ssi if needed
15+
if ! command -v ssi >/dev/null 2>&1 || [ "$(ssi --version 2>/dev/null)" != "$SSI_VERSION" ]; then
16+
if command -v curl >/dev/null 2>&1; then
17+
curl -fSsL https://github.com/DannyBen/ssi/releases/download/v$SSI_VERSION/ssi -o ssi
18+
elif command -v wget >/dev/null 2>&1; then
19+
wget -nv -O ssi https://github.com/DannyBen/ssi/releases/download/v$SSI_VERSION/ssi
20+
else
21+
echo "Error: please install wget or curl, then try again" >&2
22+
exit 1
23+
fi
24+
chmod +x ssi
6425
fi
6526
}
6627

67-
onerror() {
68-
local exit_status=$?
69-
printf "\n=== %s\n" "$(red "Aborted with exit status $exit_status")"
70-
exit $exit_status
71-
}
72-
73-
fail() {
74-
printf "$(red 'ERR') %s\n" "$*"
75-
return 1
76-
}
77-
78-
initialize() {
79-
set -e
80-
trap 'onerror' ERR
81-
82-
# Figure out if we need sudo or not
83-
sudo=''
84-
if [[ $EUID -ne 0 ]]; then
85-
sudo='sudo'
86-
fi
87-
}
88-
89-
initialize
90-
91-
section "Removing files"
92-
rm_executable 'rush'
93-
rm_man 'rush'
94-
rm_completions 'rush'
28+
prepare_installer
9529

96-
section "Done"
30+
ssi log info Uninstalling rush
31+
ssi uninstall bin rush
32+
ssi uninstall man rush --all
33+
ssi uninstall completion rush
34+
ssi log debug Unistallation complete

0 commit comments

Comments
 (0)