forked from szepeviktor/debian-server-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upcloud-init.sh
executable file
·72 lines (58 loc) · 2.27 KB
/
upcloud-init.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
#!/bin/bash
#
# Prepare UpCloud server with docker and pip.
#
# Initialization script: https://github.com/szepeviktor/debian-server-tools/raw/master/upcloud-init.sh
# Follow log: tail -f /var/log/upcloud_userdata.log
# http://deb.debian.org/debian/pool/contrib/g/geoipupdate/
GEOIPUPDATE_VERSION="2.5.0-1"
DEBIAN_CODENAME="stretch"
export LC_ALL="C"
export DEBIAN_FRONTEND="noninteractive"
Auto_country() {
apt-get clean
apt-get update
apt-get install -qq mmdb-bin netselect-apt
wget -nv "http://deb.debian.org/debian/pool/contrib/g/geoipupdate/geoipupdate_${GEOIPUPDATE_VERSION}_amd64.deb"
dpkg -i geoipupdate_*_amd64.deb
geoipupdate
IP="$(ifconfig | sed -n -e '0,/^\s*inet \(addr:\)\?\([0-9\.]\+\)\b.*$/s//\2/p')"
test -n "$IP"
COUNTRY="$(mmdblookup --file /var/lib/GeoIP/GeoLite2-Country.mmdb --ip "$IP" registered_country iso_code | sed -n -e '0,/.*"\([A-Z]\+\)".*/s//\1/p')" #'
test -n "$COUNTRY"
netselect-apt -c "$COUNTRY" stable
MIRROR="$(sed -n -e '0,/^deb \(http\S\+\) .*$/s//\1/p' sources.list)"
test -n "$MIRROR"
rm -f geoipupdate_*_amd64.deb sources.list
wget -nv -O- "https://github.com/szepeviktor/debian-server-tools/raw/master/package/apt-sources/sources.list" \
| sed -e "s|@@MIRROR@@|${MIRROR}|" > /etc/apt/sources.list
}
set -e -x
# Create temporary files in /tmp
test -d /tmp && cd /tmp/
# Output may end up in a log file
echo 'Dpkg::Use-Pty "0";' > /etc/apt/apt.conf.d/00usepty
# LeaseWeb sources
wget -nv -O /etc/apt/sources.list \
"https://github.com/szepeviktor/debian-server-tools/raw/master/package/apt-sources/${DEBIAN_CODENAME}-for-upcloud.list"
apt-get clean -q
apt-get update -q
# Prevent kernel update
#apt-mark hold linux-image-amd64 "linux-image-[0-9].*-amd64"
apt-get dist-upgrade -q -y
# docker
apt-get install -qq dirmngr apt-transport-https
apt-key adv --keyserver "hkp://p80.pool.sks-keyservers.net:80" --recv-keys 2C52609D
echo "deb https://apt.dockerproject.org/repo debian-${DEBIAN_CODENAME} main" \
> /etc/apt/sources.list.d/docker.list
apt-get update -q
apt-get install -qq docker-engine
docker version
# pip
apt-get install -qq python3-dev
wget -nv "https://bootstrap.pypa.io/get-pip.py"
python3 get-pip.py
rm -f get-pip.py
pip3 --version
rm -f /etc/apt/apt.conf.d/00usepty
echo "OK."