forked from szepeviktor/debian-server-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
debian-setup-functions
64 lines (51 loc) · 1.47 KB
/
debian-setup-functions
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
# shellcheck shell=bash
# Common functions for debian-setup
Error() {
echo "ERROR: $(tput bold;tput setaf 7;tput setab 1)${*}$(tput sgr0)" 1>&2
}
Is_installed() {
local PKG="$1"
test "$(dpkg-query --showformat="\${Status}" --show "$PKG" 2> /dev/null)" == "install ok installed"
}
export -f Is_installed
Is_installed_regexp() {
local PKG="$1"
local SEARCH="?and(?installed, ?name(${PKG}))"
test -n "$(aptitude --disable-columns --display-format "%p" search "$SEARCH")"
}
export -f Is_installed_regexp
Pkg_install_quiet() {
DEBIAN_FRONTEND=noninteractive apt-get install -q -y "$@"
}
export -f Pkg_install_quiet
# Download architecture-independent packages
Getpkg() {
local P="$1"
local R="${2:-sid}"
local PKG_PAGE="https://packages.debian.org/${R}/all/${P}/download"
local URL
URL="$(wget -q -O- "$PKG_PAGE" | grep -o '[^"]\+ftp.de.debian.org/debian[^"]\+\.deb')"
[ -z "$URL" ] && return 1
(
cd /root/dist-mod/ || return 1
wget -q -O "${P}.deb" "$URL"
dpkg -i "${P}.deb"
)
}
export -f Getpkg
# Install a script from debian-server-tools
Dinstall() {
(
cd /usr/local/src/ || return 1
if ! [ -d "debian-server-tools" ]; then
git clone https://github.com/szepeviktor/debian-server-tools.git
fi
cd debian-server-tools/ || return 1
./install.sh "$@"
)
}
export -f Dinstall
Data() {
PYTHONIOENCODING="utf_8" shyaml "$@" < /root/server.yml
}
export -f Data