-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
80 lines (72 loc) · 2.31 KB
/
install
File metadata and controls
80 lines (72 loc) · 2.31 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
# Run the following command in your terminal to execute this script!
# bash -c "$(curl -#fL raw.githubusercontent.com/<your github username>/<your dotfiles repo name>/main/install)"
# /install
#!/usr/bin/env bash
LOG="${HOME}/Library/Logs/dotfiles.log"
GITHUB_USER=platocrat
GITHUB_REPO=https://github.com/platocrat/dotfiles-starter-kit
DIR="/usr/local/opt/${GITHUB_REPO} "
# /install
_process() {
echo "$(date) PROCESSING: $@" >> $LOG
printf "$(tput setaf 6) %s...$(tput sgr0)\n" "$@"
}
_success() {
local message=$1
printf "%s✓ Success:%s\n" "$(tput setaf 2)" "$(tput sgr0) $message"
}
# /install
download_dotfiles() {
_process "→ Creating directory at ${DIR} and setting permissions"
mkdir -p "${DIR}"
_process "→ Downloading repository to /tmp directory"
curl -#fLo /tmp/${GITHUB_REPO}.tar.gz "https://github.com/${GITHUB_USER}/${GITHUB_REPO}/tarball/main"
_process "→ Extracting files to ${DIR}"
tar -zxf /tmp/${GITHUB_REPO}.tar.gz --strip-components 1 -C "${DIR}"
_process "→ Removing tarball from /tmp directory"
rm -rf /tmp/${GITHUB_REPO}.tar.gz
[[ $? ]] && _success "${DIR} created, repository downloaded and extracted"
# Change to the dotfiles directory
cd "${DIR}"
}
# /install
link_dotfiles() {
# symlink files to the HOME directory.
if [[ -f "${DIR}/opt/files" ]]; then
_process "→ Symlinking dotfiles in /configs"
# Set variable for list of files
files="${DIR}/opt/files"
# Store IFS separator within a temp variable
OIFS=$IFS
# Set the separator to a carriage return & a new line break
# read in passed-in file and store as an array
IFS=$'\r\n'
links=($(cat "${files}"))
# Loop through array of files
for index in ${!links[*]}
do
for link in ${links[$index]}
do
_process "→ Linking ${links[$index]}"
# set IFS back to space to split string on
IFS=$' '
# create an array of line items
file=(${links[$index]})
# Create symbolic link
ln -fs "${DIR}/${file[0]}" "${HOME}/${file[1]}"
done
# set separater back to carriage return & new line break
IFS=$'\r\n'
done
# Reset IFS back
IFS=$OIFS
source "${HOME}/.bash_profile"
[[ $? ]] && _success "All files have been copied"
fi
}
# /install
install() {
download_dotfiles
link_dotfiles
}
install