-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup.sh
executable file
·128 lines (105 loc) · 3.76 KB
/
setup.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
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
#!/bin/bash
cd $(dirname $0)
# If the path is under HOME, then make it relative
PATH_TO_ETC=${PWD/$HOME\//}
ETC_HOME=${PWD/$HOME\//\$HOME\/}
TILDE_ETC_HOME=${PWD/$HOME\//~\/}
CONFIG_HOME=${XDG_CONFIG_HOME-$HOME/.config}
if [ "$PATH_TO_ETC" != "projects/etc" ]; then
SET_ETC_HOME="ETC_HOME=\"$ETC_HOME\""
SOURCE_PREFIX="\$ETC_HOME"
else
SET_ETC_HOME=""
# Use ETC_HOME as the source prefix because the shell may be coming up in
# a directory other than home. This is common in Fedora, where a new
# terminal will start you in the current working directory.
SOURCE_PREFIX="$ETC_HOME"
fi
# Record the date and time for backups
save_date=$(date "+%Y%m%d-%H%M%S")
_backupFile() {
local origFile="$1"
local newFile="$origFile.$save_date"
test -e "$origFile" &&
mv "$origFile" "$newFile" &&
echo "Saved old '$origFile' as '$newFile'"
return 0
}
_maybeInstall() {
local s="$1"
local file="$2"
local base=$(basename "${file}")
echo "Checking ${base}..."
(test -e "$file" && grep -F -x -q "${s}" "$file") ||
(_backupFile "$file" &&
((test -n "$SET_ETC_HOME" && echo "$SET_ETC_HOME" > "$file") ||
: > "$file") &&
echo "$s" >> "$file" &&
echo "Installed $base")
return 0
}
_installLink() {
local name
name="$(basename "$1")"
[[ -n "$3" ]] && name="$3"
echo "Checking $name..."
test ! -e "$1" && \
ln -s "$PATH_TO_ETC/$2" "$1" &&
echo "Installed $name"
}
# Set up links to configuration bits
_installLink "$HOME/.agignore" ag/agignore
_installLink "$HOME/.inputrc" inputrc/inputrc
_installLink "$HOME/.tmux.conf" tmux/tmux.conf
_installLink "$HOME/.quiltrc" quilt/quiltrc
_installLink "$HOME/.colordiffrc" colordiffrc/colordiffrc
_installLink "$HOME/.ctags" ctags/ctags
_installLink "$HOME/.rpmmacros" rpm/rpmmacros
_installLink "$HOME/.wgetrc" wgetrc/wgetrc
echo "Checking .gitconfig..."
test ! -e "$HOME/.gitconfig" &&
echo "\
[include]
path = $TILDE_ETC_HOME/gitconfig/gitconfig
[core]
excludesfile = $TILDE_ETC_HOME/gitconfig/gitignores
" > "$HOME/.gitconfig" &&
echo "Installed .gitconfig" &&
echo 'Run the following to set the git user name:
git config --global user.name "User Name"' &&
echo 'Run the following to set the git user email:
git config --global user.email "[email protected]"'
echo "Checking .gituser..."
test \( ! -e "$HOME/.gituser" \) -a -e "$ETC_HOME/user/$ETC_USER/gitconfig" &&
_installLink "$HOME/.gituser" "$ETC_HOME/user/$ETC_USER/gitconfig"
echo "Checking svnwrap config..."
test ! -e "$CONFIG_HOME/svnwrap/config.ini" &&
mkdir -p "$CONFIG_HOME/svnwrap" &&
cp "svnwrap/config.ini" "$CONFIG_HOME/svnwrap/config.ini" &&
echo "Installed svnwrap config"
echo "Checking wezterm config..."
test ! -e "$CONFIG_HOME/wezterm/wezterm.lua" &&
mkdir -p "$CONFIG_HOME/wezterm" &&
_installLink "$CONFIG_HOME/wezterm/wezterm.lua" "$ETC_HOME/wezterm/wezterm.lua" &&
echo "Installed wezterm config"
if [ "$(uname)" == "Darwin" ]; then
_installLink "$HOME/.editrc" editrc/editrc
mkdir -p $HOME/Library/Fonts &&
cp fonts/*.ttf $HOME/Library/Fonts &&
echo "Installed custom fonts"
fi
if [ "$(uname)" == "Linux" ]; then
mkdir -p $HOME/.fonts &&
cp fonts/*.ttf $HOME/.fonts &&
echo "Installed custom fonts"
fi
if [ "$(uname)" == "Darwin" ]; then
# Under Mac OS X, it opens login shells, and the default /etc/bashrc doesn't
# source the user's ~/.bashrc.
if ! test -r "$HOME/.bash_profile"; then
echo '[ -r ~/.bashrc ] && . ~/.bashrc' > ~/.bash_profile
fi
fi
_maybeInstall ". \"$SOURCE_PREFIX/bash/bashrc\"" "$HOME/.bashrc"
_maybeInstall ". \"$SOURCE_PREFIX/zsh/zshenv\"" "$HOME/.zshenv"
_maybeInstall ". \"$SOURCE_PREFIX/zsh/zshrc\"" "$HOME/.zshrc"