forked from shadowsocks/shadowsocks-libev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chroot_build.sh
executable file
·125 lines (111 loc) · 3.21 KB
/
chroot_build.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
#!/bin/sh
# Copyright 2018 Roger Shimizu <[email protected]>
#
# This is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
set -e
help_usage() {
cat << EOT
Call build_deb.sh script in a chrooted environment
Usage:
sudo $(basename $0) [--help|-h] [codename]
--help|-h Show this usage.
[code name] Debian/Ubuntu release codename
e.g. jessie/stretch/trusty/xenial
EOT
exit
}
# POSIX-compliant maint function recommend by devref
# to check for the existence of a command
# https://www.debian.org/doc/manuals/developers-reference/ch06.html#bpp-debian-maint-scripts
pathfind() {
OLDIFS="$IFS"
IFS=:
for p in $PATH; do
if [ -x "$p/$*" ]; then
IFS="$OLDIFS"
return 0
fi
done
IFS="$OLDIFS"
return 1
}
case "$1" in
wheezy|precise)
echo Sorry, the system $1 is not supported.
;;
jessie|stretch|buster|testing|unstable|sid)
OSID=debian
REPO=http://deb.debian.org/debian
;;
trusty|yakkety|zesty|xenial|artful|bionic)
OSID=ubuntu
REPO=http://archive.ubuntu.com/ubuntu
;;
--help|-h|*)
help_usage
esac
if ! pathfind debootstrap; then
echo Please install debootstrap package.
exit 1
fi
OSVER=$1
CHROOT=/tmp/${OSVER}-build-$(date +%Y%m%d%H%M)
TIMESTAMP0=$(date)
mkdir -p ${CHROOT}/etc
echo en_US.UTF-8 UTF-8 > ${CHROOT}/etc/locale.gen
if ! debootstrap --variant=minbase --include=ca-certificates,git,sudo,wget,whiptail --exclude=upstart,systemd $OSVER $CHROOT $REPO; then
echo debootstrap failed. Please kindly check whether proper sudo or not.
exit 1
fi
case "$OSID" in
debian)
echo deb $REPO ${OSVER} main > ${CHROOT}/etc/apt/sources.list
echo deb $REPO ${OSVER}-updates main >> ${CHROOT}/etc/apt/sources.list
echo deb $REPO-security ${OSVER}/updates main >> ${CHROOT}/etc/apt/sources.list
;;
ubuntu)
echo deb $REPO $OSVER main universe > ${CHROOT}/etc/apt/sources.list
echo deb $REPO ${OSVER}-updates main universe >> ${CHROOT}/etc/apt/sources.list
echo deb $REPO ${OSVER}-security main universe >> ${CHROOT}/etc/apt/sources.list
;;
esac
cat << EOL | chroot $CHROOT
apt-get purge -y udev
apt-get update
apt-get -fy install
apt-get -y upgrade
apt-get -y install --no-install-recommends lsb-release
# dh_auto_test of mbedtls (faketime) depends on /dev/shm. https://bugs.debian.org/778462
mkdir -p ~ /dev/shm
mount tmpfs /dev/shm -t tmpfs
date > /TIMESTAMP1
git config --global user.email "[email protected]"
git config --global user.name "build script"
if [ -n "$http_proxy" ]; then
git config --global proxy.http $http_proxy
echo Acquire::http::Proxy \"$http_proxy\"\; > /etc/apt/apt.conf
export http_proxy=$http_proxy
export https_proxy=$https_proxy
export no_proxy=$no_proxy
fi
cd /tmp
wget https://raw.githubusercontent.com/shadowsocks/shadowsocks-libev/master/scripts/build_deb.sh
chmod 755 build_deb.sh
./build_deb.sh
date > /TIMESTAMP2
./build_deb.sh kcp
umount /dev/shm
EOL
TIMESTAMP1=$(cat ${CHROOT}/TIMESTAMP1)
TIMESTAMP2=$(cat ${CHROOT}/TIMESTAMP2)
TIMESTAMP3=$(date)
printf \\n"All built deb packages:"\\n
ls -l ${CHROOT}/tmp/*.deb
echo
echo Start-Time: $TIMESTAMP0
echo ChrootDone: $TIMESTAMP1
echo SsDeb-Done: $TIMESTAMP2
echo \ Kcp-Done : $TIMESTAMP3