Skip to content

Commit 2f2bf0e

Browse files
committed
site: Add install script and install site
1 parent 13b908d commit 2f2bf0e

File tree

3 files changed

+172
-29
lines changed

3 files changed

+172
-29
lines changed

home/.install-one-password.sh

Lines changed: 64 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
52112
step_start() {
53113
__STEP_NUMBER=$((__STEP_NUMBER + 1))
54114
__STEP_LABEL="$1"
@@ -116,7 +176,7 @@ get_arch() {
116176
}
117177

118178
get_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

195252
step_start "download the 1Password CLI"
196253
checked_step \
197-
curl -SL --progress-bar "$OP_URL" -o "$__TMP_DIR/op.zip"
254+
download_to_file "$OP_URL" "$__TMP_DIR/op.zip"
198255

199256
if 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"
209266
checked_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-
234269
step_start "ensure installation directory exists"
235270
checked_step \
236271
mkdir -p "$__INSTALL_DIR"

site/index.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Jacobo's Dotfiles</title>
7+
<link
8+
rel="stylesheet"
9+
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"
10+
>
11+
</head>
12+
<body>
13+
<main class="container">
14+
<h1>Jacobo's Dotfiles</h1>
15+
16+
<p>
17+
<a href="https://github.com/jdevera/dotfiles">View on GitHub</a>
18+
</p>
19+
20+
<h2>Installation</h2>
21+
<pre><code>sh -c "$(curl -fsLS get.chezmoi.io)" -- init --apply jdevera</code></pre>
22+
</main>
23+
</body>
24+
</html>

site/install

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/bin/sh
2+
3+
set -eu
4+
5+
DOTFILES_REPO=${DOTFILES_REPO:-jdevera}
6+
PWM_MANAGER_INSTALLER='https://raw.githubusercontent.com/jdevera/dotfiles/refs/heads/main/home/.install-one-password.sh'
7+
CHEZMOI_INSTALL_URL='https://get.chezmoi.io/lb'
8+
9+
DOWNLOADER=''
10+
11+
log() {
12+
printf '[chezmoi bootstrap] %s\n' "$*" >&2
13+
}
14+
15+
case ":${PATH:-}:" in
16+
*:"$HOME/.local/bin":*)
17+
;;
18+
*)
19+
PATH="$HOME/.local/bin:${PATH:-}"
20+
export PATH
21+
;;
22+
esac
23+
24+
error() {
25+
printf '%s\n' "$1" >&2
26+
exit 1
27+
}
28+
29+
ensure_downloader() {
30+
if [ -n "$DOWNLOADER" ]; then
31+
return
32+
fi
33+
if command -v curl >/dev/null 2>&1; then
34+
DOWNLOADER='curl'
35+
elif command -v wget >/dev/null 2>&1; then
36+
DOWNLOADER='wget'
37+
else
38+
error 'This installer needs curl or wget to download required scripts.'
39+
fi
40+
}
41+
42+
fetch_to_file() {
43+
url=$1
44+
dest=$2
45+
46+
ensure_downloader
47+
48+
case "$DOWNLOADER" in
49+
curl)
50+
curl -fsSL "$url" -o "$dest"
51+
;;
52+
wget)
53+
wget -qO "$dest" "$url"
54+
;;
55+
esac
56+
}
57+
58+
INSTALLER=$(mktemp)
59+
CHEZMOI_SCRIPT=''
60+
cleanup() {
61+
rm -f "$INSTALLER"
62+
if [ -n "${CHEZMOI_SCRIPT:-}" ]; then
63+
rm -f "$CHEZMOI_SCRIPT"
64+
fi
65+
}
66+
trap cleanup EXIT INT TERM
67+
68+
if [ -n "${PWM_INSTALLER_FILE:-}" ] && [ -f "$PWM_INSTALLER_FILE" ]; then
69+
cp "$PWM_INSTALLER_FILE" "$INSTALLER"
70+
log "using password manager installer from $PWM_INSTALLER_FILE"
71+
else
72+
fetch_to_file "$PWM_MANAGER_INSTALLER" "$INSTALLER"
73+
log "downloaded password manager installer from $PWM_MANAGER_INSTALLER"
74+
fi
75+
76+
log "running password manager installer"
77+
sh "$INSTALLER"
78+
79+
CHEZMOI_SCRIPT=$(mktemp)
80+
fetch_to_file "$CHEZMOI_INSTALL_URL" "$CHEZMOI_SCRIPT"
81+
log "downloaded chezmoi installer from $CHEZMOI_INSTALL_URL"
82+
83+
log "running chezmoi installer"
84+
sh "$CHEZMOI_SCRIPT" -- init --apply "$DOTFILES_REPO"

0 commit comments

Comments
 (0)