-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·110 lines (87 loc) · 3.31 KB
/
install.sh
File metadata and controls
executable file
·110 lines (87 loc) · 3.31 KB
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
#!/usr/bin/env bash
#
# install.sh - Bootstrap installer for urda.bash
#
# Usage:
# /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/urda/urda.bash/master/install.sh)"
#
# Downloads and installs urda.bash dotfiles into the user's home directory.
# Existing files will be overwritten after confirmation.
#
set -euo pipefail
BASE_URL="https://raw.githubusercontent.com/urda/urda.bash/master"
# ---------------------------------------------------------------------------
# Fetch version and manifest from remote
# ---------------------------------------------------------------------------
echo "Fetching urda.bash..."
if ! VERSION=$(curl -fs -m 10 "${BASE_URL}/VERSION"); then
echo "Error: failed to fetch VERSION from remote" >&2
exit 1
fi
VERSION=${VERSION//[[:space:]]/}
if ! MANIFEST=$(curl -fs -m 10 "${BASE_URL}/MANIFEST"); then
echo "Error: failed to fetch MANIFEST from remote" >&2
exit 1
fi
if [[ -z ${VERSION} || -z ${MANIFEST} ]]; then
echo "Error: empty VERSION or MANIFEST from remote" >&2
exit 1
fi
echo "urda.bash ${VERSION}"
# ---------------------------------------------------------------------------
# Download all managed files to a temporary staging directory
# ---------------------------------------------------------------------------
STAGING=$(mktemp -d)
trap 'rm -rf "${STAGING}"' EXIT
echo "Staging to: ${STAGING}"
while IFS= read -r file; do
[[ -z ${file} ]] && continue
echo " ${file}"
if ! curl -fs -m 10 -o "${STAGING}/${file}" "${BASE_URL}/${file}"; then
echo "Error: failed to download ${file}" >&2
exit 1
fi
done <<< "${MANIFEST}"
# ---------------------------------------------------------------------------
# Verify downloads (count and non-empty)
# ---------------------------------------------------------------------------
expected=$(echo "${MANIFEST}" | grep -c .)
actual=$(find "${STAGING}" -type f | grep -c .)
if [[ ${expected} -ne ${actual} ]]; then
echo "Error: expected ${expected} files, got ${actual}" >&2
exit 1
fi
if [[ -n $(find "${STAGING}" -type f -empty -print -quit) ]]; then
echo "Error: empty files detected" >&2
exit 1
fi
echo "Files verified (${actual} files)"
# ---------------------------------------------------------------------------
# Warn about existing files that will be overwritten
# ---------------------------------------------------------------------------
echo ""
while IFS= read -r file; do
[[ -z ${file} ]] && continue
if [[ -f "${HOME}/.${file}" ]]; then
echo " Will overwrite: ${HOME}/.${file}"
else
echo " Will create: ${HOME}/.${file}"
fi
done <<< "${MANIFEST}"
# ---------------------------------------------------------------------------
# Confirm with user (read from /dev/tty since stdin may be a pipe)
# ---------------------------------------------------------------------------
echo ""
read -r -p "Install urda.bash ${VERSION}? [Y/N] " confirm < /dev/tty
if [[ ${confirm} != [yY] ]]; then
echo "Install cancelled"
exit 0
fi
# ---------------------------------------------------------------------------
# Copy files to home directory
# ---------------------------------------------------------------------------
while IFS= read -r file; do
[[ -z ${file} ]] && continue
cp -v "${STAGING}/${file}" "${HOME}/.${file}"
done <<< "${MANIFEST}"
echo "urda.bash ${VERSION} installed. Open a new shell to use it."