Last active
March 4, 2016 03:11
-
-
Save SavageCore/558390b15d62e70fd374 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# Bash script to setup testing alongside stable on Debian. | |
# Based on http://serverfault.com/a/382101 | |
# with fixes from http://serverfault.com/a/653552 | |
# FUNCTIONS # | |
# This is a general-purpose function to ask Yes/No questions in Bash, either | |
# with or without a default answer. It keeps repeating the question until it | |
# gets a valid answer. | |
# https://gist.github.com/davejamesmiller/1965569 | |
ask() { | |
# http://djm.me/ask | |
while true; do | |
if [ "${2:-}" = "Y" ]; then | |
prompt="Y/n" | |
default=Y | |
elif [ "${2:-}" = "N" ]; then | |
prompt="y/N" | |
default=N | |
else | |
prompt="y/n" | |
default= | |
fi | |
# Ask the question - use /dev/tty in case stdin is redirected from somewhere else | |
read -p "$1 [$prompt] " REPLY </dev/tty | |
# Default? | |
if [ -z "$REPLY" ]; then | |
REPLY=$default | |
fi | |
# Check if the reply is valid | |
case "$REPLY" in | |
Y*|y*) return 0 ;; | |
N*|n*) return 1 ;; | |
esac | |
done | |
} | |
if [[ $# -eq 0 ]] ; then | |
echo "Missing argument: mirror (http://ftp.nluug.nl/pub/os/Linux/distr/debian/)" | |
exit 0 | |
fi | |
echo "Creating files in /etc/apt/preferences.d..." | |
cat > /etc/apt/preferences.d/security.pref <<EOF | |
Package: * | |
Pin: release l=Debian-Security | |
Pin-Priority: 900 | |
EOF | |
cat > /etc/apt/preferences.d/stable.pref <<EOF | |
Package: * | |
Pin: release a=stable | |
Pin-Priority: 995 | |
EOF | |
cat > /etc/apt/preferences.d/testing.pref <<EOF | |
Package: * | |
Pin: release a=testing | |
Pin-Priority: 750 | |
EOF | |
cat > /etc/apt/preferences.d/unstable.pref <<EOF | |
Package: * | |
Pin: release a=unstable | |
Pin-Priority: 50 | |
EOF | |
cat > /etc/apt/preferences.d/experimental.pref <<EOF | |
Package: * | |
Pin: release a=experimental | |
Pin-Priority: 1 | |
EOF | |
echo "Created files in /etc/apt/preferences.d" | |
echo "" | |
echo "Creating files in /etc/apt/sources.list.d" | |
cat > /etc/apt/sources.list.d/security.list <<EOF | |
deb http://security.debian.org/ stable/updates main contrib non-free | |
deb http://security.debian.org/ testing/updates main contrib non-free | |
EOF | |
cat > /etc/apt/sources.list.d/stable.list <<EOF | |
deb $1 stable main contrib non-free | |
deb-src $1 stable main contrib non-free | |
deb http://ftp.debian.org/debian/ stable main contrib non-free | |
deb-src http://ftp.debian.org/debian/ stable main contrib non-free | |
EOF | |
cat > /etc/apt/sources.list.d/testing.list <<EOF | |
deb $1 testing main contrib non-free | |
deb-src $1 testing main contrib non-free | |
deb http://ftp.debian.org/debian/ testing main contrib non-free | |
deb-src http://ftp.debian.org/debian/ testing main contrib non-free | |
EOF | |
cat > /etc/apt/sources.list.d/unstable.list <<EOF | |
deb $1 unstable main contrib non-free | |
deb-src $1 unstable main contrib non-free | |
deb http://ftp.debian.org/debian/ unstable main contrib non-free | |
deb-src http://ftp.debian.org/debian/ unstable main contrib non-free | |
EOF | |
cat > /etc/apt/sources.list.d/experimental.list <<EOF | |
deb $1 experimental main contrib non-free | |
deb-src $1 experimental main contrib non-free | |
deb http://ftp.debian.org/debian/ experimental main contrib non-free | |
deb-src http://ftp.debian.org/debian/ experimental main contrib non-free | |
EOF | |
echo "Created files in /etc/apt/sources.list.d" | |
echo "" | |
# Default to No if the user presses enter without giving an answer: | |
if ask "Do you want to run apt-get update now?" N; then | |
sudo apt-get update | |
echo "" | |
echo "Done! Testing enabled." | |
else | |
echo "" | |
echo "Ok. Please verify the files and run apt-get update manually later." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment