1 #!/bin/sh 2 3 # Copyright (C) 2007, 2008, 2010, 2011, 2012, 2013, 2014 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> ] ] [ <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 66 if [ "$USE_MULTISTRAP" ] && [ ! "$MIRROR" ]; then 67 echo "Multistrap usage requires that a mirror be specified." 1>&2 68 exit 1 69 fi 70 71 PATH=$PATH${PATH:+:}/usr/sbin:/sbin 72 73 # For multistrap, make a configuration file and use it to invoke multistrap. 74 75 if [ "$USE_MULTISTRAP" ]; then 76 if [ ! -e "$MULTISTRAP_CONFIG" ]; then 77 DEBIAN_ARCH=`dpkg-architecture -qDEB_BUILD_ARCH` 78 cat > "$MULTISTRAP_CONFIG" <<EOF 79 [General] 80 arch=$DEBIAN_ARCH 81 cleanup=true 82 noauth=false 83 bootstrap=Debian 84 aptsources=Debian 85 86 [Debian] 87 packages=apt 88 source=$MIRROR 89 keyring=$ARCHIVE_KEYRING 90 suite=$USERINSTALL_CODENAME 91 EOF 92 fi 93 94 if ! sudo multistrap -f "$MULTISTRAP_CONFIG" -d "$PACKAGEROOT" ; then 95 cat 1>&2 <<EOF 96 Failed to complete an installation of the chosen distribution. 97 See the error messages above for more information. 98 EOF 99 exit 1 100 fi 101 102 # For normal root installations, use debootstrap. 103 104 elif [ "$AS_ROOT" ]; then 105 if ! sudo debootstrap --include="gnupg,$KEYRING" "$USERINSTALL_CODENAME" "$PACKAGEROOT" "$MIRROR" ; then 106 cat 1>&2 <<EOF 107 Failed to complete an installation of the chosen distribution. 108 See the error messages above for more information. 109 EOF 110 exit 1 111 fi 112 113 # For non-root installations, use debootstrap with fakeroot and fakechroot. 114 115 else 116 if ! fakeroot fakechroot $FAKECHROOT_OPTIONS debootstrap --variant=fakechroot --include="gnupg,$KEYRING" \ 117 "$USERINSTALL_CODENAME" "$PACKAGEROOT" "$MIRROR" ; then 118 cat 1>&2 <<EOF 119 Failed to complete an installation of the chosen distribution. 120 See the error messages above for more information. 121 EOF 122 exit 1 123 fi 124 fi 125 126 cat 1>&2 <<EOF 127 Don't forget to run the following before installing packages: 128 129 user-postsetup $AS_ROOT [ <country> ] 130 EOF