-
Notifications
You must be signed in to change notification settings - Fork 0
/
20_ubuntu_apt.sh
156 lines (134 loc) · 4.08 KB
/
20_ubuntu_apt.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
# Ubuntu-only stuff. Abort if not Ubuntu.
is_ubuntu || return 1
apt_keys=()
apt_source_files=()
apt_source_texts=()
apt_packages=()
deb_installed=()
deb_sources=()
installers_path="$DOTFILES/caches/installers"
# Ubuntu distro release name, eg. "xenial"
release_name=$(lsb_release -c | awk '{print $2}')
function add_ppa() {
apt_source_texts+=($1)
IFS=':/' eval 'local parts=($1)'
apt_source_files+=("${parts[1]}-ubuntu-${parts[2]}-$release_name")
}
#############################
# WHAT DO WE NEED TO INSTALL?
#############################
# Misc.
apt_packages+=(
build-essential
curl
git-core
htop
sl
vim
zsh
thefuck
ruby-full
neovim
tree
keychain
docker.io
)
# https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-ansible-on-ubuntu-16-04
# add_ppa ppa:ansible/ansible
# apt_packages+=(ansible)
add_ppa ppa:jgmath2000/et
apt_packages+=(et)
# debs
deb_installed+=(/usr/bin/bat)
deb_sources+=(https://github.com/sharkdp/bat/releases/download/v0.12.1/bat_0.12.1_amd64.deb)
####################
# ACTUALLY DO THINGS
####################
# Add APT keys.
# keys_cache=$DOTFILES/caches/init/apt_keys
# IFS=$'\n' GLOBIGNORE='*' command eval 'setdiff_cur=($(<$keys_cache))'
# setdiff_new=("${apt_keys[@]}"); setdiff; apt_keys=("${setdiff_out[@]}")
# unset setdiff_new setdiff_cur setdiff_out
# if (( ${#apt_keys[@]} > 0 )); then
# e_header "Adding APT keys (${#apt_keys[@]})"
# for key in "${apt_keys[@]}"; do
# e_arrow "$key"
# if [[ "$key" =~ -- ]]; then
# sudo apt-key adv $key
# else
# wget -qO- $key | sudo apt-key add -
# fi && \
# echo "$key" >> $keys_cache
# done
# fi
# Add APT sources.
function __temp() { [[ ! -e /etc/apt/sources.list.d/$1.list ]]; }
source_i=($(array_filter_i apt_source_files __temp))
if (( ${#source_i[@]} > 0 )); then
e_header "Adding APT sources (${#source_i[@]})"
for i in "${source_i[@]}"; do
source_file=${apt_source_files[i]}
source_text=${apt_source_texts[i]}
if [[ "$source_text" =~ ppa: ]]; then
e_arrow "$source_text"
sudo add-apt-repository -y $source_text
else
e_arrow "$source_file"
sudo sh -c "echo '$source_text' > /etc/apt/sources.list.d/$source_file.list"
fi
done
fi
# Update APT.
e_header "Updating APT"
sudo apt-get -qq update
# Only do a dist-upgrade on initial install, otherwise do an upgrade.
e_header "Upgrading APT"
# if is_dotfiles_bin; then
sudo apt-get -qy upgrade
# else
# sudo apt-get -qy dist-upgrade
# fi
# Install APT packages.
installed_apt_packages="$(dpkg --get-selections | grep -v deinstall | awk 'BEGIN{FS="[\t:]"}{print $1}' | uniq)"
apt_packages=($(setdiff "${apt_packages[*]}" "$installed_apt_packages"))
if (( ${#apt_packages[@]} > 0 )); then
e_header "Installing APT packages (${#apt_packages[@]})"
for package in "${apt_packages[@]}"; do
e_arrow "$package"
[[ "$(type -t preinstall_$package)" == function ]] && preinstall_$package
sudo apt-get -qq install "$package" && \
[[ "$(type -t postinstall_$package)" == function ]] && postinstall_$package
done
fi
# Install debs via dpkg
function __temp() { [[ ! -e "$1" ]]; }
deb_installed_i=($(array_filter_i deb_installed __temp))
if (( ${#deb_installed_i[@]} > 0 )); then
mkdir -p "$installers_path"
e_header "Installing debs (${#deb_installed_i[@]})"
for i in "${deb_installed_i[@]}"; do
e_arrow "${deb_installed[i]}"
deb="${deb_sources[i]}"
[[ "$(type -t "$deb")" == function ]] && deb="$($deb)"
installer_file="$installers_path/$(echo "$deb" | sed 's#.*/##')"
wget -O "$installer_file" "$deb"
sudo dpkg -i "$installer_file"
done
fi
# install bins from zip file
function install_from_zip() {
local name=$1 url=$2 bins b zip tmp
shift 2; bins=("$@"); [[ "${#bins[@]}" == 0 ]] && bins=($name)
if [[ ! "$(which $name)" ]]; then
mkdir -p "$installers_path"
e_header "Installing $name"
zip="$installers_path/$(echo "$url" | sed 's#.*/##')"
wget -O "$zip" "$url"
tmp=$(mktemp -d)
unzip "$zip" -d "$tmp"
for b in "${bins[@]}"; do
sudo cp "$tmp/$b" "/usr/local/bin/$(basename $b)"
done
rm -rf $tmp
fi
}