[bglug] apt-sourcesconf v0.1
k|b|s
kbs@bglug.it
Mar 21 Giu 2005 17:55:39 CEST
Ogni volta che vengo al lug per aggiornare la distro devo editare a mano il
file sources.list. Ergo bisogna fare uno script...
Provatelo e mandatemi feedbacks di ogni genere.
Have fun ;^)
--8<-- CUT HERE --8<--
#!/bin/bash
#
# apt-sourcesconf v0.1 by k|b|s <kbs(at)despammed(dot)com>
# simple script to modify on the fly your apt's sources.list
# License: GPL
#
# $Last modified: 2005/06/21 17:09:15 kbs Exp $
## Customize:
editor="vim"
# Country list for apt-spy
# example: "IT,AT,CH"
country_list="IT"
#### Below is probably ok...
## Are you root?
if [ ! `id -u` -eq 0 ];then
echo "su root, dude..."
exit
fi
## Create /etc dir
if [ ! -d /etc/apt-sourcesconf ]; then
mkdir -p /etc/apt-sourcesconf
fi
## Automatic backup of original sources.list
if [ ! -f /etc/apt-sourcesconf/backup ]; then
cp /etc/apt/sources.list /etc/apt-sourcesconf/backup
fi
list="`ls /etc/apt-sourcesconf/* |sed '/backup/d' | grep -v "^#" |sed 's/\/etc\/apt-sourcesconf\///g' |awk '{print "\t",FNR, $1}'`"
listn="`ls /etc/apt-sourcesconf | sed '/backup/d' |wc -l`"
link="`ls -l /etc/apt/sources.list |awk '{print $10}' | sed 's/\/etc\/apt-sourcesconf\///'`"
## Do the job
if test $# -eq 0
then
echo "Available apt-sources:"
echo "$list"
echo "Your choiche: [1-$listn] >"
read answer
source="`ls /etc/apt-sourcesconf/* |sed '/backup/d' | grep -v "^#" | awk "{ if (FNR == $answer) print $1 }"`"
ln -sf $source /etc/apt/sources.list
echo "...done"
echo "Do you want to update now? [y|N]"
read update
case $update in
y|Y)
apt-get update
;;
*)
exit
;;
esac
exit
fi
## Options
case $1 in
h|-h|--h|-help|--help)
echo "apt-sourcesconf v0.1 by k|b|s"
echo " usage: apt-sourcesconf -<cehlnrsu>"
echo " -c create (create a sources file with apt-spy)"
echo " -e edit (edit sources.list)"
echo " -h help (this help)"
echo " -l list (list available sources)"
echo " -n new (create a new source file)"
echo " -r restore (restore original sources.list)"
echo " -s show (show the linked sources.list)"
echo " -u update (update the sources)"
exit
;;
-c|c|create)
echo "Which distribution:"
echo "1 Stable"
echo "2 Unstable"
echo "3 Testing"
read distro
case $distro in
1)
dist=stable
;;
2)
dist=unstable
;;
3)
dist=testing
;;
esac
echo "Creating a sources.list with apt-spy..."
apt-spy -d $dist -s $country_list -o /etc/apt-sourcesconf/apt-spy.$dist
echo "...done"
;;
-l|l|list)
echo "List of available apt-sources:"
echo "$list"
;;
-e|e|edit)
$editor /etc/apt/sources.list
;;
-n|n|new)
echo "Write a name for your source"
read name
$editor /etc/apt-sourcesconf/$name
;;
-s|s|show)
if [ ! -L /etc/apt/sources.list ]; then
echo "Your sources.list is untouched"
else
echo "Available sources:"
echo "$list"
echo "Your sources.list is linked to: $link"
fi
;;
-r|r|restore)
echo "Restoring your original sources.list..."
rm -f /etc/apt/sources.list
cp /etc/apt-sourcesconf/backup /etc/apt/sources.list
echo "...done"
;;
-u|u|update)
echo "Updating..."
apt-get update
echo "...done"
;;
esac
--8<-- CUT HERE --8<--
--
Non disperdere il vetro nell'ambiente.
k|b|s ~> mailto `echo ti.gulgb@sbk|'rev'`
Maggiori informazioni sulla lista
bglug