-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·168 lines (153 loc) · 3.79 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
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
#!/bin/sh
scope ()
(
# ---------- VARIABLES -----------
script_path="$(dirname "$(readlink -e -- "$0")")"
script_name="$(basename "$0")"
logfile_name=/dev/null
runtime_dependencies="sudo ln sed"
export SUDO_ASKPASS="$(which ssh-askpass)"
unset verbose
unset distname
distname="$(awk -F'=' '/^ID=/ {print tolower($2)}' /etc/*-release)"
# if [ "$distname" = "ubuntu" ]
# then
# elif [ "$distname" = "fedora" ]
# then
# fi
# ---------- ARGPARSE ------------
while getopts 'lv' c
do
case $c in
l) logfile_name="log_${script_name%.*}.txt"; shift ;;
v) verbose=1; shift ;;
--) shift; break ;;
*) echo "[ERROR] unsupported argument: $1"; usage ;;
esac
done
# ---------- FUNCTIONS -----------
usage () {
printf "%b\n" "Usage: $script_name [-v] [-l]"
exit 2
}
hello () {
printf "%b\n" "[INFO] $script_path/$script_name\n$(date -Iseconds)"
printf "%b\n" "Symlink configuration files in appropriate places"
}
log () {
if [ -n "$verbose" ]
then
"$@" | tee -a $logfile_name
else
"$@" >> $logfile_name
fi
}
debug () {
if [ -n "$debug" ]
then
"$@"
fi
}
check_for_app () {
for dep in $@
do
if [ -n "$(which $dep)" ]
then
printf "%b\n" "found $dep"
else
printf "%b\n" "[ERROR] $dep not found, aborting"
exit 2
fi
done
}
trysudo () {
if [ -n "$(getent group sudo | grep -o $USER)" ]
then
if [ -n "$SUDO_ASKPASS" ]
then
sudo -A "$@"
else
read -s -t 30 -p "[sudo] password for $USER: " sudoPW
echo $sudoPW | sudo -S "$@"
unset sudoPW
fi
else
printf "%b\n" "[WARN] $USER has no sudo rights: $@"
fi
}
which_os () {
if [ -r /etc/redhat-release ]
then
distname="fedora"
elif [ -r /etc/os-release ] # or /etc/lsb-release
then
distname="ubuntu"
fi
}
enso () {
# "ensure_softlink"
if [ -h "$2" ]
then
rm "$2"
fi
ln -vs "$1" "$2"
}
# ---------- MAIN ----------------
main () {
hello
check_for_app $runtime_dependencies
# env
enso ~/dotfiles/env/.profile ~/.profile
if [ -z "$(sed -n '/^export my_base/p' ~/dotfiles/env/.profile)" ]
then
sed -i "1i export my_base=\'$script_path\'" ~/dotfiles/env/.profile
fi
enso ~/dotfiles/env/.Xresources ~/.Xresources
# bash
enso ~/dotfiles/bash/.bashrc ~/.bashrc
enso ~/dotfiles/bash/.bash_aliases ~/.bash_aliases
enso ~/dotfiles/bash/.bash_setenv ~/.bash_setenv
enso ~/dotfiles/bash/.inputrc ~/.inputrc
#emacs
enso ~/dotfiles/emacs/init.el ~/.config/emacs/init.el
if [ "$distname" = "fedora" ]
then
#trysudo
sudo ln -vs ~/dotfiles/emacs/site-start.el /usr/share/emacs/site-lisp/site-start.d/site-start.el
elif [ "$distname" = "ubuntu" ]
then
#trysudo
sudo ln -vs ~/dotfiles/emacs/site-start.el /usr/local/share/emacs/site-lisp/site-start.el
fi
# git
enso ~/dotfiles/git/.gitconfig ~/.gitconfig
# i3
enso ~/dotfiles/i3/config ~/.config/i3/config
mkdir -vp ~/.config/i3status
enso ~/dotfiles/i3/i3status/config ~/.config/i3status/config
# mpv
if [ "$distname" = "ubuntu" ]
then
enso ~/dotfiles/mpv/mpv.conf ~/.config/mpv/mpv.conf
fi
# neovim
enso ~/dotfiles/nvim/init.vim ~/.config/nvim/init.vim
# flatpak version
if [ -n "$(which io.neovim.nvim)" ]
then
mkdir -v ~/.var/app/io.neovim.nvim/config/nvim
enso ~/dotfiles/nvim/init.vim ~/.var/app/io.neovim.nvim/config/nvim/init.vim
# note that nvim plugin manager junegunn/vim-plug uses ~/.local/share/nvim/ to put plugins
# but the flatpak version needs them in ~/.var/app/io.neovim.nvim/data/nvim
fi
# vim
enso ~/dotfiles/vim/.vimrc ~/.vimrc
# mail
# mkdir -v ~/.config/offlineimap
enso ~/dotfiles/mail/.offlineimaprc ~/.config/offlineimap/config
printf "%b\n" ""
}
log main $@
)
scope $@
# ---------- COMMENTS ------------