-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·180 lines (161 loc) · 5.03 KB
/
install.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
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
#!/usr/bin/env bash
trap 'echo "Error happened. Exiting script."; exit' ERR
add_ppa_unique() {
for i in "$@"; do
if ! grep -h "^deb.*$i" /etc/apt/sources.list.d/* >/dev/null 2>&1; then
echo "Adding ppa:$i"
# -n for not updating
sudo add-apt-repository -n -y "ppa:$i"
else
echo "ppa:$i already exists"
fi
done
}
# Check if content of folderes or files are the same
is_same() {
if [ "$(diff -r "$(eval echo $1)" $(eval echo $2))" ]; then
false
else
true
fi
}
# Prevent redundantly echong to a file
try_echo() {
if [ $# -ne 2 ]; then
echo "Wrong input of function ${FUNCNAME[0]}"
return
fi
if grep -Fxq "$1" "$(eval echo $2)" &>/dev/null; then
return
fi
echo "$1" >>"$(eval echo $2)"
}
# Get user confirmation in console
confirm() {
while true; do
read -p "Continue (y/n)?" choice
case "$choice" in
y | Y)
echo "yes"
break
;;
n | N)
echo "no"
break
;;
*) ;;
esac
done
}
# Create a softlink to the folder under .config
create_soft_link() {
src=$(eval echo "$1")
dest=$(eval echo "$2")
# Check if the src folder exists
if [ ! -d "${src}" ]; then
echo -e "\n ${src} does not exist."
return
fi
if [ ! -d "${dest}" ]; then
ln -sT "${src}" "${dest}"
echo -e "Soft link of ${src} has been created at ${dest}"
elif is_same "${src}" "${dest}"; then
echo -e "A same ${dest} already exists. SKIP."
else
echo -e "\nA different ${dest} already exists. Do you want to overwrite it?"
case "$(confirm)" in
"yes")
cp -rf "${dest}" /tmp
rm -r "${dest}"
ln -sT "${src}" "${dest}"
echo "${dest} has been moved to /tmp"
echo "Soft link of ${src} has been created at ${dest}"
;;
"no") echo "${dest} is left untouched" ;;
esac
fi
}
install_soft_link() {
name=$1
src="${HOME}/.dotfiles/${name}"
dest="${2:-${HOME}/${name}}"
create_soft_link "${src}" "${dest}"
}
# Add PPAs
add_ppa_unique kgilmer/speed-ricer
add_ppa_unique fish-shell/release-3
sudo apt -qq update
# Install i3wm dependencies
echo ""
sudo apt -qq install git curl fish i3-gaps i3status i3blocks i3lock xautolock suckless-tools arandr dunst xclip mps-youtube zathura sxiv entr feh fonts-font-awesome w3m-img python3-pip scrot byzanz udiskie fcitx-googlepinyin yad xdotool neofetch python3-tk xcompmgr brightnessctl tmate playerctl
echo ""
pip3 install --user ranger-fm youtube-dl pygments gdbgui
echo ""
sudo snap install peco
echo ""
# Install kitty terminal emulator locally
if [ ! "$(command -v kitty)" ]; then
curl -L https://sw.kovidgoyal.net/kitty/installer.sh | sh /dev/stdin
ln -svf ~/.local/kitty.app/bin/kitty ~/.local/bin/
sudo update-alternatives --install /usr/bin/x-terminal-emulator x-terminal-emulator ~/.local/kitty.app/bin/kitty 50
sudo update-alternatives --set x-terminal-emulator ~/.local/kitty.app/bin/kitty
fi
# Install rust
curl https://sh.rustup.rs -sSf | sh
# Install rclone
curl https://rclone.org/install.sh | sudo bash || :
# Install fonts
curl -L https://github.com/hbin/top-programming-fonts/raw/master/install.sh | bash
# #---Install i3wm config---# #
if [ ! -d "$(eval echo "${HOME}/.config")" ]; then
mkdir -p ~/.config
echo "Folder .config is created under ~/"
fi
# Download dotfiles from github
if [ ! -d "$(eval echo "${HOME}/.dotfiles")" ]; then
git clone https://github.com/Maverobot/dotfiles.git ~/.dotfiles
cd ~/.dotfiles || exit
git submodule update --init --recursive
else
echo "The folder ~/.dotfiles already exists."
cd ~/.dotfiles || exit
git pull
git submodule update --init --recursive
fi
install_soft_link ".config/i3"
install_soft_link ".config/systemd"
install_soft_link ".config/ranger"
install_soft_link ".config/dunst"
install_soft_link ".config/kitty"
install_soft_link ".config/fish"
install_soft_link ".config/rofi"
install_soft_link ".config/udiskie"
install_soft_link ".scripts"
install_soft_link "org" "${HOME}/org/home"
systemctl enable --user emacs
systemctl enable --user auto_lock_screen
systemctl enable --user udiskie
systemctl start --user emacs
systemctl start --user auto_lock_screen
systemctl start --user udiskie
# Setup nmcli aliases
try_echo "alias wifi='nmcli device wifi'" "${HOME}/.bash_aliases"
try_echo "alias network='nmcli device'" "${HOME}/.bash_aliases"
# Setup emacsclient (terminal) with alias: vi (short for evil, vim-style)
try_echo "alias vi='emacsclient -t'" "${HOME}/.bash_aliases"
# Setup emacsclient (gui) with alias: emacs (for emacs, gui-style)
try_echo "alias emacs='emacsclient -nc'" "${HOME}/.bash_aliases"
# Add GOPATH to PATH
try_echo 'export GOPATH="${HOME}/go"' "${HOME}/.profile"
try_echo 'export PATH="$PATH:$GOPATH/bin"' "${HOME}/.profile"
# Add .script to PATH
try_echo 'export PATH="$PATH:$HOME/.scripts"' "${HOME}/.profile"
# Add ~/.local/bin to PATH
try_echo 'export PATH="$PATH:$HOME/.local/bin"' "${HOME}/.profile"
# Add force 256 corlor
try_echo 'export TERM=xterm-256color' "${HOME}/.bashrc"
# Enable vim mode in bash and show insert/normal mode
try_echo 'set -o vi' "${HOME}/.bashrc"
try_echo "$(cat ~/.dotfiles/.config/.inputrc)" "${HOME}/.inputrc"
# Allow cd into directory by merely typing the name
try_echo 'shopt -s autocd' "${HOME}/.bashrc"