-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdotfiles-openjck-setup-bootstrap
More file actions
117 lines (104 loc) · 3.37 KB
/
Copy pathdotfiles-openjck-setup-bootstrap
File metadata and controls
117 lines (104 loc) · 3.37 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
111
112
113
114
115
116
117
#!/usr/bin/env bash
# Use Bash's unofficial "strict mode."
#
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -o errexit
set -o nounset
set -o pipefail
IFS=$'\n\t'
# This script is **intentionally** not executable by default.
#
# This script should never need to be run _after_ setup is complete. Rather, it
# should be downloaded from the Git host, marked as executable, and run to
# _perform_ the setup.
# This is a copy of the __distro_base function, which is used elsewhere as a
# utility, as of 2026-04-20.
#
# https://github.com/openjck/dotfiles/blob/0b619659e922d624125d16975285d3e7f3688839/.config/sh/init/utils/__distro_base.sh
get_distro_base() {
# https://unix.stackexchange.com/a/46086/410447
if [[ -f /etc/alpine-release ]]; then
echo "alpine"
elif [[ -f /etc/arch-release ]]; then
echo "arch"
elif [[ -f /etc/debian_version ]]; then
echo "debian"
elif [[ -f /etc/gentoo-release ]]; then
echo "gentoo"
elif [[ -f /etc/redhat-release ]]; then
echo "redhat"
elif [[ -f /etc/SuSE-release ]]; then
echo "suse"
else
echo "__UNKNOWN__"
fi
}
# This is a copy of the get_os_id function, which is used elsewhere as a
# utility, as of 2026-04-24.
#
# https://github.com/openjck/dotfiles/blob/3016d31b3e33329b7e024c9ca710c8953ba205ff/.config/sh/init/utils/__get_os_id.sh
get_os_id() {
if [ -e /etc/os-release ]; then
. /etc/os-release
elif [ -e /usr/lib/os-release ]; then
. /usr/lib/os-release
fi
if [ -n "$ID" ]; then
echo "$ID"
else
echo "__UNKNOWN__"
fi
}
DISTRO_BASE=$(get_distro_base)
DISTRO=$(get_os_id)
SUPPORTED=false
if [[ $DISTRO_BASE == debian ]]; then
SUPPORTED=true
elif [[ $DISTRO == fedora ]]; then
SUPPORTED=true
fi
if [[ $SUPPORTED == false ]]; then
echo >&2 'FATAL ERROR: This distro is not supported.'
exit 1
fi
# In addition to checking if the user has (some form of) sudo access, this
# prompts the user for their password once, now, at the beginning of this
# process, so that they don't need to be prompted for it in the middle of this
# process.
if ! sudo --validate; then
echo >&2 "FATAL ERROR: \"sudo\" must be installed and enabled for \"$USER\"."
exit 1
fi
if ! command -v vcsh >/dev/null; then
# We need to test for Fedora specifically because some distributions related
# to RedHat, including RedHat Enterprise Linux (RHEL) itself, have fewer
# packages available to them.
#
# I don't know if vcsh is available on RHEL, but it is available on Fedora.
if [[ $DISTRO_BASE == debian ]]; then
sudo apt-get install --assume-yes vcsh
elif [[ $DISTRO == fedora ]]; then
sudo dnf install --assumeyes vcsh
fi
fi
# https://stackoverflow.com/a/32708121/715866
while true; do
read -rp 'Use SSH or HTTPS to clone dotfiles (S/H)? ' PROTOCOL
case $PROTOCOL in
[Ss])
REMOTE='git@github.com:openjck/dotfiles.git'
break
;;
[Hh])
REMOTE='https://github.com/openjck/dotfiles.git'
break
;;
*) echo 'Please choose SSH (S) or HTTPS (H).' ;;
esac
done
# In the past, I attempted to run "clone" and "pull" in this script instead of
# the following commands. That led to all sorts of problems, though. This
# approach should be more reliable. It does overwrite any existing file with
# the same name as a version-controlled file, but that's fine with me.
vcsh clone "$REMOTE" dotfiles-openjck --quiet --bare
vcsh dotfiles-openjck reset --hard origin/main