-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap
85 lines (66 loc) · 2.4 KB
/
bootstrap
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
#!/usr/bin/env bash
set -e
# shellcheck source=./directories.sh
eval "$(curl -fLsS https://raw.githubusercontent.com/anttikivi/etc/main/directories.sh)"
REPO_DIR="${ETC_DIR}"
readonly REPO_DIR
HTTPS_REMOTE_URL='https://github.com/anttikivi/etc.git'
readonly HTTPS_REMOTE_URL
SSH_REMOTE_URL='git@github.com:anttikivi/etc.git'
readonly SSH_REMOTE_URL
PURUS_HTTPS_URL='https://github.com/anttikivi/purus.git'
readonly PURUS_HTTPS_URL
PURUS_SSH_URL='git@github.com:anttikivi/purus.git'
readonly PURUS_SSH_URL
echo "Running the configuration bootstrapping script!"
echo "Checking if the configuration repository is present at ${REPO_DIR}"
first_run="false"
if [ ! -e "${REPO_DIR}" ]; then
first_run="true"
if [ ! -d "$(dirname "${REPO_DIR}")" ]; then
echo "Please make sure that the parent directory for ${REPO_DIR} (i.e. $(dirname "${REPO_DIR}")) exists" >&2
exit 1
fi
echo "Cloning the configuration repository into ${REPO_DIR}"
git clone "${HTTPS_REMOTE_URL}" "${REPO_DIR}"
elif [ "$(git -C "${REPO_DIR}" remote get-url origin)" != "${SSH_REMOTE_URL}" ]; then
first_run="true"
fi
if [ "${first_run}" = "true" ]; then
echo "This is marked as the first run"
fi
cd "${REPO_DIR}"
if [ "${first_run}" = "true" ]; then
echo "Changing the URL for the 'purus' submodule"
git submodule set-url -- purus "${PURUS_HTTPS_URL}"
fi
echo "Running the main script"
if [ "${first_run}" = "true" ]; then
FIRST_RUN=true ./install "$@"
else
./install "$@"
fi
# shellcheck source=./bash_profile
source ~/.bash_profile
if [ "${first_run}" = "true" ]; then
echo "Changing the URL for the 'purus' submodule back to the original"
git submodule set-url -- purus "${PURUS_SSH_URL}"
echo "Updating the submodules"
git submodule sync --recursive
git submodule update --init --recursive
echo "Checking the remote URL of the configuration repository"
current_url="$(git remote get-url origin)"
echo "The remote URL of the configuration repository is currently set to ${current_url}"
if [ "${current_url}" != "${SSH_REMOTE_URL}" ]; then
git remote set-url origin "${SSH_REMOTE_URL}"
fi
echo "The remote URLs of the configuration repository are now set to:"
git remote -v
echo "Fetching the remote"
git fetch
echo "The status of the Git repository is:"
git status
fi
cd - >/dev/null
echo "Bootstrapping complete!"
echo "You probably need to launch a new shell to properly enjoy the experience that was set up"