Created
October 21, 2013 17:08
-
-
Save rpavlik/7087314 to your computer and use it in GitHub Desktop.
Selectively adding packages from Debian Testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
RELEASE=testing | |
PREFS=/etc/apt/preferences.d/debian-${RELEASE} | |
PRIORITY=300 | |
# Set up two variables: one with the package names, and one with package | |
# names followed by /testing (for example) | |
PACKAGENAMES="$@" | |
for pkg in "$@"; do | |
PACKAGENAMES_WITH_RELEASE="${PACKAGENAMES_WITH_RELEASE} ${pkg}/${RELEASE}" | |
done | |
# Variables used in the prefs file comment | |
SCRIPT=$(readlink -f ${0}) | |
DATESTAMP=$(date) | |
simcommand="apt-get --simulate --quiet install ${PACKAGENAMES_WITH_RELEASE}" | |
installcmd="sudo apt-get --quiet install ${PACKAGENAMES_WITH_RELEASE}" | |
# Check to see if it's feasible with just the packages listed | |
${simcommand} > /dev/null 2>&1 | |
if [ $? -eq 0 ]; then | |
echo "Package removals/installations along with source distro/release:" | |
echo "----------------------------------------------------------------" | |
${simcommand} | egrep "^Inst|^Remv" | |
if [ ! $? -eq 0 ]; then | |
cat <<-EOF | |
NONE! | |
Warning: The install command | |
${installcmd} | |
appears to not actually change anything. Perhaps you've already used | |
this script for those packages? | |
You can continue, but all this script will do is: | |
EOF | |
installcmd="echo 'Skipping install command'" | |
else | |
cat <<-EOF | |
This install is possible. If you continue, this script will: | |
- Perform the above operations by running the command: | |
${installcmd} | |
EOF | |
fi | |
echo " - Pin the following to '${RELEASE}' with priority ${PRIORITY} by appending to '${PREFS}':" | |
for pkg in ${PACKAGENAMES}; do | |
echo " ${pkg}" | |
done | |
cat <<-EOF | |
To continue, please type a summary for this group to be used as a comment in '${PREFS}'. | |
To cancel, press Ctrl-C or hit enter without entering a summary. | |
EOF | |
# Read comment or allow cancellation | |
read COMMENT || exit 1 | |
if [ "x${COMMENT}" == "x" ]; then | |
echo "Empty comment - exiting." | |
exit 1 | |
fi | |
echo "Will continue to install and pin group '${COMMENT}'" | |
sudo -v | |
# Clever way of doing a heredoc with sudo | |
sudo bash -c "cat >> ${PREFS}" <<-EOF | |
# ${COMMENT} | |
# Added by ${SCRIPT} on ${DATESTAMP} | |
Package: ${PACKAGENAMES} | |
Pin: release a=${RELEASE} | |
Pin-Priority: ${PRIORITY} | |
EOF | |
else | |
cat <<-EOF | |
Incomplete package group - must specify more package names | |
Output from simulating '${installcmd}': | |
------- | |
EOF | |
${simcommand} | |
cat <<-EOF | |
------- | |
Consider re-running $0 with additional package names to install | |
from testing to satisfy the dependencies listed above. | |
EOF | |
exit 1 | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Default to not use packages from testing unless it's the only way | |
Package: * | |
Pin: release a=testing | |
Pin-Priority: 50 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
deb http://ftp.us.debian.org/debian testing main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment