paul@31 | 1 | #!/bin/sh |
paul@0 | 2 | |
paul@63 | 3 | # Copyright (C) 2007, 2008, 2010, 2011, 2012, 2013 Paul Boddie <paul@boddie.org.uk> |
paul@63 | 4 | # |
paul@63 | 5 | # This program is free software; you can redistribute it and/or modify it under |
paul@63 | 6 | # the terms of the GNU General Public License as published by the Free Software |
paul@63 | 7 | # Foundation; either version 3 of the License, or (at your option) any later |
paul@63 | 8 | # version. |
paul@63 | 9 | # |
paul@63 | 10 | # This program is distributed in the hope that it will be useful, but WITHOUT |
paul@63 | 11 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@63 | 12 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@63 | 13 | # details. |
paul@63 | 14 | # |
paul@63 | 15 | # You should have received a copy of the GNU General Public License along with |
paul@63 | 16 | # this program. If not, see <http://www.gnu.org/licenses/>. |
paul@63 | 17 | |
paul@0 | 18 | # Configuration: |
paul@2 | 19 | if [ -e userinstall-defaults ]; then |
paul@31 | 20 | . "$PWD/userinstall-defaults" |
paul@10 | 21 | elif [ -e /etc/default/userinstall ]; then |
paul@31 | 22 | . /etc/default/userinstall |
paul@0 | 23 | else |
paul@34 | 24 | echo "No defaults found for userinstall." 1>&2 |
paul@67 | 25 | exit 1 |
paul@0 | 26 | fi |
paul@0 | 27 | |
paul@31 | 28 | if [ "$1" = "--help" ]; then |
paul@67 | 29 | cat 1>&2 <<EOF |
paul@67 | 30 | Usage: `basename $0` [ --root [ --multistrap [ -f <config> ] ] ] [ <mirror> ] |
paul@34 | 31 | |
paul@34 | 32 | Examples: |
paul@34 | 33 | |
paul@34 | 34 | user-setup |
paul@34 | 35 | user-setup file:///tmp/$USERINSTALL_CODENAME/ |
paul@34 | 36 | user-setup http://ftp.xx.debian.org/debian/ |
paul@34 | 37 | user-setup --root http://ftp.xx.debian.org/debian/ |
paul@67 | 38 | user-setup --root --multistrap http://ftp.xx.debian.org/debian/ |
paul@34 | 39 | EOF |
paul@67 | 40 | exit 1 |
paul@34 | 41 | elif [ "$1" = '--root' ]; then |
paul@34 | 42 | AS_ROOT="$1" |
paul@67 | 43 | shift 1 |
paul@67 | 44 | if [ "$1" = '--multistrap' ]; then |
paul@67 | 45 | USE_MULTISTRAP="$1" |
paul@67 | 46 | shift 1 |
paul@67 | 47 | if [ "$1" = '-f' ]; then |
paul@67 | 48 | MULTISTRAP_CONFIG="$2" |
paul@67 | 49 | shift 2 |
paul@67 | 50 | elif [ ! -e "userinstall-multistrap" ]; then |
paul@67 | 51 | MULTISTRAP_CONFIG="userinstall-multistrap" |
paul@67 | 52 | else |
paul@67 | 53 | echo "Any existing multistrap configuration file must be specified using the -f option." 1>&2 |
paul@67 | 54 | exit 1 |
paul@67 | 55 | fi |
paul@67 | 56 | fi |
paul@4 | 57 | fi |
paul@4 | 58 | |
paul@34 | 59 | if [ ! "$PACKAGEROOT" ] || [ "$PACKAGEROOT" = '/' ]; then |
paul@34 | 60 | echo "The package root must be specified and not be set to / (the system root)." 1>&2 |
paul@34 | 61 | exit 1 |
paul@24 | 62 | fi |
paul@24 | 63 | |
paul@34 | 64 | MIRROR="$1" |
paul@57 | 65 | PATH=$PATH${PATH:+:}/usr/sbin:/sbin |
paul@34 | 66 | |
paul@67 | 67 | # For multistrap, make a configuration file and use it to invoke multistrap. |
paul@67 | 68 | |
paul@67 | 69 | if [ "$USE_MULTISTRAP" ]; then |
paul@67 | 70 | if [ ! -e "$MULTISTRAP_CONFIG" ]; then |
paul@67 | 71 | DEBIAN_ARCH=`dpkg-architecture -qDEB_BUILD_ARCH` |
paul@67 | 72 | cat > "$MULTISTRAP_CONFIG" <<EOF |
paul@67 | 73 | [General] |
paul@67 | 74 | arch=$DEBIAN_ARCH |
paul@67 | 75 | cleanup=true |
paul@67 | 76 | noauth=false |
paul@67 | 77 | bootstrap=Debian |
paul@67 | 78 | aptsources=Debian |
paul@67 | 79 | |
paul@67 | 80 | [Debian] |
paul@67 | 81 | packages=gnupg |
paul@67 | 82 | source=$MIRROR |
paul@67 | 83 | keyring=$ARCHIVE_KEYRING |
paul@67 | 84 | suite=$USERINSTALL_CODENAME |
paul@67 | 85 | EOF |
paul@67 | 86 | fi |
paul@67 | 87 | |
paul@67 | 88 | if ! sudo multistrap -f "$MULTISTRAP_CONFIG" -d "$PACKAGEROOT" ; then |
paul@67 | 89 | cat 1>&2 <<EOF |
paul@67 | 90 | Failed to complete an installation of the chosen distribution. |
paul@67 | 91 | See the error messages above for more information. |
paul@67 | 92 | EOF |
paul@67 | 93 | exit 1 |
paul@67 | 94 | fi |
paul@67 | 95 | |
paul@67 | 96 | # For normal root installations, use debootstrap. |
paul@67 | 97 | |
paul@67 | 98 | elif [ "$AS_ROOT" ]; then |
paul@61 | 99 | if ! sudo debootstrap --include="gnupg,$KEYRING" "$USERINSTALL_CODENAME" "$PACKAGEROOT" "$MIRROR" ; then |
paul@61 | 100 | cat 1>&2 <<EOF |
paul@61 | 101 | Failed to complete an installation of the chosen distribution. |
paul@61 | 102 | See the error messages above for more information. |
paul@61 | 103 | EOF |
paul@67 | 104 | exit 1 |
paul@61 | 105 | fi |
paul@67 | 106 | |
paul@67 | 107 | # For non-root installations, use debootstrap with fakeroot and fakechroot. |
paul@67 | 108 | |
paul@24 | 109 | else |
paul@61 | 110 | if ! fakeroot fakechroot $FAKECHROOT_OPTIONS debootstrap --variant=fakechroot --include="gnupg,$KEYRING" \ |
paul@61 | 111 | "$USERINSTALL_CODENAME" "$PACKAGEROOT" "$MIRROR" ; then |
paul@61 | 112 | cat 1>&2 <<EOF |
paul@61 | 113 | Failed to complete an installation of the chosen distribution. |
paul@61 | 114 | See the error messages above for more information. |
paul@61 | 115 | EOF |
paul@67 | 116 | exit 1 |
paul@61 | 117 | fi |
paul@24 | 118 | fi |
paul@24 | 119 | |
paul@35 | 120 | cat 1>&2 <<EOF |
paul@34 | 121 | Don't forget to run the following before installing packages: |
paul@34 | 122 | |
paul@34 | 123 | user-postsetup $AS_ROOT [ <country> ] |
paul@34 | 124 | EOF |