-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.sh
More file actions
189 lines (164 loc) · 3.81 KB
/
setup.sh
File metadata and controls
189 lines (164 loc) · 3.81 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
set -e
if [[ `id -u` != 0 ]]
then
echo "you are not root, how the hell do you think you can setup?"
exit -1
fi
if [[ $# != 1 ]]
then
echo "Usage: $0 <user>"
exit -1
fi
USER="$1"
HOME_DIR="/home/$USER"
SCRIPT_RELATIVE_DIR=$(dirname "${BASH_SOURCE[0]}")
cwd=$(pwd)
cd "$SCRIPT_RELATIVE_DIR"
PROJ_DIR=$(pwd)
cd "$cwd"
CONFIGS_DIR="$PROJ_DIR/configs"
SCRIPTS_DIR="$PROJ_DIR/scripts"
save_dir()
{
local old_pwd="$(pwd)"
func="$1"
shift
eval "$func" $@
cd "$old_pwd"
}
confirm()
{
message="$1"
shift
default="$1"
shift
func="$1"
shift
if [[ "$default" == y ]]
then
do_it=1
default="[Yn]"
elif [[ "$default" == n ]]
then
do_it=0
default="[yN]"
else
do_it=0
default=
fi
echo -n "$message $default: "
read response
if [[ ! -z "$response" ]]
then
if [ "$response" = "y" -o "$response" = "Y" ]
then
do_it=1
else
do_it=0
fi
fi
if [[ "$do_it" == 1 ]]
then
eval "$func" $@
fi
}
fast_install()
{
apt-get --install-suggests -y --show-progress install $@
}
fast_purge()
{
apt-get --install-suggests -y --show-progress purge $@
}
install_git()
{
# cannot runit is shit for git in ubuntu 16.04, we must use the sysvinit instead
fast_purge runit
fast_purge git-all
fast_purge git
apt-get autoremove
apt-get update
fast_install git-daemon-sysvinit
fast_install git
}
config_git()
{
git config --global "alias.st" status
git config --global "alias.br" branch
git config --global "alias.co" checkout
ln -sf "$CONFIGS_DIR/git-completion.bash" "$HOME_DIR/git.autocompletion"
ln -sf "$CONFIGS_DIR/global_gitignore" "$HOME_DIR/.global_gitignore"
git config --global core.excludesfile "$HOME_DIR/.global_gitignore"
echo "enter global git user: "
read user
echo "enter global git mail: "
read mail
git config --global user.name "$user"
git config --global user.email "$mail"
}
install_fix_display()
{
path="$SCRIPTS_DIR/fix_display.sh"
echo "@reboot bash $path 3840x2160 2>&1 >> $HOME_DIR/fix_display.log" >> "/var/spool/cron/crontabs/$USER"
chown "$USER:crontab" "/var/spool/cron/crontabs/$USER"
}
install_rc()
{
bashrc="$SCRIPTS_DIR/bashrc"
vimrc="$SCRIPTS_DIR/vimrc"
pythonrc="$SCRIPTS_DIR/pythonrc"
ln -sf "$bashrc" "$HOME_DIR/.bashrc"
ln -sf "$vimrc" "$HOME_DIR/.vimrc"
ln -sf "$pythonrc" "$HOME_DIR/.pythonrc"
}
install_packages()
{
for repo in $(cat "$CONFIGS_DIR/repositories.txt")
do
echo "adding $repo"
add-apt-repository "$repo"
done
apt-get update
for package in $(cat "$CONFIGS_DIR/install_packages.txt")
do
echo "installing $package"
fast_install "$package"
done
}
clone_project()
{
git clone "$1"
chown -R "$USER:$USER" $(echo $(basename "$1") | cut -f1 -d'.')
if [ ! -z "$2" ]
then
save_dir "$2"
fi
}
clone_projects()
{
cd "$HOME/projects"
declare -a repos
readarray -t repos < "$CONFIGS_DIR/git_repositories.txt"
for repo in "${repos[@]}"
do
post_script=$(echo "$repo" | cut -s -f2 -d" ")
repo=$(echo "$repo" | cut -f1 -d" ")
confirm "> clone $repo?" "n" clone_project "$repo" "$post_script"
done
}
tmux_config()
{
cd
ln -sf projects/.tmux/.tmux.conf
cp projects/.tmux/.tmux.conf.local .
}
commacd_config()
{
curl -sL https://github.com/shyiko/commacd/raw/v0.4.0/commacd.bash -o commacd/.commacd.bash
}
confirm "install rc files?" "n" install_rc
confirm "install git?" "n" install_git
confirm "config git?" "n" config_git
confirm "install fix display?" "n" install_fix_display
confirm "install packages?" "n" install_packages
confirm "clone projects?" "n" save_dir clone_projects