File: emsandbox

package info (click to toggle)
emdebian-tools 1.4.3
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 1,112 kB
  • ctags: 274
  • sloc: perl: 6,297; xml: 4,828; sh: 1,902; php: 406; ansic: 189; makefile: 15
file content (160 lines) | stat: -rwxr-xr-x 3,878 bytes parent folder | download
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/bin/bash
set -e
#  emsandbox : emdebian roots creation.
#
#  Copyright (C) 2006, 2007  Neil Williams <codehelp@debian.org>
#
#  This package 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.
#
#  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/>.
#

# the name is not finalised
PROG=emsandbox

function usagehelp () {
    # print out help message
    cat <<EOF
$PROG - cross-built chroot Emdebian rootfs builder
version $OURVERSION

Syntax: sudo $PROG [OPTIONS] [COMMAND]

Commands:
-?|-h|--help|--version:  print this help message and exit
--create|create:         create a cross-built base tarball for ARCH

Options:
-a|--arch:               Override the default cross-build architecture (from dpkg-cross).
-s|--script FILENAME:    Override the default package set and second-stage install.
-m|--machine NAME:       Specify a machine name for customisation hooks
-v|--variant NAME:       Specify a machine variant name for customisation hooks
   --machine-path PATH:  Specify a path to replace the $WORK/machine default

Although based on debootstrap, $PROG cannot support the full range of
debootstrap commands or options.

Some customised $PROG scripts are provided with emdebian-tools. The
default uses the standard Emdebian 'busybox' package with 'dpkg' and 'apt'.
Replacement scripts need to be full debootstrap suite shell scripts that specify
how to complete the first and second stage installations. If the script uses
'busybox', the second-stage install function must be compatible with the
shell applet in busybox - avoid bashisms!

EOF
}

. /usr/lib/emdebian-tools/empbuilderlib

SUITE=unstable
PACKAGE=
EXTRA_BASE=""
EXTRA_REQ=""
MACHINE=
VARIANT=
FILENAME=

get_work_dir
get_default_arch

check_sudo()
{
	# test for sudo - normally empdebuild is installed in /usr/sbin so this
	# test is really only for SVN users.
	# make sure sudo is in use.
	# bash cannot seem to do this when set -e is enabled
	# because grep returns non-zero on a non-match
	# so I use perl. :-)
	ISSUDOSET=`perl -e '$e=\`printenv\`; ($e =~ /SUDO_USER/) ? print "yes" : print "no";'`
	if [ $ISSUDOSET == "no" ] ; then
		echo "$PROG needs to be run under sudo."
		exit 2
	fi
}

while [ -n "$1" ]; do
case "$1" in
	--help|-h|-\?|--version)
		usagehelp
		exit;
	;;
	-a|--arch)
		shift
		ARCH=$1
		# chomp the argument to --arch
		shift
	;;
	--create|create)
		shift;
	;;
	-s|--script)
		shift
		FILENAME=$1
		shift
	;;
	-m|--machine)
		shift
		MACHINE=$1
		shift
	;;
	-v|--variant)
		shift
		VARIANT=$1
		shift
	;;
	--machine-path)
		shift
		MACHINEPATH=$1
		shift
	;;
	*)
		echo "Unrecognised option: $1"
		echo
		usagehelp
		exit;
	;;
esac
done

if [ $INCLUDE ]; then
	INCLUDE="--include=$1"
fi

if [ $MACHINEPATH ]; then
	CUSTOM="--machine-path $MACHINEPATH"
fi

if [ $MACHINE ]; then
	CUSTOM+=" --machine $MACHINE"
fi

if [ $VARIANT ]; then
	CUSTOM+=" --variant $VARIANT"
fi

if [ "$ARCH" = "None." ]; then
	echo Error: No default architecture has been set.
	echo Use the --arch option or \'sudo dpkg-reconfigure dpkg-cross\'
	exit
fi

checkarch
check_sudo
CROSS=$ARCH
BASETGZ="${WORKDIR}/emdebian-$ARCH.tgz"
if [ $FILENAME ]; then
	BASETGZ="${WORKDIR}/$FILENAME"
	/usr/lib/emdebian-tools/embootstrap --arch $ARCH --cross --script $FILENAME $CUSTOM $INCLUDE
	echo " -> embootstrap complete"
else
	/usr/lib/emdebian-tools/embootstrap --arch $ARCH --cross $CUSTOM
fi