forked from open-switch/opx-onie-installer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build_opx_rootfs.sh
executable file
·61 lines (45 loc) · 1.23 KB
/
build_opx_rootfs.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
#!/bin/bash
# Build the base rootfs for OpenSwitch
if [ $# -ne 2 ]
then
echo 'usage: build_opx_rootfs.sh <version> <arch>'
exit 1
fi
version=$1
arch=$2
tmpdir=$(mktemp -d)
apt-get update
apt-get install -y debootstrap
set -e
debootstrap \
--arch=$arch \
--include=sudo \
jessie \
$tmpdir
# Add the admin user
chroot $tmpdir adduser --quiet --gecos 'OPX Administrator,,,,' \
--disabled-password admin
# Set the default password
echo 'admin:admin' | chpasswd -R $tmpdir
# Set the default hostname into /etc/hostname and /etc/hosts
default_hostname=OPX
echo $default_hostname > $tmpdir/etc/hostname
echo -e "127.0.1.1\t$default_hostname" >> $tmpdir/etc/hosts
# Copy the contents of the rootconf folder to the rootfs
rsync -avz --chown root:root rootconf/* $tmpdir
# Update package cache
chroot $tmpdir apt-get update
# Add the admin user to the sudo group
chroot $tmpdir usermod -a -G sudo admin
rm $tmpdir/usr/sbin/policy-rc.d
chroot $tmpdir apt-get update
chroot $tmpdir apt-get clean
rm -rf $tmpdir/tmp/*
# Create the rootfs tarball
tarfile=opx-rootfs_${version}_${arch}.tar.gz
tar czf $tarfile -C $tmpdir .
# Reset the ownership
chown $LOCAL_UID:$LOCAL_GID $tarfile
# Clean up
rm -fr $tmpdir
# LocalWords: tmp