-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall
executable file
·32 lines (26 loc) · 1.03 KB
/
install
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
#!/usr/bin/env bash
# WARNING: this script will destroy all data on the $HOME directory.
set -euEo pipefail
trap 'echo "${BASH_SOURCE:-unknown}:${LINENO:-unknown}: $BASH_COMMAND";' ERR
# Accepts REPO_URL in the environment or use default value
readonly REPO_URL="${REPO_URL:[email protected]:lemuelroberto/dotfiles.git}"
# Make sure the user wants to remove all files on target
# WARNING: Reading user input when the script is piped to shell may result in
# unexpected behaivour.
# It's safer to execute bash <(cat install) than cat install | bash.
# Read discussion at stackoverflow to understand why we need read from /dev/tty.
# https://stackoverflow.com/a/20149981/5111444
echo "Will remove all files on $HOME"
read -p "Are you sure? " -n 1 -r < /dev/tty
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo >&2 "Exiting without setting up dotfiles"
exit 1
fi
cd "$HOME" || exit 1
rm -rf ./.??* ./* # Remove all files, including the hidden ones
# Setup repository
git init
git remote add -f origin "$REPO_URL"
git fetch origin main:main
git checkout main