-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
142 lines (123 loc) · 4.53 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
#!/bin/bash
# TODO(everyone): Keep this script simple and easily auditable.
# Thanks deno.land for inspiration <3
#
# Copyright (C) 2020 Flossbank, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
set -eo pipefail
BOLD="$(tput bold 2>/dev/null || echo '')"
RED="$(tput setaf 1 2>/dev/null || echo '')"
YELLOW="$(tput setaf 3 2>/dev/null || echo '')"
MAGENTA="$(tput setaf 5 2>/dev/null || echo '')"
NO_COLOR="$(tput sgr0 2>/dev/null || echo '')"
info() {
printf "%s\n" "${BOLD}$*${NO_COLOR}"
}
error() {
printf "%s\n" "${RED}x $*${NO_COLOR}" >&2
}
flossbank_install="${FLOSSBANK_INSTALL:-$HOME/.flossbank}"
bin_dir="$flossbank_install/bin"
exe="$bin_dir/flossbank"
if [ -z "$FLOSSBANK_INSTALL_TOKEN" ]; then
# We might not need an install token: Flossbank might already be installed
# and an API key may already be configured. So we'll check that here.
if [ ! -x "$exe" ] || ! "$exe" check; then
# The installer needs a token and it isn't present as an env var.
# When we ask for the user to type it in, this script will try to read
# from stdin. But this script was piped into `sh`. Instead we're going
# to explicitly connect /dev/tty to the installer's stdin, ala https://sh.rustup.rs.
if [ ! -t 1 ]; then
error "Unable to run interactively. Run with FLOSSBANK_INSTALL_TOKEN=<token>."
fi
while [ -z "$FLOSSBANK_INSTALL_TOKEN" ]; do
read -r -p "${BOLD}Please enter install token to continue: ${NO_COLOR}" FLOSSBANK_INSTALL_TOKEN </dev/tty
done
fi
fi
case $(uname -s) in
Darwin) target="macos-x86_64" ;;
*) target="linux-x86_64" ;;
esac
if [ "$(uname -m)" != "x86_64" ]; then
error "Unsupported architecture $(uname -m). Only x64 binaries are available."
exit
fi
if ! command -v unzip >/dev/null; then
error "Error: unzip is required to install Flossbank." 1>&2
exit 1
fi
if ! command -v curl >/dev/null; then
error "Error: curl is required to install Flossbank." 1>&2
exit 1
fi
if ! command -v cut >/dev/null; then
error "Error: cut is required to install Flossbank." 1>&2
exit 1
fi
echo
info "Welcome to Flossbank!"
echo
echo "This script will download and install the latest version of Flossbank,"
echo "a package manager wrapper that helps compensate open source maintainers."
echo
echo "It will add the 'flossbank' command to Flossbank's bin directory, located at:"
echo
echo "${YELLOW}${bin_dir}${NO_COLOR}"
echo
echo "This path will then be added to your PATH environment variable by"
echo "modifying your shell profile/s."
echo
echo "You can uninstall at any time by executing 'flossbank uninstall'"
echo "and these changes will be reverted."
echo
if [ ! "$FLOSSBANK_CONFIRM" ]; then
if [ -t 1 ]; then
read -n 1 -s -r -p "Press any key to continue..." </dev/tty
echo
fi
fi
flossbank_asset_info=$(command curl -sSLf "https://install.flossbank.com/releases/${target}")
if [ ! "$flossbank_asset_info" ]; then
echo
error "Error: unable to locate latest release on GitHub. Please try again or email [email protected] for help!"
exit 1
fi
flossbank_uri=$(echo "$flossbank_asset_info" | head -n 1)
flossbank_version=$(echo "$flossbank_asset_info" | tail -n 1)
flossbank_file_name=$(echo "$flossbank_uri" | cut -d'/' -f 9)
echo "Installing version: ${YELLOW}${flossbank_version}${NO_COLOR}"
echo " - Downloading ${YELLOW}${flossbank_file_name}${NO_COLOR}..."
[ ! -d "$bin_dir" ] && mkdir -p "$bin_dir"
curl -sS --fail --location --output "$exe.zip" "$flossbank_uri"
cd "$bin_dir"
unzip -qq -o "$exe.zip"
chmod +x "$exe"
rm "$exe.zip"
echo
$exe install "$flossbank_install"
$exe wrap all
[ -n "$FLOSSBANK_INSTALL_TOKEN" ] && $exe auth "$FLOSSBANK_INSTALL_TOKEN"
echo
echo
info "Flossbank (${flossbank_version}) is now installed and registered. Great!"
echo
echo "To get started, you need Flossbank's bin directory (${bin_dir}) in your 'PATH'"
echo "environment variable. Next time you log in this will be done"
echo "automatically."
echo
info "To configure your current shell run ${MAGENTA}source ${flossbank_install}/env${NO_COLOR}"
echo