| 1 |
#!/bin/sh |
| 2 |
# Copyright © 2005-2009 Roger Leigh <[email protected]> |
| 3 |
# |
| 4 |
# schroot is free software: you can redistribute it and/or modify it |
| 5 |
# under the terms of the GNU General Public License as published by |
| 6 |
# the Free Software Foundation, either version 3 of the License, or |
| 7 |
# (at your option) any later version. |
| 8 |
# |
| 9 |
# schroot is distributed in the hope that it will be useful, but |
| 10 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 |
# General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU General Public License |
| 15 |
# along with this program. If not, see |
| 16 |
# <http://www.gnu.org/licenses/>. |
| 17 |
# |
| 18 |
##################################################################### |
| 19 |
|
| 20 |
set -e |
| 21 |
|
| 22 |
. "$SETUP_DATA_DIR/common-data" |
| 23 |
. "$SETUP_DATA_DIR/common-functions" |
| 24 |
. "$SETUP_DATA_DIR/common-config" |
| 25 |
|
| 26 |
# Copy NSS database from host to chroot |
| 27 |
# $1: database name |
| 28 |
# $2: destination file name |
| 29 |
dup_nss() |
| 30 |
{ |
| 31 |
info "Copying $1 database to $2" |
| 32 |
getent "$1" > "$2" |
| 33 |
} |
| 34 |
|
| 35 |
if [ $STAGE = "setup-start" ] || [ $STAGE = "setup-recover" ]; then |
| 36 |
|
| 37 |
if [ -n "$SETUP_NSSDATABASES" ]; then |
| 38 |
if [ -f "$SETUP_NSSDATABASES" ]; then |
| 39 |
while read db; do |
| 40 |
if echo "$db" | egrep -q '^(#|$)' ; then |
| 41 |
continue |
| 42 |
fi |
| 43 |
|
| 44 |
# Device and inode |
| 45 |
dr=$(/usr/bin/stat --format="%d %i" "/etc/$db") |
| 46 |
# This one can fail since it might not exist yet |
| 47 |
dc=$(/usr/bin/stat --format="%d %i" "${CHROOT_PATH}/etc/$db" 2>/dev/null || :) |
| 48 |
|
| 49 |
# If the database inside and outside the chroot is the |
| 50 |
# same, it's very likely that dup_nss would blank the |
| 51 |
# database, so skip it. |
| 52 |
if [ "$dr" = "$dc" ]; then |
| 53 |
warn "$db files '/etc/$db' and '${CHROOT_PATH}/etc/$db' are the same file; skipping" |
| 54 |
continue; |
| 55 |
fi |
| 56 |
|
| 57 |
dup_nss "$db" "${CHROOT_PATH}/etc/$db" |
| 58 |
done < "$SETUP_NSSDATABASES" |
| 59 |
else |
| 60 |
fatal "nssdatabases file '$SETUP_NSSDATABASES' does not exist" |
| 61 |
fi |
| 62 |
fi |
| 63 |
|
| 64 |
fi |
| 65 |
|