-
Notifications
You must be signed in to change notification settings - Fork 3
/
bootstrap-user
executable file
·71 lines (54 loc) · 2.33 KB
/
bootstrap-user
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
#!/usr/bin/env bash
set -euo pipefail
dh_bootstrap_users_default=https://raw.githubusercontent.com/dot-home/dot-home/main/dh/bootstrap-users
DH_BOOTSTRAP_USERS=${DH_BOOTSTRAP_USERS:-$dh_bootstrap_users_default}
dh_repo=https://github.com/dot-home/dot-home
dh_local="$HOME/.home/dot-home"
####################################################################
USAGE="\
Usage: $(basename "$0")
This command bootstraps a dot-home configuration for the user specified in
\$LOGNAME. (POSIX XBD 8.3 specifies that this defaults to the current user.[1])
This reads the \$DH_BOOTSTRAP_USERS file (default [2]) which contains lines
of three whitespace-separated fields: login-name, repo-url and repo-name. It
will find the first line whose login-name matches \$LOGNAME and:
1. Clone the repo specified in repo-url to \$HOME/.home/<repo-name>
2. Clone the dot-home repo to \$HOME/.home/dot-home
3. Run \$HOME/.home/dot-home/bin/dot-home-setup -u
This script is typically run using the following command:
curl -sfL https://raw.githubusercontent.com/dot-home/dot-home/main/bootstrap-user | bash
See the dot-home README.md file[3] for more information.
[1]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html
[2]: $dh_bootstrap_users_default
[3]: $dh_repo
"
####################################################################
die() { local ec=$1; shift; echo 1>&2 "$@"; exit $ec; }
clone_or_update() {
local url="$1" dir="$2"
if [[ ! -d $dir ]]; then
git clone -q "$url" "$dir"
else
git -C "$dir" fetch -q
git -C "$dir" rebase -q
fi
}
[[ "${#@}" -eq 0 ]] || { echo "$USAGE"; exit 2; }
echo "dot-home bootstrap for user $LOGNAME"
echo "Reading $DH_BOOTSTRAP_USERS"
while read logname user_repo_url user_local_repo; do
[[ $logname == $LOGNAME ]] || continue
[[ -n $user_local_repo ]] || user_local_repo=${user_repo_url##*/}
break
done < <(curl -sfL "$DH_BOOTSTRAP_USERS")
if [[ $logname != $LOGNAME ]]; then
echo "Warning: cannot find user $LOGNAME in $DH_BOOTSTRAP_USERS"
else
echo "Cloning $user_local_repo from $user_repo_url"
clone_or_update "$user_repo_url" "$HOME/.home/$user_local_repo"
fi
echo "Cloning dot-home from $dh_repo"
clone_or_update "$dh_repo" "$dh_local"
echo "Running dot-home-setup"
"$dh_local"/bin/dot-home-setup
echo "Test in a new window, or 'source ~/.bashrc'."