-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·66 lines (47 loc) · 1.47 KB
/
install.sh
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
#!/bin/bash
DOTFILES=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
BASH_DIR="${DOTFILES}/bash"
# shellcheck source=/dev/null
source "${BASH_DIR}/_config.sh"
THIS_BACKUP="${BACKUP_DIR}/$(date '+%Y-%m-%d_%H:%M:%S')"
_cd "${HOME}"
backup_old() {
OLD_PATH=${1}
if [ ! -d "${THIS_BACKUP}" ]; then
minor_step "Creating a backup folder for old contents: '${THIS_BACKUP}'"
mkdir -p "${THIS_BACKUP}"
fi
minor_step "Moving old ${OLD_PATH} into ${THIS_BACKUP}/${OLD_PATH}"
mv "${OLD_PATH}" "${THIS_BACKUP}/${OLD_PATH}"
continue_if_succeeded
}
create_symlink() {
SYMLINK_TO=${1}
minor_step "${SYMLINK_TO}"
ln -s "${DOTFILES}/${SYMLINK_TO}" "${SYMLINK_TO}"
continue_if_succeeded
}
step "Adding \$PATH into .bash_paths"
echo "export DOTFILES=\"${DOTFILES}\"" >>${DOTFILES}/.bash_paths
echo "export PATH=\"\${DOTFILES}/commands:\$PATH\"" >>${DOTFILES}/.bash_paths
step "Backing up old contents"
for PATH_TO in "${PATHS_TO_PROCESS[@]}"; do
if [ -f "${PATH_TO}" ] || [ -d "${PATH_TO}" ]; then
backup_old "${PATH_TO}"
fi
done
continue_if_succeeded
step "Creating symlinks"
for PATH_TO in "${PATHS_TO_PROCESS[@]}"; do
create_symlink "${PATH_TO}"
done
continue_if_succeeded
_cd "${DOTFILES}"
step "Git assume no change"
git update-index --assume-unchanged "${DOTFILES}"/.ssh/authorized_keys
continue_if_succeeded
step "Copying old 'id_rsa'"
cp "${THIS_BACKUP}"/.ssh/id_rsa "${DOTFILES}"/.ssh/id_rsa
continue_if_succeeded
all_done
info "Remember to re-open terminal!"