Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: dffd637ce8
Fetching contributors…

Cannot retrieve contributors at this time

executable file 193 lines (151 sloc) 6.317 kb
#!/bin/sh -e
sinfo() {
echo ${BASH:+-e} "\033[1;33;41m$@\033[0m"
}
# Must have root directory as an argument
if [ -z "$1" ]; then
echo "$0 <livecd root> [copy|image] [-c shell command...]"
exit 1
fi
# Launch in a separate mount namespace
if [ unshare != "$1" ]; then
exec unshare -m -- "$0" unshare "$@"
else
shift
fi
# Variables
SRC=`dirname $0`/src
RSYNC="rsync -rlptOHS"
version=`cat ${SRC}/../conf/version`
environment="LVERSION=${version} LOGNAME=root USER=root HOME=/root HOSTNAME=liberte"
for env in LANG TERM RSYNC_PROXY http_proxy https_proxy ftp_proxy no_proxy; do
if printenv ${env} 1>/dev/null; then
environment="${environment} ${env}=`printenv ${env}`"
fi
done
# Tweak target directory if alternative is given,
# otherwise, synchronize configuration
if [ "$2" = copy ]; then
PHASE=$2
LIVECD=$1/${PHASE}
shift 2
elif [ "$2" = image ]; then
PHASE=$2
LIVECD=$1/src
shift 2
else
PHASE=src
LIVECD=$1/${PHASE}
shift
# NOTE: non-pruned files: /, /etc/portage/gnupg, /etc/privoxy, /var/lib/portage
# /home/anon/persist/security/pgp/*.{gpg,crt}
# Specify permissions completely, to be independent from ${SRC}/* chmods
sinfo "Copying configuration files:"
${RSYNC} --chmod=u=rwX,go=rX -i \
--exclude=/root/ \
--exclude=/home/anon/ \
--exclude=/home/nofw/ \
--exclude=/var/lib/i2p/ \
--exclude=/var/lib/portage/ \
--exclude=/usr/local/portage/ \
--exclude=/etc/sudoers \
--exclude=/etc/sysctl.conf \
--exclude=/etc/polkit-1 \
--exclude=/etc/portage/gnupg/ -C ${SRC}/ ${LIVECD}
${RSYNC} --chmod=u=rwX,go=rX -i --delete-excluded \
-C --exclude=.gitignore ${SRC}/root ${LIVECD}
${RSYNC} --chmod=u=rwX,go= -i -C ${SRC}/etc/portage/gnupg ${LIVECD}/etc/portage
${RSYNC} --chmod=u=rwX,go=rX,Dg+s -i -C ${SRC}/var/lib/portage ${LIVECD}/var/lib
${RSYNC} --chmod=u=rwX,go=rX -i --delete --exclude=/portage/distfiles -C ${SRC}/usr/local/portage ${LIVECD}/usr/local
if [ -e ${LIVECD}/var/log/privoxy ]; then
chown -hR --from=`stat -c %u:%g ${LIVECD}/var/log/privoxy` 0:0 ${LIVECD}/etc/privoxy
fi
${RSYNC} --chmod=ug=r,o= -i ${SRC}/etc/sudoers ${LIVECD}/etc
${RSYNC} --chmod=u=rw,g=r,o= -i ${SRC}/etc/sysctl.conf ${LIVECD}/etc
if [ -e ${LIVECD}/etc/polkit-1/localauthority ]; then
${RSYNC} --chmod=u=rwX,go=rX -i --delete-excluded -C \
${SRC}/etc/polkit-1/localauthority/* ${LIVECD}/etc/polkit-1/localauthority
fi
mkdir -p -m 755 ${LIVECD}/usr/local/addons
${RSYNC} --chmod=u=rwX,go=rX -i --delete-excluded -C ${LIVECD}/../mirror/keys ${LIVECD}/usr/local/addons
# rwX------
${RSYNC} --chmod=u=rwX,go= -i --delete \
--exclude=/anon/persist/security/pgp/\*.gpg --exclude=/anon/persist/security/pgp/\*.crt \
--exclude=/anon/persist/cables/queue --exclude=/anon/persist/cables/rqueue \
--exclude=/anon/persist/mail/inbox -C ${SRC}/home/anon ${LIVECD}/home
${RSYNC} --chmod=ug=rwX,o=,Do+t -i --delete-excluded \
-C ${SRC}/home/anon/persist/cables/queue ${SRC}/home/anon/persist/cables/rqueue \
${LIVECD}/home/anon/persist/cables
${RSYNC} --chmod=ug=rwX,o=,Do+t -i --delete-excluded \
-C ${SRC}/home/anon/persist/mail/inbox ${LIVECD}/home/anon/persist/mail
chown -hR --from=0:0 2101:9000 ${LIVECD}/home/anon
${RSYNC} --chmod=u=rwX,go= -i --delete-excluded -C ${SRC}/home/nofw ${LIVECD}/home
chown -hR --from=0:0 2102:9001 ${LIVECD}/home/nofw
${RSYNC} --chmod=u=rwX,go= -i --delete \
--exclude=/i2p/router/netDb/ -C ${SRC}/var/lib/i2p ${LIVECD}/var/lib
if [ -e ${LIVECD}/tmp/i2p-ref ]; then
chown -hR --from=0:0 --reference=${LIVECD}/tmp/i2p-ref ${LIVECD}/var/lib/i2p
fi
if [ -e /etc/resolv.conf ]; then
${RSYNC} -L --chmod=u=rw,go=r -i /etc/resolv.conf ${LIVECD}/etc
fi
fi
environment="${environment} PHASE=${PHASE}"
setarch=`which setarch`
chroot=`which chroot`
tty=`tty`
sinfo "Mounting system directories"
[ "${tty#/dev/pts/}" = "${tty}" ] || tty=
[ -L ${LIVECD}/dev/fd ] || ln -sfT /proc/self/fd ${LIVECD}/dev/fd
for mp in /proc /dev/null /dev/random /dev/urandom /dev/tty /dev/ptmx /dev/pts ${tty}; do
if [ ! -e ${LIVECD}${mp} ]; then
if [ -d ${mp} ]; then
mkdir -m 755 ${LIVECD}${mp}
elif [ -e ${mp} ]; then
touch ${LIVECD}${mp}
fi
fi
mount -B ${mp} ${LIVECD}${mp}
done
mount -rB -o remount ${LIVECD}/proc
if [ ${PHASE} = copy -a -d ${LIVECD}/usr/portage ]; then
mount -B ${LIVECD}/../src/usr/portage ${LIVECD}/usr/portage
mount -rB -o remount ${LIVECD}/usr/portage
fi
if [ -d /usr/portage/distfiles -a -d ${LIVECD}/usr/portage/distfiles ]; then
mount -B /usr/portage/distfiles ${LIVECD}/usr/portage/distfiles
fi
if [ ${PHASE} = image ]; then
mkdir -p ${LIVECD}/../dist
mount -B ${LIVECD}/../copy ${LIVECD}/mnt/live
mount -B ${LIVECD}/../dist ${LIVECD}/mnt/boot
fi
sinfo "Environment:"
echo "${environment}" | tr ' ' '\n' | sed 's/^/ /'
sinfo "Launching chrooted shell in ${LIVECD}"
set +e
env -i ${environment} "${setarch}" i686 "${chroot}" ${LIVECD} /bin/bash -l "$@"
retval=$?
if [ ${retval} != 0 ]; then
sinfo "Failed."
fi
# Unnecessary with unshare -m, but stale processes might hold the mounts
sinfo "Unmounting system directories"
if [ ${PHASE} = image ]; then
umount ${LIVECD}/mnt/live
umount ${LIVECD}/mnt/boot
fi
if [ -d /usr/portage/distfiles -a -d ${LIVECD}/usr/portage/distfiles ]; then
umount ${LIVECD}/usr/portage/distfiles
fi
if [ -d ${LIVECD}/usr/portage -a ${PHASE} = copy ]; then
umount ${LIVECD}/usr/portage
fi
for mp in ${tty} /dev/pts /dev/ptmx /dev/tty /dev/urandom /dev/random /dev/null /proc; do
umount -l ${LIVECD}${mp}
done
# Condition is false for empty ${tty} and for block-device ${tty} (i.e., unmount failed)
if [ -f ${LIVECD}${tty} ]; then
rm ${LIVECD}${tty}
fi
exit ${retval}
Jump to Line
Something went wrong with that request. Please try again.