live-build/helpers/lh_chroot_sources

284 lines
7.3 KiB
Plaintext
Raw Normal View History

2007-09-23 08:04:46 +00:00
#!/bin/sh
# lh_chroot_sources(1) - manage /etc/apt/sources.list
2007-09-23 08:04:48 +00:00
# Copyright (C) 2006-2007 Daniel Baumann <daniel@debian.org>
#
# live-helper comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
# This is free software, and you are welcome to redistribute it
# under certain conditions; see COPYING for details.
2007-09-23 08:04:46 +00:00
set -e
2007-09-23 08:05:11 +00:00
# Including common functions
LH_BASE="${LH_BASE:-/usr/share/live-helper}"
for FUNCTION in "${LH_BASE}"/functions/*.sh
2007-09-23 08:04:46 +00:00
do
2007-09-23 08:05:11 +00:00
. "${FUNCTION}"
2007-09-23 08:04:46 +00:00
done
2007-09-23 08:05:11 +00:00
# Setting static variables
2007-09-23 08:04:48 +00:00
DESCRIPTION="manage /etc/apt/sources.list"
HELP=""
USAGE="${PROGRAM} {install|remove} [--force]"
Arguments "${@}"
2007-09-23 08:04:46 +00:00
# Reading configuration files
2007-09-23 08:04:52 +00:00
Read_conffile config/common
2007-09-23 08:04:49 +00:00
Read_conffile config/bootstrap
2007-09-23 08:04:46 +00:00
Read_conffile config/chroot
2007-09-23 08:04:52 +00:00
Read_conffile config/binary
Read_conffile config/source
2007-09-23 08:05:18 +00:00
Read_conffile "${LH_CONFIG}"
2007-09-23 08:04:46 +00:00
Set_defaults
# Requiring stage file
2007-09-23 08:04:47 +00:00
Require_stagefile .stage/bootstrap
2007-09-23 08:04:46 +00:00
case "${1}" in
install)
2007-09-23 08:05:12 +00:00
Echo_message "Configuring file /etc/apt/sources.list"
2007-09-23 08:04:46 +00:00
# Checking stage file
2007-09-23 08:04:47 +00:00
Check_stagefile .stage/chroot_sources
2007-09-23 08:04:46 +00:00
2007-09-23 08:04:50 +00:00
# Checking lock file
Check_lockfile .lock
# Creating lock file
Create_lockfile .lock
2007-09-23 08:04:46 +00:00
# Configure custom sources.list
2007-09-23 08:05:17 +00:00
echo "deb ${LH_MIRROR_BOOTSTRAP} ${LH_DISTRIBUTION} ${LH_SECTIONS}" > chroot/etc/apt/sources.list
2007-09-23 08:04:46 +00:00
2007-09-23 08:05:17 +00:00
if [ "${LH_SOURCE}" = "enabled" ]
2007-09-23 08:04:46 +00:00
then
2007-09-23 08:05:17 +00:00
echo "deb-src ${LH_MIRROR_BOOTSTRAP} ${LH_DISTRIBUTION} ${LH_SECTIONS}" >> chroot/etc/apt/sources.list
2007-09-23 08:04:46 +00:00
fi
2007-09-23 08:05:17 +00:00
if [ "${LH_SECURITY}" = "enabled" ]
2007-09-23 08:04:46 +00:00
then
2007-10-19 10:45:57 +00:00
if [ "${LH_DISTRIBUTION}" != "sid" ] && [ "${LH_DISTRIBUTION}" != "unstable" ]
then
echo "deb ${LH_MIRROR_BOOTSTRAP_SECURITY} ${LH_DISTRIBUTION}/updates ${LH_SECTIONS}" >> chroot/etc/apt/sources.list
2007-09-23 08:04:51 +00:00
2007-10-19 10:45:57 +00:00
if [ "${LH_SOURCE}" = "enabled" ]
then
echo "deb-src ${LH_MIRROR_BOOTSTRAP_SECURITY} ${LH_DISTRIBUTION}/updates ${LH_SECTIONS}" >> chroot/etc/apt/sources.list
fi
fi
2007-09-23 08:04:46 +00:00
fi
2007-09-23 08:04:47 +00:00
# Check local sources.list
2007-09-23 08:05:11 +00:00
if ls config/chroot_sources/*.bootstrap > /dev/null 2>&1
2007-09-23 08:04:47 +00:00
then
echo "" >> chroot/etc/apt/sources.list
echo "# Custom repositories" >> chroot/etc/apt/sources.list
2007-09-23 08:04:49 +00:00
2007-09-23 08:05:09 +00:00
for FILE in config/chroot_sources/*.bootstrap
2007-09-23 08:04:49 +00:00
do
2007-09-23 08:04:50 +00:00
cat ${FILE} | grep -v "^##" >> chroot/etc/apt/sources.list
2007-09-23 08:04:49 +00:00
done
fi
2007-09-23 08:04:52 +00:00
# Update indices from cache
2007-09-23 08:05:09 +00:00
if [ "${LH_CACHE_INDICES}" = "enabled" ] && [ -d cache/indices_bootstrap ]
2007-09-23 08:04:49 +00:00
then
2007-09-23 08:05:11 +00:00
if ls cache/indices_bootstrap/secring.gpg* > /dev/null 2>&1
2007-09-23 08:04:52 +00:00
then
2007-09-23 08:05:09 +00:00
cp -f cache/indices_bootstrap/secring.gpg* chroot/etc/apt
2007-09-23 08:04:52 +00:00
fi
2007-09-23 08:04:49 +00:00
2007-09-23 08:05:11 +00:00
if ls cache/indices_bootstrap/trusted.gpg* > /dev/null 2>&1
2007-09-23 08:04:52 +00:00
then
2007-09-23 08:05:09 +00:00
cp -f cache/indices_bootstrap/trusted.gpg* chroot/etc/apt
2007-09-23 08:04:52 +00:00
fi
2007-09-23 08:04:47 +00:00
2007-09-23 08:05:09 +00:00
if [ -f cache/indices_bootstrap/pkgcache.bin ]
2007-09-23 08:04:52 +00:00
then
2007-09-23 08:05:09 +00:00
cp -f cache/indices_bootstrap/pkgcache.bin chroot/var/cache/apt
2007-09-23 08:04:52 +00:00
fi
2007-09-23 08:05:09 +00:00
if [ -f cache/indices_bootstrap/srcpkgcache.bin ]
2007-09-23 08:04:52 +00:00
then
2007-09-23 08:05:09 +00:00
cp -f cache/indices_bootstrap/srcpkgcache.bin chroot/var/cache/apt
2007-09-23 08:04:52 +00:00
fi
2007-09-23 08:05:11 +00:00
if ls cache/indices_bootstrap/*_Packages > /dev/null 2>&1
2007-09-23 08:04:52 +00:00
then
2007-09-23 08:05:09 +00:00
cp -f cache/indices_bootstrap/*_Packages chroot/var/lib/apt/lists
2007-09-23 08:04:52 +00:00
fi
2007-09-23 08:05:11 +00:00
if ls cache/indices_bootstrap/*_Sources > /dev/null 2>&1
2007-09-23 08:04:52 +00:00
then
2007-09-23 08:05:09 +00:00
cp -f cache/indices_bootstrap/*_Sources chroot/var/lib/apt/lists
2007-09-23 08:04:52 +00:00
fi
2007-09-23 08:05:11 +00:00
if ls cache/indices_bootstrap/*_Release* > /dev/null 2>&1
2007-09-23 08:04:52 +00:00
then
2007-09-23 08:05:09 +00:00
cp -f cache/indices_bootstrap/*_Release* chroot/var/lib/apt/lists
2007-09-23 08:04:52 +00:00
fi
if [ "${LH_APT}" = "aptitude" ] && [ ! -x /usr/bin/aptitude ]
2007-09-23 08:04:46 +00:00
then
Chroot "apt-get install --yes --force-yes aptitude"
fi
2007-09-23 08:04:52 +00:00
else # Get fresh indices
# Check local gpg keys
2007-09-23 08:05:11 +00:00
if ls config/chroot_sources/*.bootstrap.gpg > /dev/null 2>&1
2007-09-23 08:04:52 +00:00
then
2007-09-23 08:05:09 +00:00
for FILE in config/chroot_sources/*.bootstrap.gpg
2007-09-23 08:04:52 +00:00
do
cp ${FILE} chroot/root
Chroot "apt-key add /root/$(basename ${FILE})"
rm -f chroot/root/$(basename ${FILE})
2007-09-23 08:04:52 +00:00
done
fi
2007-09-23 08:04:46 +00:00
2007-09-23 08:04:52 +00:00
# Check local keyring packages
2007-09-23 08:05:11 +00:00
if ls config/chroot_sources/*.deb > /dev/null 2>&1
2007-09-23 08:04:52 +00:00
then
for PACKAGE in config/chroot_sources/*.deb
do
cp ${PACKAGE} chroot/root
Chroot "dpkg -i /root/$(basename ${PACKAGE})"
rm -f chroot/root/$(basename ${PACKAGE})
2007-09-23 08:04:52 +00:00
done
fi
2007-09-23 08:04:46 +00:00
2007-09-23 08:04:52 +00:00
# Installing aptitude
if [ "${LH_APT}" = "apt" ] || [ "${LH_APT}" = "apt-get" ]
then
Chroot "apt-get update"
elif [ "${LH_APT}" = "aptitude" ]
then
if [ ! -x /usr/bin/aptitude ]
then
Chroot "apt-get update"
Chroot "apt-get install --yes --force-yes aptitude"
fi
Chroot "aptitude update"
fi
# Installing keyring packages
2007-09-23 08:05:17 +00:00
if [ -n "${LH_KEYRING_PACKAGES}" ]
2007-09-23 08:04:52 +00:00
then
2007-09-23 08:05:17 +00:00
Chroot "apt-get install --yes --force-yes ${LH_KEYRING_PACKAGES}"
2007-09-23 08:04:52 +00:00
Chroot "apt-get update"
fi
if [ "${LH_CACHE_INDICES}" = "enabled" ]
then
2007-09-23 08:05:11 +00:00
mkdir -p cache/indices_bootstrap
2007-09-23 08:04:52 +00:00
2007-09-23 08:05:09 +00:00
cp -f chroot/etc/apt/secring.gpg* cache/indices_bootstrap
cp -f chroot/etc/apt/trusted.gpg* cache/indices_bootstrap
2007-09-23 08:04:52 +00:00
2007-09-23 08:05:09 +00:00
cp -f chroot/var/cache/apt/pkgcache.bin cache/indices_bootstrap
cp -f chroot/var/cache/apt/srcpkgcache.bin cache/indices_bootstrap
2007-09-23 08:04:52 +00:00
2007-09-23 08:05:09 +00:00
cp -f chroot/var/lib/apt/lists/*_Packages cache/indices_bootstrap
cp -f chroot/var/lib/apt/lists/*_Sources cache/indices_bootstrap
cp -f chroot/var/lib/apt/*_Release* cache/indices_bootstrap
2007-09-23 08:04:52 +00:00
fi
2007-09-23 08:04:49 +00:00
fi
2007-09-23 08:04:46 +00:00
# Creating stage file
2007-09-23 08:04:47 +00:00
Create_stagefile .stage/chroot_sources
2007-09-23 08:04:46 +00:00
;;
remove)
2007-09-23 08:05:12 +00:00
Echo_message "Deconfiguring file /etc/apt/sources.list"
2007-09-23 08:04:50 +00:00
# Checking lock file
Check_lockfile .lock
# Creating lock file
Create_lockfile .lock
2007-09-23 08:04:46 +00:00
# Configure generic indices
2007-09-23 08:05:17 +00:00
if [ "${LH_BINARY_INDICES}" = "enabled" ]
2007-09-23 08:04:46 +00:00
then
2007-09-23 08:04:49 +00:00
# Don't do anything if it's not required
2007-09-23 08:05:17 +00:00
if [ "${LH_MIRROR_BOOTSTRAP}" = "${LH_MIRROR_BINARY}" ] && \
[ "${LH_MIRROR_BOOTSTRAP_SECURITY}" = "${LH_MIRROR_BINARY_SECURITY}" ]
2007-09-23 08:04:49 +00:00
then
2007-09-23 08:05:16 +00:00
# Removing stage file
rm -f .stage/chroot_sources
2007-09-23 08:04:49 +00:00
exit 0
fi
2007-09-23 08:04:46 +00:00
# Cleaning apt list cache
2007-09-23 08:04:47 +00:00
rm -rf chroot/var/lib/apt/lists
mkdir -p chroot/var/lib/apt/lists/partial
2007-09-23 08:04:46 +00:00
2007-09-23 08:05:17 +00:00
echo "deb ${LH_MIRROR_BINARY} ${LH_DISTRIBUTION} ${LH_SECTIONS}" > chroot/etc/apt/sources.list
2007-09-23 08:04:46 +00:00
2007-09-23 08:05:17 +00:00
if [ "${LH_SOURCE}" = "enabled" ]
2007-09-23 08:04:46 +00:00
then
2007-09-23 08:05:17 +00:00
echo "deb-src ${LH_MIRROR_BINARY} ${LH_DISTRIBUTION} ${LH_SECTIONS}" >> chroot/etc/apt/sources.list
2007-09-23 08:04:46 +00:00
fi
2007-09-23 08:05:17 +00:00
if [ "${LH_SECURITY}" = "enabled" ]
2007-09-23 08:04:46 +00:00
then
2007-10-19 10:45:57 +00:00
if [ "${LH_DISTRIBUTION}" != "sid" ] && [ "${LH_DISTRIBUTION}" != "unstable" ]
then
echo "deb ${LH_MIRROR_BINARY_SECURITY} ${LH_DISTRIBUTION}/updates ${LH_SECTIONS}" >> chroot/etc/apt/sources.list
if [ "${LH_SOURCE}" = "enabled" ]
then
echo "deb-src ${LH_MIRROR_BINARY_SECURITY} ${LH_DISTRIBUTION}/updates ${LH_SECTIONS}" >> chroot/etc/apt/sources.list
fi
fi
2007-09-23 08:04:46 +00:00
fi
2007-09-23 08:04:47 +00:00
# Check local sources.list
2007-09-23 08:05:11 +00:00
if ls config/chroot_sources/*.binary > /dev/null 2>&1
2007-09-23 08:04:47 +00:00
then
echo "" >> chroot/etc/apt/sources.list
echo "# Custom repositories" >> chroot/etc/apt/sources.list
2007-09-23 08:04:49 +00:00
2007-09-23 08:05:09 +00:00
for FILE in config/chroot_sources/*.binary
2007-09-23 08:04:49 +00:00
do
2007-09-23 08:04:50 +00:00
cat ${FILE} | grep -v "^##" >> chroot/etc/apt/sources.list
2007-09-23 08:04:49 +00:00
done
fi
# Check local gpg keys
2007-09-23 08:05:11 +00:00
if ls config/chroot_sources/*.binary.gpg > /dev/null 2>&1
2007-09-23 08:04:49 +00:00
then
2007-09-23 08:05:09 +00:00
for FILE in config/chroot_sources/*.binary.gpg
2007-09-23 08:04:49 +00:00
do
cp ${FILE} chroot/root
Chroot "apt-key add /root/$(basename ${FILE})"
rm -f chroot/root/$(basename ${FILE})
2007-09-23 08:04:49 +00:00
done
2007-09-23 08:04:47 +00:00
fi
2007-09-23 08:04:46 +00:00
case "${LH_APT}" in
2007-09-23 08:04:47 +00:00
apt|apt-get)
2007-09-23 08:04:46 +00:00
Chroot "apt-get update"
;;
aptitude)
Chroot "aptitude update"
;;
esac
fi
# Cleaning apt packages cache
2007-09-23 08:04:47 +00:00
rm -rf chroot/var/cache/apt
mkdir -p chroot/var/cache/apt/archives/partial
2007-09-23 08:04:46 +00:00
# Removing stage file
2007-09-23 08:04:47 +00:00
rm -f .stage/chroot_sources
2007-09-23 08:04:46 +00:00
;;
*)
2007-09-23 08:04:48 +00:00
Usage
2007-09-23 08:04:46 +00:00
;;
esac