-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·182 lines (151 loc) · 3.73 KB
/
install
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
#!/usr/bin/env bash
#
# Configuration
#
LINK_FROM=$HOME
LINK_TO=$(pwd)
LINK_MODE=link
PACKAGES=(git vim vim-nox vim-gtk3 tree htop psmisc tmux curl wget nmap)
PACKAGES+=(colordiff apt-file autoconf automake libssl-dev libncurses5-dev)
PACKAGES+=(audacious id3v2 mplayer vlc irssi direnv jq httpie sysstat iotop)
PACKAGES+=(cmus docker.io docker-compose inotify-tools tree net-tools fzf)
#
# Helper functions
#
extract_arg_value() {
echo $1 | sed 's/^[-a-zA-Z0-9]*=//'
}
extract_arg_name() {
echo $1 | sed -e 's/^\([-a-zA-Z0-9]*\)=.*/\1/'
}
package_installed() {
dpkg --list | grep "\b$1\b" &> /dev/null
}
command_exists() {
builtin type -p $1 &> /dev/null
}
#
# Extract arguments
#
for arg in "$@"
do
case $arg in
-f=*|--from=*)
LINK_FROM=$(extract_arg_value $arg)
;;
-m=*|--mode=*)
LINK_MODE=$(extract_arg_value $arg)
;;
*)
echo "ERROR: Unable to handle argument: $(extract_arg_name $arg)"
exit 1
esac
done
#
# Validate arguments
#
if [ ! -d "$LINK_FROM" ]; then
echo "ERROR: Invalid link from given. Must be a valid directory."
exit 1
fi
if [ "$LINK_MODE" != "link" ] && [ "$LINK_MODE" != "copy" ]; then
echo "ERROR: Invalid link mode given. Must either be 'link' or 'copy'."
exit 1
fi
#
# Install packages
#
MISSING=()
for PACKAGE in "${PACKAGES[@]}"
do
if ! package_installed $PACKAGE ; then
MISSING+=($PACKAGE)
fi
done
if [ "${#MISSING[@]}" -gt 0 ]; then
echo ">> Installing missing packages: ${MISSING[@]}"
sudo apt-get update
sudo apt-get --no-install-recommends install --yes ${MISSING[@]}
fi
if ! command_exists asdf ; then
echo ">> Install asdf (Extendable Version Manager)"
git clone https://github.com/asdf-vm/asdf.git ~/.asdf
pushd ~/.asdf
git checkout "$(git describe --abbrev=0 --tags)"
popd
# TODO: Install `erlang`
# TODO: Install `elixir`
# TODO: Install `python`
fi
if ! command_exists scdl ; then
echo ">> Install scdl (Soundcloud Downloader)"
pip3 install --upgrade scdl
fi
if ! command_exists youtube-dl ; then
echo ">> Install youtube-dl (Youtube Downloader)"
pip3 install --upgrade youtube-dl
fi
# TODO: Run `asdf reshim`
if ! command_exists calc ; then
echo ">> Install calc (Minimalistic calculator)"
sudo ./install-calc
fi
#
# Link all dotfiles from the current directory
#
echo ">> Creating all symlinks"
for dir in $(ls -a1); do
# Skip "." and ".."
if [ "${dir}" == "." ] || [ "${dir}" == ".." ]; then
continue
fi
# Skip all "normal" (non hidden) files
if [ "${dir:0:1}" != "." ]; then
continue
fi
# Skip some git files that are specific to this repository
if [ "${dir}" == ".git" ] \
|| [ "${dir}" == ".gitmodules" ] \
|| [ "${dir}" == ".gitignore" ] \
|| [ "${dir}" == ".gitattributes" ]; then
continue
fi
if [ "${dir}" == ".dpkg.cfg" ]; then
if [ -f /etc/os-release ]; then
OS_ID=`cat /etc/os-release | grep "ID=" | sed "s/ID=//"`
if [ "${OS_ID}" != "ubuntu" ]; then
continue;
fi
elif [ -f /etc/debian_version ]; then
continue;
fi
fi
FILE_LINK_FROM="${LINK_FROM}/${dir}"
FILE_LINK_TO="${LINK_TO}/${dir}"
rm -rf "${FILE_LINK_FROM}"
if [ "$LINK_MODE" == "copy" ]; then
echo "Copy: $FILE_LINK_FROM --> $FILE_LINK_TO"
cp -R "${FILE_LINK_FROM}" "${FILE_LINK_TO}"
else
echo "Symlink: $FILE_LINK_FROM --> $FILE_LINK_TO"
ln -s "${FILE_LINK_TO}" "${FILE_LINK_FROM}"
fi
done
#
# Install GNOME settings
#
if command_exists gsettings ; then
echo ">> Installing GNOME settings"
./install-gnome-settings
fi
#
# Install GConf settings
#
if command_exists "gconftool-2" ; then
echo ">> Installig GConf settings"
./install-gconf-settings
fi
#
# Done! :D
#
echo ">> Done"