#!/bin/bash # Script to generate (a nice, neat) sources.list from user input # # Feel free to redistribute, derive, and include, but send me mail if you're # doing something neat with it # # Feedback welcome! Send mail to sheeettin@gmail.com # Arg handling first, I guess case $1 in -h | --help) echo "Usage: $0 [OPTION]" echo "Generate a nice, neat sources.list based on user input" echo "" echo " -h, --help Display this message" echo " -o, --output Set file to write to. Defaults to /etc/apt/sources.list." exit 0 ;; -o | --output) outfile="$2" ;; esac if [ ! "$outfile" ] then outfile=/etc/apt/sources.list fi # Make sure we have write access (a test would take a few ifs, so we'll go with this) if touch $outfile then true else echo "couldn't write to $outfile--do you need to be root?" exit 1 fi # This is 80+9 characters--don't go past it for reads ----------------------------------| read -p "First question: the local mirror (two-letter country code or none): " ccode echo "You want the main repositories, trust me on this one. So..." read -p "Do you want the restricted repositories (proprietary drivers)? (y/n) [n] " restricted read -p "Universe repositories (community-maintained packages)? (y/n) [y] " universe read -p "Multiverse (software restricted by copyright or legal issues)? (y/n) [n] " multiverse echo "" echo "Okay. Now, do you want to enable retrieving sources? These'll come in" read -p "handy if you want to compile something in the repos yourself. (y/n) [n] " source echo "" read -p "Next up: updates. You probably want these. (y/n) [y] " updates read -p "How about security fixes? (y/n) [y] " security echo "And backports? These are updates made after a release but not officially" read -p "supported. (y/n) [n] " backports read -p "Last question: the \"proposed\" repository. Basically, beta software. (y/n) [n] " proposed echo "" echo "Great! Making backup if necessary, generating, and writing out now." if [ -e "$outfile" ] then mv -f "$outfile" "$outfile.bak" fi # This makes making the lines much easier # Anything but the opposite of the default is considered to be the default case "$restricted" in y) restricted=" restricted" ;; *) restricted="" ;; esac case "$universe" in n) universe="" ;; *) universe=" universe" ;; esac case "$multiverse" in y) multiverse=" multiverse" ;; *) multiverse="" ;; esac case "$source" in y) source="deb-src" ;; *) source="" ;; esac if [ "$ccode" ] then ccode="$ccode." fi echo "## Feisty repositories" > $outfile echo "deb http://$(echo $ccode)archive.ubuntu.com/ubuntu/ feisty main$restricted$universe$multiverse" >> $outfile if [ $source ] then echo "deb-src http://$(echo $ccode)archive.ubuntu.com/ubuntu/ feisty main$restricted$universe$multiverse" >> $outfile fi echo "" >> $outfile # This could probably be done better with a for loop. Unfortunately, I'm not familiar with them. if [ "$updates" != n ] then echo "deb http://$(echo $ccode)archive.ubuntu.com/ubuntu/ feisty-updates main$restricted$universe$multiverse" >> $outfile if [ $source ] then echo "deb-src http://$(echo $ccode)archive.ubuntu.com/ubuntu/ feisty-updates main$restricted$universe$multiverse" >> $outfile fi fi echo "" >> $outfile if [ "$security" != n ] then echo "deb http://$(echo $ccode)archive.ubuntu.com/ubuntu/ feisty-security main$restricted$universe$multiverse" >> $outfile if [ $source ] then echo "deb-src http://$(echo $ccode)archive.ubuntu.com/ubuntu/ feisty-security main$restricted$universe$multiverse" >> $outfile fi fi echo "" >> $outfile if [ "$backports" != n ] then echo "deb http://$(echo $ccode)archive.ubuntu.com/ubuntu/ feisty-backports main$restricted$universe$multiverse" >> $outfile if [ $source ] then echo "deb-src http://$(echo $ccode)archive.ubuntu.com/ubuntu/ feisty-backports main$restricted$universe$multiverse" >> $outfile fi fi echo "" >> $outfile if [ "$proposed" != n ] then echo "deb http://$(echo $ccode)archive.ubuntu.com/ubuntu/ feisty-proposed main$restricted$universe$multiverse" >> $outfile if [ $source ] then echo "deb-src http://$(echo $ccode)archive.ubuntu.com/ubuntu/ feisty-proposed main$restricted$universe$multiverse" >> $outfile fi fi echo "Done! sources.list written to $outfile."