forked from tianon/docker-gentoo-stage3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.sh
executable file
·67 lines (52 loc) · 2.15 KB
/
update.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
#!/bin/bash
set -e
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
stage3="$(wget -qO- 'http://distfiles.gentoo.org/releases/arm/autobuilds/latest-stage3-armv6j_hardfp.txt' | tail -n1)"
if [ -z "$stage3" ]; then
echo >&2 'wtf failure'
exit 1
fi
url="http://distfiles.gentoo.org/releases/arm/autobuilds/$stage3"
name="$(basename "$stage3")"
( set -x; wget -N "$url" )
base="${name%%.*}"
image="gentoo-temp:$base"
container="gentoo-temp-$base"
# bzcat thanks to https://code.google.com/p/go/issues/detail?id=7279
#
# -p parameter doesn't seem standard. A simple test would allow us
# to check building os. Defaults to Gentoo.
bzcat_bin=$(which bzcat 2>/dev/null)
test $(lsb_release -a | grep ID | awk 'BEGIN{FS=":"}{print $2;}'|tr -d "\t") != "Gentoo" && bzcat_line="${bzcat_bin}" || bzcat_line="${bzcat_bin} -p"
( set -x; ${bzcat_line} "$name" | docker import - "$image" )
docker rm -f "$container" > /dev/null 2>&1 || true
( set -x; docker run -t -v /usr/portage:/usr/portage:ro --name "$container" "$image" bash -exc $'
export MAKEOPTS="-j$(nproc)"
pythonTarget="$(emerge --info | sed -n \'s/.*PYTHON_TARGETS="\\([^"]*\\)".*/\\1/p\')"
pythonTarget="${pythonTarget##* }"
echo \'PYTHON_TARGETS="\'$pythonTarget\'"\' >> /etc/portage/make.conf
echo \'PYTHON_SINGLE_TARGET="\'$pythonTarget\'"\' >> /etc/portage/make.conf
emerge --newuse --deep --with-bdeps=y @system @world
emerge -C editor ssh man man-pages openrc e2fsprogs texinfo service-manager
emerge --depclean
' )
xz="$base.tar.xz"
( set -x; docker export "$container" | xz -9 > "$xz" )
docker rm "$container"
docker rmi "$image"
echo 'FROM scratch' > Dockerfile
echo "ADD $xz /" >> Dockerfile
echo 'CMD ["/bin/bash"]' >> Dockerfile
user="$(docker info | awk '/^Username:/ { print $2 }')"
[ -z "$user" ] || user="$user/"
( set -x; docker build -t "${user}rpi-gentoo-stage3" . )
# Quick n' dirty solution
git add Dockerfile "$xz" && \
git commit -m "New version - $base" && \
git checkout master && \
git merge script -m "New version - $base" && \
git checkout script && \
git reset --hard HEAD^1 && \
git checkout master && \
echo "Git structure prepared correctly" || \
echo "An error was found. Please check it manually"