[Gentoo Linux] Update script

Hier kan je al jouw zelfgemaakte scripts delen met andere.

[Gentoo Linux] Update script

Berichtdoor Cybertinus » di nov 27, 2007 18:32

Hallo allemaal,

Zelf draai ik Gentoo Linux op m'n desktop als hoofd OS. Windows XP staat er nog wel op, maar die heb ik al in geen maanden geboot. Zoals bij elke Linux distro zijn er regelmatig nieuwe versies van allerlei software via de package manager te vinden. Die moet je dus installeren. Zelf heb ik nog wat extra bronnen toegevoegd waar ik eventueel nog nieuwere versie's vandaan kan halen dan dat er officieel wordt uitgegeven. Die software komt uit zogenaamde overlays. Na het updaten update ik ook nog even een database waarin de locatie van alle files op m'n disk staan, update ik een database waarin staat wat ik precies geinstalleerd heb, en draai ik nog een script wat de benodigde librarys van een executable in dat executable erbij zet, zodat alles wat sneller start. Al die taken bij elkaar zijn toch weel heel wat commando's. Daar had ik op een gegeven moment geen zin meer in en aangezien Gentoo een DIY distro is, heb ik een scrippie geschreven dat het updaten een heel stuk makkelijker maakt. Ik denk dat dit script redelijk voor zich spreekt als je Gentoo vaker gebruikt. Verder heb ik ook aardig wat commentaar erin gezet.
Zoals te zien is, heeft Boudewijn Ector ook wat aanpassingen gedaan in m'n script. Dat is ook iemand die regelmatig met Gentoo werkt en ik ken via het internet.
Dit script is overigens gewoon OSS. Het is vrijgegeven onder de BSD licentie. Dat houd in dat je er eigenlijk mee mag doen wat je wilt. Dus je mag het gebruiken (zowel als particulier als commercieel), mag aanpassen, opnieuw mag vrijgeven (eventueel zonder de broncode opnieuw vrij te geeven. Dit mag je doen zowel als particulier als commercieel). Je bent dus volledig vrij om ermee te doen wat je wilt. De enige beperking is dat je de copyright notice waarin de naam van Boudewijn en mij staat niet mag verwijderen. Verder mag je er eigenlijk alles mee doen.
Dit is het script:

Code: Selecteer alles
#!/bin/bash
#############################################################################
#                            GENTOO UPDATE SCRIPT                           #
#############################################################################

#############################################################################
#                                                                           #
# Author:  Tijn Buijs (Cybertinus) and Boudewijn Ector                      #
# Date:    November 24, 2007                                                #
# E-mail:  <my-nickname>@<my-nickname>.nl and firstname@firsnamelastname.nl #
#                                                                           #
# Copyright (c) 2007 Tijn Buijs and Boudewijn Ector                         #
#                                                                           #
# Permission to use, copy, modify, and distribute this software for any     #
# purpose with or without fee is hereby granted, provided that the above    #
# copyright notice and this permission notice appear in all copies.         #
#                                                                           #
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES  #
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF          #
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR   #
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES    #
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN     #
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF   #
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.            #
#                                                                           #
#############################################################################

#CHANGELOG:
#0.1   : initial version (TB)
#0.2   : commandline options (BE)
#0.3   : dynamic helper binary paths (BE)
#0.3.1 : fixed bug #1 ($LAYMAN_LOCATION ignored) (TB)
#        fixed bug #2 (extra ' after = at UPDATEDB_LOCATION) (TB)
#        fixed bug #3 (no - in the update-eix command) (TB)
#        added line to indicate that layman is starting (TB)
#        added $EMERGE_LOCATION to make the emerge an option too (TB)

#################
# CONFIGURATION #
#################

# Update layman?
RUN_LAYMAN='N'

# Run updatedb afterwards?
RUN_UPDATEDB='N'

# Run update-eix afterwards?
RUN_UPDATEEIX='N'

# Run prelink afterwards?
RUN_PRELINK='N'

# Locations (only required to set when you enable the corresponding command)
LAYMAN_LOCATION=`which layman`
UPDATEDB_LOCATION=`which updatedb`
UPDATEEIX_LOCATION=`which update-eix`
PRELINK_LOCATION='/etc/cron.daily/prelink'
EMERGE_LOCATION=`which emerge`


#################
# ACTUAL SCRIPT #
#################

# handle the commandline options  (By BE)
while [ -n "$(echo $1 | grep '-')" ]; do
        case $1 in

                # full options
                --layman ) RUN_LAYMAN='Y';;
                --updatedb ) RUN_UPDATEDB='Y';;
                --updateeix ) RUN_UPDATEEIX='Y';;
                --prelink ) RUN_PRELINK='Y';;


                #single char versions of options
                -l ) RUN_LAYMAN='Y';;
                -u ) RUN_UPDATEDB='Y';;
                -x ) RUN_UPDATEEIX='Y';;
                -p ) RUN_PRELINK='Y';;

        esac
        shift
done

#end of commandline option handling


# Update layman (overlays)
if [ "$RUN_LAYMAN" = 'Y' ] ; then
   echo 'Updating the Layman overlays now';
   $LAYMAN_LOCATION -S
fi

# Run normal updates
$EMERGE_LOCATION --sync
$EMERGE_LOCATION -pvuDN world
echo -n -e '\nWould you like to merge these packages? [\033[1;32mYes\033[0m/\033[1;31mNo\033[0m] '
read ANSWER
ANSWER=$(echo $ANSWER | tr '[A-Z]' '[a-z]')
if [ "$ANSWER" = "y" -o "$ANSWER" = "yes" ] ; then
   # Do regular updates
   $EMERGE_LOCATION -vuDN world

   # CHECK FOR POST-UPDATE COMMANDS
   # Check 1: run updatedb?
   if [ "$RUN_UPDATEDB" = 'Y' ] ; then
      echo -n 'Running updatedb now... '
      $UPDATEDB_LOCATION
      echo 'done'
   fi

   # Check 2: run update-eix? (for updating the eix database, faster searching in the portage database)
   if [ "$RUN_UPDATEEIX" = "Y" ] ; then
      echo 'Running update-eix now...'
      $UPDATEEIX_LOCATION
      echo 'Done updating the eix database';
   fi

   # Check 3: run prelink? See http://www.gentoo.org/doc/en/prelink-howto.xml for more information
   if [ "$RUN_PRELINK" = "Y" ] ; then
      echo -n 'Running prelink now... '
      $PRELINK_LOCATION
      echo 'done'
   fi
fi
"Been There, Done That, GOING BACK!" - Disneyland Parijs.
Avatar gebruiker
Cybertinus
 
Berichten: 135
Geregistreerd: ma aug 28, 2006 14:11
Woonplaats: In de buurt van Breda

Keer terug naar Scripts

Wie is er online

Gebruikers op dit forum: Geen geregistreerde gebruikers en 1 gast

cron