Sources-list Tool

This blog post has been published on 2010-01-31 and may be out of date.

Zum Üben habe ich mir vor ein paar Monaten ein kleines Shell-Skript gebaut,welches mit Arrays, Dialog Boxen und vielen mehr arbeitet, im Grunde kann das Skript nicht viel, aber vielleicht Hilft es da jemand als Beispiel weiter… :)

#!/bin/bash

#######################################################################
# Title      :    sources.list_tool
# Author     :    Voku (voku-online.de)
# Date       :    2009-05-25
# Requires   :    dialog
#######################################################################

VER='0.3'

_temp="/tmp/answer.$$"
sources="/etc/apt/sources.list"
sources_temp="/tmp/sources.list"
backup="/etc/apt/backup"
backup_old="/etc/apt/backup_old"
dialog 2>$_temp
du=`whoami`

if [ $du != "root" ]; then
        dialog --title " Du bist nicht root " --msgbox "nDu bist nicht root, du bist '$du'!nn(versuche es mal mit "sudo $0")" 8 44
        exit
fi

if [ -d $backup ] ; then
        if [ -f $backup/*.bz2 ]; then
                bzip2 -z -f -q $(find $backup -mtime +1)
        fi
else
        mkdir $backup
fi

if [ -d $backup_old ]; then
        find $backup -iregex '.*.(bz2)' -mtime +7 -exec mv {} $backup_old ;
        find $backup_old -iregex '.*.(bz2)' -mtime +30 -exec rm {} ;
else
        mkdir $backup_old
fi

cp -p $sources $backup/sources.old.$(date "+%y%m%d-%H%M")
cp -p $sources $sources_temp

SUBJECT="[`hostname`] Update Hinweis"
MESSAGE="SYSTEMMELDUNG:nAuf `hostname` sind neue Updates vorhanden"
COUNT=`apt-get -s upgrade | grep -c "Inst"`
if [ $COUNT -gt 0 ]; then
        dialog --title " $SUBJECT " --msgbox "n`echo -e "$MESSAGE"`" 10 50
fi

checklist() {

launchpad ()
{
grep -iv $1 $sources > $sources_temp
cp -p $sources_temp $sources
a="## $2 ($1)"
b="deb http://ppa.launchpad.net/$1/ubuntu jaunty main"
c="deb-src http://ppa.launchpad.net/$1/ubuntu jaunty main"
echo -e "$a" "n$b" "n$c" >> $sources
}

    dialog --backtitle "Extra-Repositories"
           --checklist "Extra-Repositories: fuer Ubuntu 9.04" 40 50 15
           01 "Medibuntu" off
           02 "Ubuntu Netbook Remix" off
           03 "Avant Window Navigator" off
           04 "Vuze (Azureus)" off
           05 "Firefox 3, Thunderbird 3" off
           06 "Terminator" off
           07 "GIMP" off
           08 "Compiz" off
           09 "OpenOffice 3" off
           10 "Gnome DO" off
           11 "Ubuntu Tweak" off
           12 "Rhythmbox" off
           13 "FreeNX" off
           14 "Adobe Flash" off
           15 "Extra Ubuntu Themes" off
           16 "Wine" off
           17 "VirtualBox" off
           18 "Swiftfox" off
           19 "VLC Media Player" off
           20 "Pidgin" off
           21 "Rhythmbox" off
           22 "Claws Mail" off
           23 "Google-Gadgets" off 2>$_temp
    if [ ${?} -ne 0 ]; then return; fi
    result=`cat $_temp`
    array=($result)

    dialog --title " Extra-Repositories " --yesno "Moechtest du die Extra-Repositories wirklich eintragen?" 6 44
    result1=$?
    if [ $result1 = "1" ]; then return; fi

for i in ${array[@]}; do

        case $i in
        "01")
                grep -iv medibuntu $sources > $sources_temp
                cp -p $sources_temp $sources
                wget http://packages.medibuntu.org/medibuntu-key.gpg && sudo apt-key add medibuntu-key.gpg && rm medibuntu-key.gpg
                a="## Medibuntu"
                b="# Please report any bug on https://bugs.launchpad.net/medibuntu/"
                c="# wget http://packages.medibuntu.org/medibuntu-key.gpg && sudo apt-key add medibuntu-key.gpg && rm medibuntu-key.gpg"
                d="deb http://packages.medibuntu.org/ jaunty free non-free"
                e="deb-src http://packages.medibuntu.org/ jaunty free non-free"
                echo -e "$a" "n$b" "n$c" "n$d" "n$e" >> $sources
        ;;
        "02")
                launchpad "netbook-remix-team" "Ubuntu Netbook Remix"
        ;;
        "03")
                launchpad "awn-testing" "AWN"
        ;;
        "04")
                launchpad "smaioli" "Vuze"
        ;;
        "05")
                launchpad "steveydoteu" "Firefox 3.1 und Thunderbird 3.0"
                lanuchpad "mozillateam" "Mozilla Team"
                lanuchpad "fta" "Mozilla Development Stuff"
        ;;
        "06")
                launchpad "gnome-terminator" "Terminator"
        ;;
        "07")
                launchpad "c-korn" "GIMP 2.6"
        ;;
        "08")
                launchpad "compiz" "Compiz"
                launchpad "tormodvolden" "nice xserver"
        ;;
        "09")
                launchpad "openoffice-pkgs" "OpenOffice 3"
        ;;
        "10")
                launchpad "do-core" "Gnome DO"
        ;;
        "11")
                launchpad "tualatrix" "Ubuntu Tweak"
        ;;
        "12")
                launchpad "jmillikin" "Rhythmbox"
        ;;
        "13")
                launchpad "freenx-team" "freenx, nxagent"
        ;;
        "14")
                launchpad "psyke83" "PulseAudio Fixes & Adobe Flash"
                launchpad "themuso" "PulseAudio - Preview Packages"
                launchpad "ubuntu-ko" "unzip, sbackup, flashplugin-nonfree"
        ;;
        "15")
                launchpad "murrine-themes" "Murrine Themes"
                launchpad "kwwii" "Intrepid theme"
        ;;
        "16")
                grep -iv wine.budgetdedicated $sources > $sources_temp
                cp -p $sources_temp $sources
                wget -q http://wine.budgetdedicated.com/apt/387EE263.gpg -O- | sudo apt-key add -
                a="## Wine (wine.budgetdedicated)"
                b="# wget -q http://wine.budgetdedicated.com/apt/387EE263.gpg -O- | sudo apt-key add -"
                c="deb http://wine.budgetdedicated.com/apt jaunty main"
                d="deb-src http://wine.budgetdedicated.com/apt jaunty main"
                echo -e "$a" "n$b" "n$c" "n$d" >> $sources
        ;;
        "17")
                grep -iv download.virtualbox $sources > $sources_temp
                cp -p $sources_temp $sources
                a="## VirtualBox (download.virtualbox)"
                b="deb http://download.virtualbox.org/virtualbox/debian jaunty non-free"
                echo -e "$a" "n$b" >> $sources
        ;;
        "18")
                grep -iv getswiftfox $sources > $sources_temp
                cp -p $sources_temp $sources
                a="## Swiftfox (getswiftfox)"
                b="deb http://getswiftfox.com/builds/debian unstable non-free"
                echo -e "$a" "n$b" >> $sources
        ;;
        "19")
                launchpad "motumedia" "VLC"
        ;;
        "20")
                launchpad "nicolai-spohrer" "Pidgin"
                launchpad "hyperair" "Pidgin, Gaim"
                launchpad "pidgin-developers" "Pidgin"
        ;;
        "21")
                launchpad "bigon" "empathy, rhythmbox"
                launchpad "jmillikin" "rhythmbox-svn"
        ;;
        "22")
                launchpad "claws-mail" "Claws Mail"
        ;;
        "23")
                launchpad "googlegadgets" "Google-Gadgets"
        ;;
        *)
                echo "Fehler?!?!"
        ;;
        esac

done
}

radiolist() {
    dialog --backtitle "Sources.list - Ubuntu Version"
           --radiolist "Ubuntu Version waehlen" 15 50 8
           01 "gutsy" off
           02 "hardy" off
           03 "intrepid" off
           04 "jaunty" on 2>$_temp
    if [ ${?} -ne 0 ]; then return; fi
    result=`cat $_temp`

    case $result in
    01)
        ubuntu_version="gutsy"
    ;;
    02)
        ubuntu_version="hardy"
    ;;
    03)
        ubuntu_version="intrepid"
    ;;
    04)
        ubuntu_version="jaunty"
    ;;
    *)
        ubuntu_version="FEHLER"
    ;;
    esac

    if [ $ubuntu_version = "FEHLER" ]; then
            continue
    else

          dialog --title " Ubuntu Version waehlen " --yesno "Moechtest du wirklich alle sources.list Eintraege auf '$ubuntu_version' aendern?" 6 44
          result1=$?

          if [ $result1 = "1" ]; then return; fi

          case $result in
          01)
                    sed -i -n -e "s/jaunty/gutsy/g" $sources
                    sed -i -n -e "s/hardy/gutsy/g" $sources
                    sed -i -n -e "s/intrepid/gutsy/g" $sources
          ;;
          02)
                    sed -i -n -e "s/jaunty/hardy/g" $sources
                    sed -i -n -e "s/gutsy/hardy/g" $sources
                    sed -i -n -e "s/intrepid/hardy/g" $sources
          ;;
          03)
                    sed -i -n -e "s/jaunty/intrepid/g" $sources
                    sed -i -n -e "s/gutsy/intrepid/g" $sources
                    sed -i -n -e "s/hardy/intrepid/g" $sources
          ;;
          04)
                    sed -i -n -e "s/jaunty/jaunty/g" $sources
                    sed -i -n -e "s/gutsy/jaunty/g" $sources
                    sed -i -n -e "s/hardy/jaunty/g" $sources
          ;;

          *)
                    continue
          ;;
          esac
    fi
} 

formbox () {
    dialog --backtitle "Repositories eintragen"
            --form " Repositories eintragen - use [up] [down] to select input field " 21 70 18
            "URL" 2 4 "http://de.archive.ubuntu.com/ubuntu/" 2 15 50 0
            "Ubuntu" 4 4 "jaunty" 4 15 20 0
            "was?" 6 4 "main" 6 15 50 0
            2>$_temp

    if [ ${?} -ne 0 ]; then return; fi
    result=`cat $_temp`
    dialog --title " Repositories eintragen " --yesno "Moechtest du wirklich folgendes wirklich eintragen n deb $result" 10 75
    result1=$?
    if [ $result1 = "1" ]; then return; fi
    echo "deb "$result >> $sources
    dialog --title "neuer Eintag in der sources.list"
           --msgbox "n deb $result" 10 75
}

textbox() {
wget -q http://www.voku-online.de/sources_new.txt -O $sources_temp &

wget_pid=$!
while [ 1 ]; do
        { for I in $(seq 1 100) ; do
        echo $I
        sleep 0.01
        done
        echo 100; } | dialog --backtitle "Dialog - Progress sample"
                             --gauge "Progress" 6 60 0

    if [ `ps | grep -c $wget_pid` -eq 0 ]; then
        break
    fi
done

    if [ -e $sources_temp ]; then
        dialog --backtitle "voku-online.de - Sources.list fuer Ubuntu 9.04 - use [up] [down] to scroll"
               --begin 3 5 --title " File: $sources_temp "
               --textbox $sources_temp 50 140
    else
        dialog --msgbox "*** ERROR ***n$sources_temp ist nicht vorhanden" 6 42
    fi
}

main_menu() {
    dialog --backtitle "voku-online.de" --title " Sources.list Tools - V. $VER "
        --cancel-label "Quit"
        --menu "Move using [UP] [DOWN], [Enter] to select" 15 80 10
        Deine_Sources.list "Deine source.list (less [q - zum beenden])"
        Repositories "Repositories eintragen"
        Extra-Repositories "Extra-Repositories: fuer Ubuntu 8.10"
        Ubuntu_Version "Waehle eine Ubuntu-Version"
        Aktuelle_Sources.list "Aktuelle source.list von voku-online.de anzeigen"
        Update "Paketdefinitionen aktualisieren"
        Quit "Exit" 2>$_temp

    opt=${?}
    if [ $opt != 0 ]; then rm $_temp; exit; fi
    menuitem=`cat $_temp`
    echo "menu=$menuitem"
    case $menuitem in
        Deine_Sources.list) less /etc/apt/sources.list;;
        Repositories) formbox;;
        Extra-Repositories) checklist;;
        Ubuntu_Version) radiolist;;
        Aktuelle_Sources.list) textbox;;
        Update) apt-get update;;
        Quit) rm $_temp; rm $sources_temp; rm $apt_get_dist_upgrade_temp; exit;;
    esac
}

while true; do
  main_menu
done

Published by

voku

Lars Moelleken | Ich bin root, ich darf das!

%d bloggers like this: