-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·154 lines (125 loc) · 3.62 KB
/
bootstrap.sh
File metadata and controls
executable file
·154 lines (125 loc) · 3.62 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/bin/bash
#
# BOOTSTRAP
#
# Install and update:
# bash <(curl -L https://raw.github.com/japboy/dotfiles/master/bootstrap.sh)
#
# Install and update without Git
# curl -L https://github.com/japboy/dotfiles/archive/master.tar.gz | tar zxvf - -C ~/.dotfiles
# bash ~/.dotfiles/bootstrap.sh sync
##
# Variables
OS=$(uname -a)
CWD=$(pwd)
TEXT_BOLD=$(tput bold)
TEXT_RED=$(tput setaf 1)
TEXT_GREEN=$(tput setaf 2)
TEXT_RESET=$(tput sgr0)
DOTFILES_REPO='https://github.com/japboy/dotfiles.git'
DOTFILES_PATH="${HOME}/.dotfiles"
##
# Functions
# Link dotfiles to home directory
function make_link {
TARGET_PARENT=${1}
if [ -z "${TARGET_PARENT}" ]
then
echo "${TEXT_RED}Link source path required. Aborted.${TEXT_RESET}"
unset TARGET_PARENT
exit 1
fi
find "${DOTFILES_PATH}/${TARGET_PARENT}" -type f \
-not -name '.DS_Store' | \
grep --invert-match --regexp='\/Services\/.*\.workflow\/' |
{
while read ACTUAL_PATH
do
TARGET_PATH=".${ACTUAL_PATH##${DOTFILES_PATH}/${TARGET_PARENT}}"
[ ! -d "${TARGET_PATH%/*}" ] && mkdir -p "${TARGET_PATH%/*}"
[ -f "${TARGET_PATH}" -a ! -L "${TARGET_PATH}" ] && mv "${TARGET_PATH}" "${TARGET_PATH}.orig"
if [ ! -e "${TARGET_PATH}" ]
then
ln -s "${ACTUAL_PATH}" "${TARGET_PATH}"
echo "Symlink created: ${TARGET_PATH}"
fi
unset ACTUAL_PATH TARGET_PATH
done
}
unset TARGET_PARENT
}
##
# Main process
echo "${TEXT_BOLD}Starting...${TEXT_RESET}"
# Skip fetching from Git if run with `sync` parameter
if [ -z "${1}" ] || [ 'sync' != ${1} ]
then
echo "${TEXT_BOLD}Fetching files from Git repository...${TEXT_RESET}"
# Check if `git` command available or not
if ! which git &> /dev/null
then
echo "${TEXT_RED}Git command not found. Aborted.${TEXT_RESET}"
exit 1
fi
# Check if `~/.dotfiles` exists or not
if [ ! -d ${DOTFILES_PATH} ]
then
git clone --recursive ${DOTFILES_REPO} ${DOTFILES_PATH}
elif [ -d ${DOTFILES_PATH}/.git ]
then
cd ${DOTFILES_PATH}
git pull --ff origin master
git submodule update --recursive
cd ${CWD}
else
echo "${TEXT_RED}Destination path already exists. Aborted.${TEXT_RESET}"
exit 1
fi
fi
# Setup macOS environment
if [[ ${OS} =~ Darwin ]]
then
echo "${TEXT_BOLD}Installing for macOS...${TEXT_RESET}"
# Run `bootstrap-darwin.sh`
if ! zsh ${DOTFILES_PATH}/bootstrap-darwin.sh
then
echo "${TEXT_RED}Error occurred. Aborted.${TEXT_RESET}"
exit 1
fi
make_link 'darwin'
fi
# Setup Linux environment
if [[ 'Linux' = ${OS} ]]
then
echo "${TEXT_BOLD}Installing for Linux...${TEXT_RESET}"
make_link 'linux'
fi
# Setup common environment
echo "${TEXT_BOLD}Installing for common environment...${TEXT_RESET}"
make_link 'common'
# Initialise Git settings
if [ -z "$(git config --global user.name)" ]
then
read -p "${TEXT_BOLD}Enter Git user.name:${TEXT_RESET} " GIT_CONFIG_USER_NAME
git config --global user.name "${GIT_CONFIG_USER_NAME}"
unset GIT_CONFIG_USER_NAME
fi
if ! echo $(git config --global user.email) | grep -q '^.*@.*\..*$'
then
read -p "${TEXT_BOLD}Enter Git user.email:${TEXT_RESET} " GIT_CONFIG_USER_EMAIL
git config --global user.email "${GIT_CONFIG_USER_EMAIL}"
unset GIT_CONFIG_USER_EMAIL
fi
echo 'Git settings update.'
# Finish
echo "${TEXT_BOLD}${TEXT_GREEN}All done.${TEXT_RESET}"
unset \
OS \
CWD \
TEXT_BOLD \
TEXT_RED \
TEXT_GREEN \
TEXT_RESET \
DOTFILES_REPO \
DOTFILES_PATH
unset -f make_link