-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·120 lines (101 loc) · 2.42 KB
/
bootstrap.sh
File metadata and controls
executable file
·120 lines (101 loc) · 2.42 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
118
119
#!/bin/bash
# Source: https://github.com/CuriousLearner/dotfiles
# Colors
function echoY() {
prompt="$1"
echo -e -n "\033[32m$prompt"
echo -e -n '\033[0m'
echo ''
}
function echoR() {
prompt="$1"
echo -e -n "\033[31m$prompt"
echo -e -n '\033[0m'
echo ''
}
function echoB() {
prompt="$1"
echo -e -n "\033[34m$prompt"
echo -e -n '\033[0m'
echo ''
}
# Get file list
function getFilesInDir() {
ls -lah | awk '{
if ($9 != "" && $9 != "." && $9 != ".." && $9 != ".git" && $9 != ".DS_Store" && $9 != ".gitmodules" && $9 != "README.md" && $9 != "bootstrap.sh" && $9 != "setup" && $9 != ".private" && $9 != ".ssh" && $9 != "bin")
print $9
}'
}
# Set vars
FILES=$(getFilesInDir)
CURRENTPATH=$(pwd)
FORCE=false
# Change value of FORCE
if [ "$1" == "--force" ]; then
FORCE=true
fi
function createSymlinks() {
# Avoid double-quotes in `${FILES[@]}` as it is posing some weird behavior.
# shellcheck disable=SC2068
for F in ${FILES[@]}; do
# Delete files if --force was used
if [ "$FORCE" == true ]; then
TIME=$(date +%s)
echoR "--> [BACKUP]: $HOME/${F}"
mv "$HOME/$F" "$HOME/$F.$TIME.bak"
fi
# Make symlink
echoY "--> [LINK]: ${HOME}/${F} -> ${CURRENTPATH}/${F}"
ln -s "$CURRENTPATH/$F" "$HOME/$F"
if [ $? -eq 1 ]; then
echo
echoR "--> [ERROR]: You already have a file named ${F} in your home folder."
echoR " Please backup of your old files."
echoR " Using \"--force\" will allow you to overwrite your existing files."
echo
break
fi
done
}
# Run
createSymlinks
## Install custom binary utilities
if [ ! -d "$HOME/.bin" ]; then
mkdir "$HOME/.bin"
fi
# Symlink binaries
ln -sf "$PWD/bin/"* "$HOME/.bin/"
declare -a BINARIES=(
'batcharge.py'
'crlf.sh'
'eachdir'
'fix-newline-eof'
'git-archive-all'
'git-flake8'
'git-icdiff'
'git-open'
'gitio'
'gravatar'
'hr'
'icdiff'
'push'
'splash'
'tags'
'tweet'
)
for i in "${BINARIES[@]}"; do
echo "Changing access permissions for binary script :: ${i##*/}"
chmod +x "$HOME/.bin/${i##*/}"
done
echo "Binaries installed"
echo
echoB "--> [DONE]"
echo
unset echoY
unset echoR
unset echoB
unset getFilesInDir
unset createSymlinks
unset BINARIES
# shellcheck disable=SC1090
source ~/.zshrc