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