-
Notifications
You must be signed in to change notification settings - Fork 1
/
build_openwrt_containers.sh
124 lines (99 loc) · 2.96 KB
/
build_openwrt_containers.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
#!/usr/bin/env sh
#
# OpenWrt lxc container build automation script
#
# Copyright (C) 2014 Cisco Systems, Inc.
#
# This program 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 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Author: Luka Perkov <luka.perkov@sartura.hr>
#
if [ `id -u` -ne 0 ]; then
echo "run this script as root"
exit 1
fi
HOSTNAME="vwrt"
DIR_CONAINER_WORKING="./rootfs"
DIR_OPENWRT_TRUNK="/opt/openwrt/trunk/"
DIR_THIS_FILE=`pwd`
openwrt_container_configure_inittab() {
cat > etc/inittab << EOF
::sysinit:/etc/init.d/rcS S boot
::shutdown:/etc/init.d/rcS K shutdown
console::askfirst:/bin/ash --login
tty1::askfirst:/bin/ash --login
tty2::askfirst:/bin/ash --login
tty3::askfirst:/bin/ash --login
tty4::askfirst:/bin/ash --login
EOF
}
openwrt_container_configure_network() {
cat > etc/config/network << EOF
config interface 'loopback'
option ifname 'lo'
option proto 'static'
option ipaddr '127.0.0.1'
option netmask '255.0.0.0'
config interface 'wan'
option ifname 'eth0'
option proto 'dhcp'
EOF
}
openwrt_container_configure_system() {
cat > etc/config/system << EOF
config system
option timezone 'UTC'
config timeserver 'ntp'
list server '0.openwrt.pool.ntp.org'
list server '1.openwrt.pool.ntp.org'
list server '2.openwrt.pool.ntp.org'
list server '3.openwrt.pool.ntp.org'
option enable_server '0'
EOF
}
openwrt_container_cleanup_rootfs() {
rm -rf lib/modules/*
}
openwrt_generate_x86_container() {
cd "$DIR_OPENWRT_TRUNK"/bin/x86
rm -rf $DIR_CONAINER_WORKING 2>/dev/null
mkdir $DIR_CONAINER_WORKING
cd $DIR_CONAINER_WORKING
tar axf "../openwrt-x86-generic-Generic-rootfs.tar.gz"
openwrt_container_configure_inittab
openwrt_container_configure_network
openwrt_container_configure_system
openwrt_container_cleanup_rootfs
cd ..
cp $DIR_THIS_FILE/lxc/template_config config
tar cf openwrt-x86-lxc-rootfs.tar $DIR_CONAINER_WORKING config
rm config
}
openwrt_generate_ar71xx_container() {
cd "$DIR_OPENWRT_TRUNK"/bin/ar71xx
rm -rf $DIR_CONAINER_WORKING 2>/dev/null
mkdir $DIR_CONAINER_WORKING
cd $DIR_CONAINER_WORKING
tar axf "../openwrt-ar71xx-generic-Default-rootfs.tar.gz"
openwrt_container_configure_inittab
openwrt_container_configure_network
openwrt_container_configure_system
openwrt_container_cleanup_rootfs
cd ..
cp $DIR_THIS_FILE/lxc/template_config config
tar cf openwrt-ar71xx-lxc-rootfs.tar $DIR_CONAINER_WORKING config
rm config
}
openwrt_generate_x86_container
openwrt_generate_ar71xx_container