@@ -49,6 +49,66 @@ log() {
4949 echo " [BOOTSTRAP 1Password] $* " >&2
5050}
5151
52+ DOWNLOADER=" "
53+
54+ select_downloader () {
55+ if [ -n " $DOWNLOADER " ]; then
56+ return
57+ fi
58+ if has_command curl; then
59+ DOWNLOADER=" curl"
60+ elif has_command wget; then
61+ DOWNLOADER=" wget"
62+ else
63+ die " missing command curl or wget, cannot download files"
64+ fi
65+ }
66+
67+ download_to_stdout () {
68+ select_downloader
69+ url=$1
70+ case " $DOWNLOADER " in
71+ curl)
72+ curl -fsSL " $url "
73+ ;;
74+ wget)
75+ wget -qO- " $url "
76+ ;;
77+ * )
78+ die " unsupported downloader: $DOWNLOADER "
79+ ;;
80+ esac
81+ }
82+
83+ download_to_file () {
84+ select_downloader
85+ url=$1
86+ dest=$2
87+ case " $DOWNLOADER " in
88+ curl)
89+ curl -fSL --progress-bar " $url " -o " $dest "
90+ ;;
91+ wget)
92+ wget -qO " $dest " " $url "
93+ ;;
94+ * )
95+ die " unsupported downloader: $DOWNLOADER "
96+ ;;
97+ esac
98+ }
99+
100+ do_sudo () {
101+ if [ " $( id -u) " -eq 0 ]; then
102+ " $@ "
103+ return
104+ fi
105+ if has_command sudo; then
106+ sudo " $@ "
107+ else
108+ die " missing command sudo, cannot run: $* "
109+ fi
110+ }
111+
52112step_start () {
53113 __STEP_NUMBER=$(( __STEP_NUMBER + 1 ))
54114 __STEP_LABEL=" $1 "
@@ -116,7 +176,7 @@ get_arch() {
116176}
117177
118178get_latest_op_version () {
119- curl -sSL https://app-updates.agilebits.com/check/1/0/CLI2/en/2.0.0/N |
179+ download_to_stdout https://app-updates.agilebits.com/check/1/0/CLI2/en/2.0.0/N |
120180 grep -Eo ' [0-9]+\.[0-9]+\.[0-9]+'
121181}
122182
@@ -137,14 +197,11 @@ apt_install() {
137197 if ! has_command apt-get; then
138198 die " missing command apt-get, cannot install $__package "
139199 fi
140- if ! has_command sudo; then
141- die " missing command sudo, cannot install $__package "
142- fi
143200 if [ " $__NEED_PACKAGE_CACHE_UPDATE " = 1 ]; then
144- sudo apt-get update --quiet --quiet
201+ do_sudo apt-get update --quiet --quiet
145202 __NEED_PACKAGE_CACHE_UPDATE=0
146203 fi
147- sudo apt-get install --no-install-recommends --quiet -y " $__package "
204+ do_sudo apt-get install --no-install-recommends --quiet -y " $__package "
148205
149206}
150207
@@ -194,7 +251,7 @@ step_done " : $OP_URL"
194251
195252step_start " download the 1Password CLI"
196253checked_step \
197- curl -SL --progress-bar " $OP_URL " -o " $__TMP_DIR /op.zip"
254+ download_to_file " $OP_URL " " $__TMP_DIR /op.zip"
198255
199256if is_macos; then
200257 # unzip is included by default on macOS, no need to install
@@ -209,28 +266,6 @@ step_start "unzip the 1Password CLI"
209266checked_step \
210267 unzip -d " $__TMP_DIR /op" " $__TMP_DIR /op.zip"
211268
212- # We can try to install gpg in linux systems, because they have a package
213- # manager built in. MacOS has Brew, but it is not installed by default.
214- # By the time this is run, it can be very early in the setup process, so
215- # we cannot assume that Brew is installed.
216- if ! has_command gpg && [ " $SYSTEM " = " linux" ]; then
217- step_start " install gpg"
218- checked_step \
219- ensure_command gpg gpg
220- fi
221-
222- if has_command gpg; then
223- step_start " download the 1Password CLI keys"
224- checked_step \
225- gpg --keyserver keyserver.ubuntu.com --receive-keys 3FEF9748469ADBE15DA7CA80AC2D62742012EA22
226-
227- step_start " verify the 1Password CLI signature"
228- checked_step \
229- gpg --verify " $__TMP_DIR /op/op.sig" " $__TMP_DIR /op/op"
230- else
231- log " WARNING: gpg is not installed, skipping signature verification"
232- fi
233-
234269step_start " ensure installation directory exists"
235270checked_step \
236271 mkdir -p " $__INSTALL_DIR "
0 commit comments