-
Notifications
You must be signed in to change notification settings - Fork 9
/
distro_install.sh
executable file
·91 lines (78 loc) · 2.54 KB
/
distro_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
#!/bin/bash
# ============================================================
# Install pkgs from distro with some bootstraping supports.
# List cmd[,pkg] as args.
# ============================================================
set -e
libs="$*"
. <(sed 's/^\(..*\)/export DISTRO_\1/' '/etc/os-release')
# Add distro-specific libs.
case "$DISTRO_ID-$DISTRO_VERSION_ID" in
'centos-7' | 'rhel-7')
libs="which,which dnf,nextgen-yum4 dnf,dnf-plugins-core $libs"
;;
'centos-'* | 'fedora-'* | 'rhel-'* | 'scientific-'*)
libs="which,which $libs"
;;
esac
libs="sudo,sudo $libs"
# Scan for missing libs.
# Known issues:
# - CentOS docker does not have which pre-installed.
pkgs=''
for pkg in $libs; do
which "$(cut -d, -f1 <<< "$pkg")" >/dev/null 2>&1 || pkgs="$pkgs $(cut -d, -f2 <<< "$pkg,$pkg")"
done
[ "$pkgs" ] || exit 0
# Pull distro repo.
case "$DISTRO_ID" in
'alpine')
$(! which sudo >/dev/null || echo sudo) apk update
;;
'centos' | 'fedora' | 'rhel' | 'scientific')
$(! which sudo >/dev/null || echo sudo) which dnf >/dev/null 2>&1 && dnf makecache -y || $(! which sudo >/dev/null || echo sudo) yum makecache -y
;;
'debian' | 'linuxmint' | 'ubuntu')
$(! which sudo >/dev/null || echo sudo) apt-get -o 'DPkg::Lock::Timeout=3600' update -y
;;
esac
# Install libs.
if ! which sudo; then
case "$DISTRO_ID" in
'alpine')
apk add sudo
;;
'centos' | 'fedora' | 'rhel' | 'scientific')
which dnf >/dev/null 2>&1 && dnf install -y sudo || yum install -y sudo
;;
'debian' | 'linuxmint' | 'ubuntu')
DEBIAN_FRONTEND=noninteractive apt-get -o 'DPkg::Lock::Timeout=3600' install -y sudo
;;
esac
fi
case "$DISTRO_ID" in
'alpine')
for pkg in $pkgs; do
sudo apk add "$pkg"
done
sudo rm -rf /var/cache/apk
;;
'centos' | 'fedora' | 'rhel' | 'scientific')
for pkg in $pkgs; do
which dnf >/dev/null 2>&1 && sudo dnf install -y "$pkg" || sudo yum install -y "$pkg"
done
sudo which dnf >/dev/null 2>&1 && sudo dnf autoremove -y || sudo yum autoremove -y
! sudo which dnf >/dev/null 2>&1 || sudo dnf clean all --enablerepo='*'
sudo yum clean all
sudo rm -rf /var/cache/yum
sudo rm -rf /var/log/dnf.librepo.log*
;;
'debian' | 'linuxmint' | 'ubuntu')
for pkg in $pkgs; do
sudo DEBIAN_FRONTEND=noninteractive apt-get -o 'DPkg::Lock::Timeout=3600' install -y "$pkg"
done
sudo apt-get -o 'DPkg::Lock::Timeout=3600' autoremove -y
sudo apt-get -o 'DPkg::Lock::Timeout=3600' clean
sudo rm -rf /var/lib/apt/lists/*
;;
esac