forked from weikinhuang/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·89 lines (77 loc) · 2.65 KB
/
install.sh
File metadata and controls
executable file
·89 lines (77 loc) · 2.65 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
#!/bin/bash
# constants
REMOTE_BASE_URL="https://raw.github.com/weikinhuang/dotfiles/master"
MAX_JOBS=$(grep "^processor" -c /proc/cpuinfo)
# list of files that need to be downloaded
FILES_BASE=".bash_profile,.bashrc,.inputrc"
FILES_DOTENV=".aliases,.completion,.exports,.functions,.prompt"
FILES_DOTENV_OS=".aliases,.completion,.env,.exports,.functions,.prompt"
FILES_DOTENV_BIN="ack,dusort,json,rename"
# Check out which env this bash is running in
DOTENV="linux"
FILES_DOTENV_OS_BIN=""
case "$(uname -s)" in
CYGWIN* )
DOTENV="cygwin"
FILES_DOTENV_OS_BIN="apt-cyg,chattr"
;;
Darwin )
DOTENV="darwin"
FILES_DOTENV_OS_BIN=""
;;
esac
function download_files () {
local dl_list="$1"
local dl_root="$2"
local dl_dest="$3"
# pull down the source files
echo "${dl_list}" | tr ',' '\n' | xargs -I {} -r -P $MAX_JOBS sh -c "\
echo 'Downloading file {} from ${REMOTE_BASE_URL}/${dl_root}/{} => ${dl_dest}/{}'; \
if [ -f '${dl_dest}/{}.bak' ] ; then
rm -f '${dl_dest}/{}.bak'; \
fi; \
if [ -f '${dl_dest}/{}' ] ; then
mv '${dl_dest}/{}' '${dl_dest}/{}.bak'; \
fi; \
if [ -n '${dl_root}' ] ; then
curl -s -o '${dl_dest}/{}' '${REMOTE_BASE_URL}/${dl_root}/{}';
else
curl -s -o '${dl_dest}/{}' '${REMOTE_BASE_URL}/{}';
fi
"
}
function download_apps () {
local dl_list="$1"
local dl_root="$2"
local dl_dest="$3"
# pull down the source files
echo "${dl_list}" | tr ',' '\n' | xargs -I {} -r -P $MAX_JOBS sh -c "\
echo 'Downloading file {} from ${REMOTE_BASE_URL}/${dl_root}/{} => ${dl_dest}/{}'; \
if [ -f '${dl_dest}/{}' ] ; then
rm -f '${dl_dest}/{}'; \
fi; \
curl -s -o '${dl_dest}/{}' '${REMOTE_BASE_URL}/${dl_root}/{}';"
}
# make the directory tree
if [ -d "${HOME}/.dotenv.bak" ] ; then
echo "Deleting: '${HOME}/.dotenv.bak'"
rm -rf "${HOME}/.dotenv.bak"
fi
if [ -d "${HOME}/.dotenv" ] ; then
echo "Moving directory: '${HOME}/.dotenv' to '${HOME}/.dotenv.bak'"
mv "${HOME}/.dotenv" "${HOME}/.dotenv.bak"
fi
echo "Creating directory tree: '${HOME}/.dotenv/bin/'"
mkdir -p "${HOME}/.dotenv/bin/"
echo "Creating directory tree: '${HOME}/.dotenv/${DOTENV}/'"
mkdir -p "${HOME}/.dotenv/${DOTENV}/"
echo "Creating directory tree: '${HOME}/.dotenv/${DOTENV}/bin/'"
mkdir -p "${HOME}/.dotenv/${DOTENV}/bin/"
echo ""
# pull down the source files
download_files "${FILES_BASE}" "" "${HOME}"
download_files "${FILES_DOTENV}" ".dotenv" "${HOME}/.dotenv"
download_files "${FILES_DOTENV_OS}" ".dotenv/${DOTENV}" "${HOME}/.dotenv/${DOTENV}"
download_apps "${FILES_DOTENV_BIN}" ".dotenv/bin" "${HOME}/.dotenv/bin"
download_apps "${FILES_DOTENV_OS_BIN}" ".dotenv/${DOTENV}/bin" "${HOME}/.dotenv/${DOTENV}/bin"
source "${HOME}/.bashrc"