-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdotfiles.sh
executable file
·117 lines (94 loc) · 2.99 KB
/
dotfiles.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
#!/bin/bash
set -e
DOTFILES_DIR="$(dirname "$(readlink --canonicalize "$0")")"
install_repositories() {
local changes
local sources_src="$DOTFILES_DIR/ROOT/etc/apt/sources.list.d"
local sources_dst="/etc/apt/sources.list.d"
for file in "$sources_src"/*.list; do
local filename="${file##*/}"
if [ ! -f "$sources_dst/$filename" ]; then
echo "dotfiles: - $filename"
changes=true
sudo cp "$file" "$sources_dst"
fi
done
local keys_src="$DOTFILES_DIR/ROOT/etc/apt/trusted.pub.d"
local keys_dst="/etc/apt/trusted.gpg.d"
for file in "$keys_src"/*.pub; do
local filename="${file##*/}"
local file_dst="$keys_dst/${filename%.*}.gpg"
if [ ! -f "$file_dst" ]; then
echo "dotfiles: - $filename"
changes=true
gpg --dearmor < "$file" \
| sudo tee "$file_dst" \
> /dev/null
fi
done
if [ "$changes" = "true" ]; then
sudo apt-get update --quiet=2
fi
}
install_software() {
local installed
installed=$(
apt list --installed 2> /dev/null \
| cut -d / -f 1 \
| sort --unique
)
local to_install
to_install=$(
comm -13 <(cat <<< "$installed") "$DOTFILES_DIR/software.list"
)
local to_remove
to_remove=$(
comm -12 <(cat <<< "$installed") "$DOTFILES_DIR/software.remove.list"
)
if [ -z "$to_install" ] && [ -z "$to_remove" ]; then
return
fi
echo "dotfiles: - install: $(tr '\n' ' ' <<< $to_install)"
echo "dotfiles: - remove: $(tr '\n' ' ' <<< $to_remove)"
sudo apt-get update --quiet=2
echo $to_remove | xargs sudo apt-get --assume-yes remove
sudo apt-get --assume-yes autoremove
echo $to_install | xargs sudo apt-get --assume-yes install
}
install_configurations() {
local include=". <(cat $HOME/.bashrc.d/*)"
if ! grep --fixed-strings --quiet "$include" "$HOME/.bashrc"; then
echo -e "\n$include" >> "$HOME/.bashrc"
fi
cp --no-target-directory --recursive "$DOTFILES_DIR/HOME" "$HOME"
. <(cat $HOME/.bashrc.d/*)
}
if [ "$1" != "--skip-update" ]; then
# make sure the script itself is update-to-date
echo "dotfiles: update dotfiles"
pushd "$DOTFILES_DIR" > /dev/null
git fetch
if [ "$(git rev-parse master)" == "$(git rev-parse origin/master)" ]; then
echo "dotfiles: already up to date"
exit
fi
git merge --ff-only
popd > /dev/null
# rerun the script which itself may have been updated
exec "$0" --skip-update
fi
echo "dotfiles: install new repositories"
install_repositories
unset -f install_repositories
echo "dotfiles: install new software"
install_software
unset -f install_software
echo "dotfiles: install new configurations"
install_configurations
unset -f install_configurations
echo "dotfiles: run custom scripts"
for script in "$DOTFILES_DIR/custom/"*; do
echo "dotfiles: - ${script##*/}"
bash "$script"
done
echo "dotfiles: all done"