| 1 | #!/bin/bash |
|---|
| 2 | set -e |
|---|
| 3 | # emsandbox : emdebian roots creation. |
|---|
| 4 | # |
|---|
| 5 | # Copyright (C) 2006-2008 Neil Williams <codehelp@debian.org> |
|---|
| 6 | # |
|---|
| 7 | # This package is free software; you can redistribute it and/or modify |
|---|
| 8 | # it under the terms of the GNU General Public License as published by |
|---|
| 9 | # the Free Software Foundation; either version 3 of the License, or |
|---|
| 10 | # (at your option) any later version. |
|---|
| 11 | # |
|---|
| 12 | # This program is distributed in the hope that it will be useful, |
|---|
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | # GNU General Public License for more details. |
|---|
| 16 | # |
|---|
| 17 | # You should have received a copy of the GNU General Public License |
|---|
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 19 | # |
|---|
| 20 | |
|---|
| 21 | # the name is not finalised |
|---|
| 22 | PROG=emsandbox |
|---|
| 23 | |
|---|
| 24 | function usagehelp () { |
|---|
| 25 | # print out help message |
|---|
| 26 | cat <<EOF |
|---|
| 27 | $PROG - cross-built chroot Emdebian rootfs builder |
|---|
| 28 | version $OURVERSION |
|---|
| 29 | |
|---|
| 30 | Syntax: sudo $PROG [OPTIONS] [COMMAND] |
|---|
| 31 | |
|---|
| 32 | Commands: |
|---|
| 33 | -?|-h|--help|--version: print this help message and exit |
|---|
| 34 | --create|create: create a cross-built base tarball for ARCH |
|---|
| 35 | |
|---|
| 36 | Options: |
|---|
| 37 | -a|--arch: Override the default cross-build architecture (from dpkg-cross). |
|---|
| 38 | -s|--script FILENAME: Override the default package set and second-stage install. |
|---|
| 39 | -S|--suite NAME: Override the default suite [unstable] |
|---|
| 40 | -m|--machine NAME: Specify a machine name for customisation hooks |
|---|
| 41 | -v|--variant NAME: Specify a machine variant name for customisation hooks |
|---|
| 42 | --machine-path PATH: Specify a path to replace the $WORK/machine default |
|---|
| 43 | |
|---|
| 44 | Although based on debootstrap, $PROG cannot support the full range of |
|---|
| 45 | debootstrap commands or options. |
|---|
| 46 | |
|---|
| 47 | Some customised $PROG scripts are provided with emdebian-tools. The |
|---|
| 48 | default uses the standard Emdebian 'busybox' package with 'dpkg' and 'apt'. |
|---|
| 49 | Replacement scripts need to be full debootstrap suite shell scripts that specify |
|---|
| 50 | how to complete the first and second stage installations. If the script uses |
|---|
| 51 | 'busybox', the second-stage install function must be compatible with the |
|---|
| 52 | shell applet in busybox - avoid bashisms! |
|---|
| 53 | |
|---|
| 54 | Overriding the default suite also configures the root filesystem to look |
|---|
| 55 | for updates within the specified suite. |
|---|
| 56 | |
|---|
| 57 | EOF |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | . /usr/lib/emdebian-tools/empbuilderlib |
|---|
| 61 | |
|---|
| 62 | SUITE=unstable |
|---|
| 63 | PACKAGE= |
|---|
| 64 | EXTRA_BASE="" |
|---|
| 65 | EXTRA_REQ="" |
|---|
| 66 | MACHINE= |
|---|
| 67 | VARIANT= |
|---|
| 68 | FILENAME= |
|---|
| 69 | |
|---|
| 70 | get_work_dir |
|---|
| 71 | get_default_arch |
|---|
| 72 | |
|---|
| 73 | check_sudo() |
|---|
| 74 | { |
|---|
| 75 | # test for sudo - normally empdebuild is installed in /usr/sbin so this |
|---|
| 76 | # test is really only for SVN users. |
|---|
| 77 | # make sure sudo is in use. |
|---|
| 78 | # bash cannot seem to do this when set -e is enabled |
|---|
| 79 | # because grep returns non-zero on a non-match |
|---|
| 80 | # so I use perl. :-) |
|---|
| 81 | ISSUDOSET=`perl -e '$e=\`printenv\`; ($e =~ /SUDO_USER/) ? print "yes" : print "no";'` |
|---|
| 82 | if [ $ISSUDOSET == "no" ] ; then |
|---|
| 83 | echo "$PROG needs to be run under sudo." |
|---|
| 84 | exit 2 |
|---|
| 85 | fi |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | while [ -n "$1" ]; do |
|---|
| 89 | case "$1" in |
|---|
| 90 | --help|-h|-\?|--version) |
|---|
| 91 | usagehelp |
|---|
| 92 | exit; |
|---|
| 93 | ;; |
|---|
| 94 | -a|--arch) |
|---|
| 95 | shift |
|---|
| 96 | ARCH=$1 |
|---|
| 97 | # chomp the argument to --arch |
|---|
| 98 | shift |
|---|
| 99 | ;; |
|---|
| 100 | --create|create) |
|---|
| 101 | shift; |
|---|
| 102 | ;; |
|---|
| 103 | -s|--script) |
|---|
| 104 | shift |
|---|
| 105 | FILENAME=$1 |
|---|
| 106 | shift |
|---|
| 107 | ;; |
|---|
| 108 | -S|--suite) |
|---|
| 109 | shift |
|---|
| 110 | SUITE=$1 |
|---|
| 111 | shift |
|---|
| 112 | ;; |
|---|
| 113 | -m|--machine) |
|---|
| 114 | shift |
|---|
| 115 | MACHINE=$1 |
|---|
| 116 | shift |
|---|
| 117 | ;; |
|---|
| 118 | -v|--variant) |
|---|
| 119 | shift |
|---|
| 120 | VARIANT=$1 |
|---|
| 121 | shift |
|---|
| 122 | ;; |
|---|
| 123 | --machine-path) |
|---|
| 124 | shift |
|---|
| 125 | MACHINEPATH=$1 |
|---|
| 126 | shift |
|---|
| 127 | ;; |
|---|
| 128 | *) |
|---|
| 129 | echo "Unrecognised option: $1" |
|---|
| 130 | echo |
|---|
| 131 | usagehelp |
|---|
| 132 | exit; |
|---|
| 133 | ;; |
|---|
| 134 | esac |
|---|
| 135 | done |
|---|
| 136 | |
|---|
| 137 | if [ $INCLUDE ]; then |
|---|
| 138 | INCLUDE="--include=$1" |
|---|
| 139 | fi |
|---|
| 140 | |
|---|
| 141 | if [ $MACHINEPATH ]; then |
|---|
| 142 | CUSTOM="--machine-path $MACHINEPATH" |
|---|
| 143 | fi |
|---|
| 144 | |
|---|
| 145 | if [ $MACHINE ]; then |
|---|
| 146 | CUSTOM+=" --machine $MACHINE" |
|---|
| 147 | fi |
|---|
| 148 | |
|---|
| 149 | if [ $VARIANT ]; then |
|---|
| 150 | CUSTOM+=" --variant $VARIANT" |
|---|
| 151 | fi |
|---|
| 152 | |
|---|
| 153 | if [ "$ARCH" = "None." ]; then |
|---|
| 154 | echo Error: No default architecture has been set. |
|---|
| 155 | echo Use the --arch option or \'sudo dpkg-reconfigure dpkg-cross\' |
|---|
| 156 | exit |
|---|
| 157 | fi |
|---|
| 158 | |
|---|
| 159 | checkarch |
|---|
| 160 | check_sudo |
|---|
| 161 | CROSS=$ARCH |
|---|
| 162 | if [ "x$SUITE" != "xunstable" ]; then |
|---|
| 163 | CUSTOM+=" --suite $SUITE" |
|---|
| 164 | fi |
|---|
| 165 | BASETGZ="${WORKDIR}/emdebian-$ARCH.tgz" |
|---|
| 166 | if [ $FILENAME ]; then |
|---|
| 167 | BASETGZ="${WORKDIR}/$FILENAME" |
|---|
| 168 | /usr/lib/emdebian-tools/embootstrap --arch $ARCH --cross --script $FILENAME $CUSTOM $INCLUDE |
|---|
| 169 | echo " -> embootstrap complete" |
|---|
| 170 | else |
|---|
| 171 | /usr/lib/emdebian-tools/embootstrap --arch $ARCH --cross $CUSTOM |
|---|
| 172 | fi |
|---|