Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[PORTAGE] Gentoo sans Internet (offline-emerge)
View unanswered posts
View posts from last 24 hours

Goto page Previous  1, 2, 3  Next  
Reply to topic    Gentoo Forums Forum Index French
View previous topic :: View next topic  
Author Message
blasserre
Veteran
Veteran


Joined: 10 Feb 2004
Posts: 1362
Location: Lille, Vlaanderen

PostPosted: Thu Nov 09, 2006 7:27 pm    Post subject: Reply with quote

là je ne peux pas te dire, je n'utilise que de vraies distribs :mrgreen:

EDIT : mais dis-donc ? t'es encore au labo à 20h30 toi :? tu me feras le plaisir d'aller profiter un peu des latines
_________________
benj

technicien professionnel, ascendant winner
Back to top
View user's profile Send private message
Il turisto
l33t
l33t


Joined: 12 May 2004
Posts: 968
Location: Battincourt - Belgique

PostPosted: Fri Nov 10, 2006 8:33 am    Post subject: Reply with quote

Je suis quasi sur que le if fonctionne car je l'ai déjà utilisé dans des scripts. Sous gentoo le wget renvoie bien le code d'erreur.
Back to top
View user's profile Send private message
Magic Banana
Veteran
Veteran


Joined: 13 Dec 2005
Posts: 1912
Location: Belo Horizonte, Minas Gerais, Brasil

PostPosted: Fri Nov 10, 2006 10:10 am    Post subject: Reply with quote

Effectivement... Je ne sais pas ce que j'ai fait hier ! :oops: Aujourd'hui j'ai bien le comportement voulu.

Bon... Je n'ai pas fait travaillé mes scripts hier soir pour deux raisons. La première est que j'ai "profité un peu des latines" (pour citer blasserre). La seconde est que depuis que je suis sans Internet, je n'ai jamais autant installé de chose ! :D Test de mes scripts oblige. Du coup hier, j'ai installé xmoto et je dois dire qu'il est bien sympa ce p'tit jeu ! :D
Back to top
View user's profile Send private message
Il turisto
l33t
l33t


Joined: 12 May 2004
Posts: 968
Location: Battincourt - Belgique

PostPosted: Fri Nov 10, 2006 10:15 am    Post subject: Reply with quote

Tu parles. Tu dis que tu as essayé alors que tu regardais mes jolies compatriotes par la fenêtre.

Pas bien...

Fais attention quand même car elles dominent les filles la bas :-).



Bon je sors installer xmoto moi (une fois que beryl aura fini de compiler).
Back to top
View user's profile Send private message
Magic Banana
Veteran
Veteran


Joined: 13 Dec 2005
Posts: 1912
Location: Belo Horizonte, Minas Gerais, Brasil

PostPosted: Fri Nov 10, 2006 10:18 am    Post subject: Reply with quote

En fait, c'est pas une latine italienne mais une latine brésilienne... Je suis comme ça moi. Lorsque j'étais au Danemark j'étais avec une russe, lorsque je suis en Italie, je suis avec une brésilienne. :D
Back to top
View user's profile Send private message
Magic Banana
Veteran
Veteran


Joined: 13 Dec 2005
Posts: 1912
Location: Belo Horizonte, Minas Gerais, Brasil

PostPosted: Sat Nov 11, 2006 7:36 pm    Post subject: Reply with quote

Je passe au laboratoire dans l'espoir que quelques uns d'entre vous prennent le temps de tester un peu la dernière version de mon script.

J'ai bien travaillé et suis assez fier du résultat ! :P Toutes les fonctions souhaitées sont implémentées. En fait je ne vois rien de plus à ajouter ! :P

Il n'y a maintenant plus qu'un seul long script qui dissimule les trois précédents :
remote-emerge:
#!/bin/bash
# Distributed under the terms of the GNU General Public License v2
# AUTHOR: Magic Banana

# Variables definitions
source /etc/make.globals
source /etc/make.conf
if [ -z "$MOVINGDIR" ]
    then
    echo "MOVINGDIR must be the name of a directory on an amovible device. Please set this variable in /etc/make.conf. You can, for instance, adapt the following command:
echo 'MOVINGDIR=\"/media/usbdisk/moving-portage\"' >> /etc/make.conf"
    exit
fi

# If there is a distfiles directory on the amovible device copy its content in "$DISTDIR"
if [ ! -d "$MOVINGDIR" ]
    then
    mkdir -p -m 755 "$MOVINGDIR"
elif [ -d "$MOVINGDIR"/distfiles ]
    then
    for sourcefile in "$MOVINGDIR"/distfiles/*
      do
      if ! grep "${sourcefile##*/}" "$MOVINGDIR"/partial_fetch &> /dev/null
     then
     mv "$sourcefile" "$DISTDIR"
      fi
    done
# I love clean permissions :
    chmod 644 "$DISTDIR"/*
fi

# remote-emerge --oldactions
if [ "$*" = "--oldactions" ]
    then
    if [ -d "$MOVINGDIR"/urls ]
   then
   for URLlist in "$MOVINGDIR"/urls/*
     do
     remote-emerge "${URLlist##*/}"
   done
    fi
    SNAPSHOT=`ls "$MOVINGDIR"/portage-[2-9][0-9][0-9][0-9][0-1][0-9][0-3][0-9].tar.bz2 2> /dev/null`
    if [ -n "$SNAPSHOT" ]
   then
# There is a new Portage tree
   if ! grep ^portage$ "$MOVINGDIR"/partial_fetch &> /dev/null
       then
# It was totally downloaded
# Remove the old one (but keep the precious disfiles, the packages and the rpms)
       for file in "$PORTDIR"/*
         do
         if [ "$file" != "$DISTDIR" -a "$file" != "$PKGDIR" -a "$file" != "$RPMDIR" ]
        then
        rm -rf "$file"
         fi
       done
# Install the new Portage tree
       tar -xvjf "$SNAPSHOT" -C "$PORTDIR"/..
# Update Portage cache
       /usr/bin/emerge --metadata
       rm "$SNAPSHOT"
   fi
    fi
else

# For any operation which does not require any fetch, use directly emerge
    for arg in $*
      do
      case $arg in
     --help|-*h*       ) echo "
remote-emerge allows you to administrate offline your system in exactly the
same way and with the same syntax as emerge. However the option --sync is not
used since fetching the Portage tree is considered as a permanent request.
To perform every action previously requested and synchronize your Portage
tree (in the limit of what has been fetched), symply run
'remote-emerge --oldactions'." && /usr/bin/emerge $* && exit;;
     --oldactions      ) echo "
To perform every action previously requested and synchronize your Portage
tree (in the limit of what has been fetched), symply run
'remote-emerge --oldactions' without other option." && exit;;
     --sync            ) echo "
The option --sync is not used since fetching the Portage is considered
as a permanent request. To perform every action previously requested and
synchronize your Portage tree (in the limit of what has been fetched),
symply run 'remote-emerge --oldactions'." && exit;;
     --version|-*V*    ) echo "remote-emerge 0.1" && /usr/bin/emerge $* && exit;;
     --clean|--depclean|--info|--metadata|--pretend|--prune|--regen|--search|--searchdesc|-*c*|-*p*|-*P*|-*s*|-*S* ) /usr/bin/emerge $* && exit;;
      esac
    done

# Create "$MOVINGDIR"/urls if not already there
    if [ ! -d "$MOVINGDIR"/urls ]
   then
   mkdir -m 755 "$MOVINGDIR"/urls
    fi

# Create the list of urls to fetch in order to perform the requested action
    newline='
'
    tempfile1=`tempfile`
    /usr/bin/emerge -fp $* 1> /dev/null 2> "$tempfile1"
    tempfile2=`tempfile`
# Strip out fetch-restrict messages, turn spaces into newlines and remove blank lines
    cat "$tempfile1" | grep -v '^!!!' | cut -d " " -f 1- --output-delim="$newline" | grep -v '^$' > "$tempfile2"
    rm "$tempfile1"
    if [ -f "$MOVINGDIR/urls/$*" ]
   then
# This command has been invoked earlier without being satisfied, remove the old urls
   rm "$MOVINGDIR/urls/$*"
    fi
# Skip files already in "$DISTDIR" and write the URLs on the amovible device
    last=""
    while read url
      do
      if [ "${url##*/}" = "$last" ]
     then
     if [ -n "$isabsent" ]
         then
         echo "$url" >> "$MOVINGDIR/urls/$*"
     fi
      else
     if [ -f "$DISTDIR/${url##*/}" ]
         then
         isabsent=""
     else
         echo "$url" >> "$MOVINGDIR/urls/$*"
         isabsent="t"
     fi
     last="${url##*/}"
      fi
    done < "$tempfile2"
    if [ -f "$MOVINGDIR/urls/$*" ]
   then
   echo "From a machine connected to Internet, please run the script remote-fetch present on your amovible device."
    else
   rmdir --ignore-fail-on-non-empty "$MOVINGDIR"/urls
# "$DISTDIR" already contains everything needed to proceed. Let's do it!
   /usr/bin/emerge $*
    fi
    rm "$tempfile2"   
fi

# "$MOVINGDIR"/remote-fetch
if [ -n "$SNAPSHOT" -o ! -x "$MOVINGDIR"/remote-fetch ]
    then
# Update or create (first run) "$MOVINGDIR"/remote-fetch
    echo '#!/bin/sh
# Distributed under the terms of the GNU General Public License v2
' > "$MOVINGDIR"/remote-fetch
    echo "GENTOO_MIRRORS=\"$GENTOO_MIRRORS\"" >> "$MOVINGDIR"/remote-fetch
    if [ -n "$SNAPSHOT" ]
   then
   SNAPSHOT_FILE=${SNAPSHOT##*/}
   echo "LAST_SNAPSHOT_INSTALLED=${SNAPSHOT_FILE:8:8}" >> "$MOVINGDIR"/remote-fetch
    else
   echo "LAST_SNAPSHOT_INSTALLED=0" >> "$MOVINGDIR"/remote-fetch
    fi
    echo '

# Priority for the distfiles on the Portage tree
rm -f portage-*.tar.bz2

# Fetch the distfiles
if [ -d urls ]
    then
    if [ ! -d distfiles ]
        then
        mkdir -m 755 distfiles
    fi
    lastfilefetched=""
    for URLlist in urls/*
      do
      while read url
   do
   file="${url##*/}"
   if [ "$file" != "$lastfilefetched" ]
       then
       echo "$file" >> partial_fetch
       if wget -c -nd -P distfiles "$url"
      then
      grep -v "$file" partial_fetch > .tempfile
      if [ -s .tempfile ]
          then
          mv .tempfile partial_fetch
      else
          rm partial_fetch .tempfile
      fi
      lastfilefetched="$file"      
       fi
   fi
      done < "$URLlist"
    done
    rmdir distfiles 2> /dev/null
fi

# Fetch the Portage tree
for mirror in "$GENTOO_MIRRORS"
  do
  for (( i=0, snapshotdate=`date -d "$i day ago" +%Y%m%d`; $snapshotdate != $LAST_SNAPSHOT_INSTALLED & i < 10; i++ ))
    do
    echo "portage" >> partial_fetch
    if wget -c -nd $mirror/snapshots/portage-${snapshotdate}.tar.bz2
   then
   grep -v "portage" partial_fetch > .tempfile
   if [ -s .tempfile ]
       then
       mv .tempfile partial_fetch
   else
       rm partial_fetch .tempfile
   fi
   exit
    fi
    if [ -f portage-${snapshotdate}-tar.bz2 ]
   then
# The Portage tree was only partially downloaded
   rm portage-${snapshotdate}-tar.bz2
   exit
    fi
  done
done
' >> "$MOVINGDIR"/remote-fetch
    chmod 755 "$MOVINGDIR"/remote-fetch
fi

# Cleaning
# There should not be any remaining snapshot of the Portage tree
rm -f "$MOVINGDIR"/portage-*.tar.bz2
# Update $MOVINGDIR/partial_fetch and $MOVINGDIR/distfiles/* according to $MOVINGDIR/distfiles/*
if [ -f "$MOVINGDIR"/partial_fetch -a -d "$MOVINGDIR"/urls ]
    then
# There may be some useful partial fetchs
    tempfile3=`tempfile`
    while read sourcefile
      do
      if grep -q "$sourcefile" "$MOVINGDIR"/urls/*
     then
# $sourcefile is marked to be partially fetched but is not required to fulfill any reqested action
     rm -f "$MOVINGDIR/distfiles/$sourcefile"
      else
     echo "$sourcefile" >> "$tempfile3"
      fi
    done < "$MOVINGDIR"/partial_fetch
    if [ -s "$tempfile3" ]
   then
   mv "$tempfile3" "$MOVINGDIR"/partial_fetch
    else
   rm -rf "$MOVINGDIR"/distfiles "$MOVINGDIR"/partial_fetch "$tempfile3"
    fi
else
    rm -rf "$MOVINGDIR"/distfiles "$MOVINGDIR"/partial_fetch
fi


Pour le tester :
1) Devenir root :
Code:
# su

2) Copier le script dans /usr/bin/remote-emerge et le rendre exécutable avec la commande suivante :
Code:
# chmod 755 /usr/bin/remote-emerge

NB : Le script s'appelant lui-même, il doit impérativement se trouver dans un répertoire de votre variable PATH
3) Définir la variable MOVINGDIR (répertoire sur le périphérique amovible) dans /etc/make.conf. Si ce n'est pas fait, le script vous le rappellera.

La commande remote-emerge a exactement la même syntaxe qu'emerge à cela près que l'option "--sync" n'est plus disponible (le script considère que la mise à jour de l'arbre Portage est une requête parmanente) et qu'une nouvelle option "--oldactions" est ajoutée pour permettre l'installation de tout ce qui a été demandé précédemment (et de l'arbre Portage). La limite de ce qui sera effectivement fait est bien entendu fixée à ce que vous aurez réussi à télécharger sur votre périphérique amovible en exécutant remote-fetch (il n'est donc pas problématique que le périphérique amovible soit un peu plein). Remote-fetch est un autre script qui se crée et se recrée sur votre périphérique amovible à chaque utilisation de remote-emerge (ne vous inquietter pas, le script s'occupe de tout, aucune action demandée ne sera oubliée). Bref, un cycle classique d'utilisation est :
1) Quelques remote-emerge "type emerge" sur la Gentoo (par exemple "remote-emerge -uDN world")
2) Exécution de remote-fetch sur une machine connectée à internet (tout *NIX fera l'affaire)
3) De retour sur la Gentoo, exécution de "remote-emerge --oldactions"

Notez qu'entre 1 et 3 vous pouvez facilement renoncer à une action en supprimant le fichier correspondant dans $MOVINGDIR/urls.
Notez également que vous pouvez sans problème d'intégrité faire de la place sur votre périphérique amovible en supprimant des sources dans $MOVINGDIR/distfiles ou en supprimant un snapshot de l'arbre Portage qui serait dans $MOVINGDIR.

J'attends vos retours. Signalez moi, tout problème ou cas d'utilisation que j'aurais oublié. Vous pouvez aussi m'écrire que tout va bien. :P

Pour ceux qui sont intéressés un peu par le bash, il reste deux petits inconvénients (et j'aimerais en particulier trouver une solution pour le deuxième vraiment tout bête) :
1) Contrairement au distfiles, je ne veux jamais me retrouver avec un snapshot de l'arbre Portage partiellement téléchargé (je peux vous expliquer pourquoi). Or le script ne vérifie pas si il y a suffisamment de place disponible sur le périphérique amovible pour l'acueillir. Du coup, il télécharge et si la place vient à manquer il supprime ce début de fichier. Ça ressemble à une perte de temps mais bon... ça ne me traumatise pas ! :P
2) En appelant remote-emerge avec world ou system alors que rien ne doit être mis à jour, le script prend inutilement un peu trop de temps. Si vous regardez un peu le script vous allez me dire : "Il suffit de tester si $tempfile2 est vide ou non". Seulement un [ -s "$tempfile2" ] ne donne pas le bon résultat et je ne comprends pas pourquoi (peut-être que la création de fichier avec tempfile est un peu particulière). Bien sûr je pourrais essayer des technique sales (genre un grep "." "$tempfile2") mais ça me chagrine de salir ce script... Si vous avez une idée je suis preneur !
Back to top
View user's profile Send private message
Magic Banana
Veteran
Veteran


Joined: 13 Dec 2005
Posts: 1912
Location: Belo Horizonte, Minas Gerais, Brasil

PostPosted: Mon Nov 13, 2006 10:27 am    Post subject: Reply with quote

Arf! On me demande de publier mon scrips et ensuite personne ne veut me donner un coup de main pour le tester... :cry:

Histoire de faire remonter le thread, voici une nouvelle version très peu différente de la précédente :

remote-emerge:
#!/bin/bash
# Distributed under the terms of the GNU General Public License v2
# AUTHOR: Magic Banana

# Variables definitions
source /etc/make.globals
source /etc/make.conf
if [ -z "$MOVINGDIR" ]
    then
    echo "
MOVINGDIR must be the name of a directory on an amovible device.
Please set this variable in /etc/make.conf.

You can, for instance, adapt the following command:
echo 'MOVINGDIR=\"/media/usbdisk/moving-portage\"' >> /etc/make.conf"
    exit
fi

# If there is a distfiles directory on the amovible device copy its content in "$DISTDIR"
if [ ! -d "$MOVINGDIR" ]
    then
    mkdir -p -m 755 "$MOVINGDIR"
elif [ -d "$MOVINGDIR"/distfiles ]
    then
    for sourcefile in "$MOVINGDIR"/distfiles/*
      do
      if ! grep "${sourcefile##*/}" "$MOVINGDIR"/.partial_fetch &> /dev/null
     then
     mv "$sourcefile" "$DISTDIR"
      fi
    done
# I love clean permissions :
    chmod 644 "$DISTDIR"/*
fi

# remote-emerge --oldactions
if [ "$*" = "--oldactions" ]
    then
    if [ -d "$MOVINGDIR"/urls ]
   then
   for URLlist in "$MOVINGDIR"/urls/*
     do
     remote-emerge "${URLlist##*/}"
   done
    fi
    SNAPSHOT=`ls "$MOVINGDIR"/portage-[2-9][0-9][0-9][0-9][0-1][0-9][0-3][0-9].tar.bz2 2> /dev/null`
    if [ -n "$SNAPSHOT" ]
   then
# There is a new Portage tree
   if ! grep ^portage$ "$MOVINGDIR"/.partial_fetch &> /dev/null
       then
# It was totally downloaded
# Remove the old one (but keep the precious disfiles, the packages and the rpms)
       for file in "$PORTDIR"/*
         do
         if [ "$file" != "$DISTDIR" -a "$file" != "$PKGDIR" -a "$file" != "$RPMDIR" -a "$file" != "$PORTDIR"/../local ]
        then
        rm -rf "$file"
         fi
       done
# Install the new Portage tree
       tar -xvjf "$SNAPSHOT" -C "$PORTDIR"/..
# Update Portage cache
       /usr/bin/emerge --metadata
       rm "$SNAPSHOT"
   fi
    fi
else

# For any operation which does not require any fetch, use directly emerge
    for arg in $*
      do
      case $arg in
     --help|-*h*       ) echo "
remote-emerge allows you to administrate offline your system in exactly the
same way and with the same syntax as emerge. However the option --sync is not
used since fetching the Portage tree is considered as a permanent request.
To perform every action previously requested and synchronize your Portage
tree (in the limit of what has been fetched), symply run
'remote-emerge --oldactions'." && /usr/bin/emerge $* && exit;;
     --oldactions      ) echo "
To perform every action previously requested and synchronize your Portage
tree (in the limit of what has been fetched), symply run
'remote-emerge --oldactions' without other option." && exit;;
     --sync            ) echo "
The option --sync is not used since fetching the Portage is considered
as a permanent request. To perform every action previously requested and
synchronize your Portage tree (in the limit of what has been fetched),
symply run 'remote-emerge --oldactions'." && exit;;
     --version|-*V*    ) echo "remote-emerge 0.1" && /usr/bin/emerge $* && exit;;
     --clean|--depclean|--info|--metadata|--pretend|--prune|--regen|--search|--searchdesc|-*c*|-*p*|-*P*|-*s*|-*S* ) /usr/bin/emerge $* && exit;;
      esac
    done

# Create "$MOVINGDIR"/urls if not already there
    if [ ! -d "$MOVINGDIR"/urls ]
   then
   mkdir -m 755 "$MOVINGDIR"/urls
    fi

# Create the list of urls to fetch in order to perform the requested action
    newline='
'
    tempfile1=`tempfile`
    /usr/bin/emerge -fp $* 1> /dev/null 2> "$tempfile1"
    tempfile2=`tempfile`
# Strip out fetch-restrict messages, turn spaces into newlines and remove blank lines
    cat "$tempfile1" | grep -v '^!!!' | cut -d " " -f 1- --output-delim="$newline" | grep -v '^$' > "$tempfile2"
    rm "$tempfile1"
    if [ -f "$MOVINGDIR/urls/$*" ]
   then
# This command has been invoked earlier without being satisfied, remove the old urls
   rm "$MOVINGDIR/urls/$*"
    fi
# Skip files already in "$DISTDIR" and write the URLs on the amovible device
    last=""
    while read url
      do
      if [ "${url##*/}" = "$last" ]
     then
     if [ -n "$isabsent" ]
         then
         echo "$url" >> "$MOVINGDIR/urls/$*"
     fi
      else
     if [ -f "$DISTDIR/${url##*/}" ]
         then
         isabsent=""
     else
         echo "$url" >> "$MOVINGDIR/urls/$*"
         isabsent="t"
     fi
     last="${url##*/}"
      fi
    done < "$tempfile2"
    if [ -f "$MOVINGDIR/urls/$*" ]
   then
   echo "
From a machine connected to Internet, please run the script remote-fetch
present on your amovible device."
    else
   rmdir --ignore-fail-on-non-empty "$MOVINGDIR"/urls
# "$DISTDIR" already contains everything needed to proceed. Let's do it!
   /usr/bin/emerge $*
    fi
    rm "$tempfile2"   
fi

# "$MOVINGDIR"/remote-fetch
if [ -n "$SNAPSHOT" -o ! -x "$MOVINGDIR"/remote-fetch ]
    then
# Update or create (first run) "$MOVINGDIR"/remote-fetch
    echo '#!/bin/sh
# Distributed under the terms of the GNU General Public License v2
' > "$MOVINGDIR"/remote-fetch
    echo "GENTOO_MIRRORS=\"$GENTOO_MIRRORS\"" >> "$MOVINGDIR"/remote-fetch
    if [ -n "$SNAPSHOT" ]
   then
   SNAPSHOT_FILE=${SNAPSHOT##*/}
   echo "LAST_SNAPSHOT_INSTALLED=${SNAPSHOT_FILE:8:8}" >> "$MOVINGDIR"/remote-fetch
    else
   echo "LAST_SNAPSHOT_INSTALLED=0" >> "$MOVINGDIR"/remote-fetch
    fi
    echo '

# Priority for the distfiles on the Portage tree
rm -f portage-*.tar.bz2

# Fetch the distfiles
if [ -d urls ]
    then
    if [ ! -d distfiles ]
        then
        mkdir -m 755 distfiles
    fi
    lastfilefetched=""
    for URLlist in urls/*
      do
      while read url
   do
   file="${url##*/}"
   if [ "$file" != "$lastfilefetched" ]
       then
       echo "$file" >> .partial_fetch
       if wget -T 180 -t 3 -c -nd -P distfiles "$url"
      then
      grep -v "$file" .partial_fetch > .tempfile
      if [ -s .tempfile ]
          then
          mv .tempfile .partial_fetch
      else
          rm .partial_fetch .tempfile
      fi
      lastfilefetched="$file"      
       fi
   fi
      done < "$URLlist"
    done
    rmdir distfiles 2> /dev/null
fi

# Fetch the Portage tree
for mirror in "$GENTOO_MIRRORS"
  do
  for (( i=0, snapshotdate=`date -d "$i day ago" +%Y%m%d`; $snapshotdate != $LAST_SNAPSHOT_INSTALLED & i < 10; i++ ))
    do
    echo "portage" >> .partial_fetch
    if wget -T 180 -t 3 -nd $mirror/snapshots/portage-${snapshotdate}.tar.bz2
   then
   grep -v "portage" .partial_fetch > .tempfile
   if [ -s .tempfile ]
       then
       mv .tempfile .partial_fetch
   else
       rm .partial_fetch .tempfile
   fi
   exit
    fi
    if [ -f portage-${snapshotdate}-tar.bz2 ]
   then
# The Portage tree was only partially downloaded
   rm portage-${snapshotdate}-tar.bz2
   exit
    fi
  done
done
' >> "$MOVINGDIR"/remote-fetch
    chmod 755 "$MOVINGDIR"/remote-fetch
fi

# Cleaning
# There should not be any remaining snapshot of the Portage tree
rm -f "$MOVINGDIR"/portage-*.tar.bz2
# Update $MOVINGDIR/.partial_fetch and $MOVINGDIR/distfiles/* according to $MOVINGDIR/distfiles/*
if [ -f "$MOVINGDIR"/.partial_fetch -a -d "$MOVINGDIR"/urls ]
    then
# There may be some useful partial fetchs
    tempfile3=`tempfile`
    while read sourcefile
      do
      if grep -q "$sourcefile" "$MOVINGDIR"/urls/*
     then
# $sourcefile is marked to be partially fetched but is not required to fulfill any reqested action
     rm -f "$MOVINGDIR/distfiles/$sourcefile"
      else
     echo "$sourcefile" >> "$tempfile3"
      fi
    done < "$MOVINGDIR"/.partial_fetch
    if [ -s "$tempfile3" ]
   then
   mv "$tempfile3" "$MOVINGDIR"/.partial_fetch
    else
   rm -rf "$MOVINGDIR"/distfiles "$MOVINGDIR"/.partial_fetch "$tempfile3"
    fi
else
    rm -rf "$MOVINGDIR"/distfiles "$MOVINGDIR"/.partial_fetch
fi


Les améliorations :
* partial_fetch est maintenant un fichier caché (l'utilisateur ne devant pas le toucher)
* Allègement des options par défaut de wget qui sont assez extrêmes
* Meilleur formatage des messages affichés dans le terminal

J'ai conscience que les lignes qui débordent (une ligne du script sur deux lignes lorsque vous copiez le script depuis votre navigateur Web) doivent poser problème. Je ne peux que vous demander de supprimer les sauts de lignes en trop... :oops: À moins que quelqu'un est la bonté de me prêter un peu d'espace sur son serveur... (que c'est dur de ne pas avoir Internet).

Pour tester le script, c'est très simple et c'est expliqué dans ma contribution précédente. Merci d'avance ! :wink:
Back to top
View user's profile Send private message
Temet
Advocate
Advocate


Joined: 14 Mar 2006
Posts: 2586
Location: 92

PostPosted: Mon Nov 13, 2006 10:49 am    Post subject: Reply with quote

Bah le problème c'est qu'ayant internet, et vu ce qu'il faut faire juste pour le tester ... tu comprendras que ceux qui ont internet manquent d'un certain courage pour tester ça.

Si tu veux, je te fais un répertoire sur mon ftp free, mais je ne peux pas te donner le pass pour des raisons évidentes (entre autre l'accès à mes mails).

Si ca t'intéresse, tu m'envoies un mp et tu m'envoies les scripts par mail, je les mets sur ftp.
Back to top
View user's profile Send private message
Magic Banana
Veteran
Veteran


Joined: 13 Dec 2005
Posts: 1912
Location: Belo Horizonte, Minas Gerais, Brasil

PostPosted: Mon Nov 13, 2006 11:00 am    Post subject: Reply with quote

Temet wrote:
Bah le problème c'est qu'ayant internet, et vu ce qu'il faut faire juste pour le tester ... tu comprendras que ceux qui ont internet manquent d'un certain courage pour tester ça.


Quoi ?!

Magic Banana wrote:
Pour le tester :
1) Devenir root :
Code:
# su


2) Copier le script dans /usr/bin/remote-emerge et le rendre exécutable avec la commande suivante :
Code:
# chmod 755 /usr/bin/remote-emerge


NB : Le script s'appelant lui-même, il doit impérativement se trouver dans un répertoire de votre variable PATH
3) Définir la variable MOVINGDIR (répertoire sur le périphérique amovible) dans /etc/make.conf. Si ce n'est pas fait, le script vous le rappellera.


Comment faire plus simple ?
Quant à l'utilisation, j'ai du mal à imaginer plus simple également !
Mais si tu as une idée pour rendre le processus encore plus simple, n'hésite pas à m'en faire part !

Merci beaucoup pour ta proposition d'hébergement ! En fait si tu pouvais copier le script par toi même et poster l'adresse dans ce thread ce serait parfait !
Back to top
View user's profile Send private message
Temet
Advocate
Advocate


Joined: 14 Mar 2006
Posts: 2586
Location: 92

PostPosted: Mon Nov 13, 2006 11:06 am    Post subject: Reply with quote

Bah c'était plutot la partie de sauvegarde de portage qui ne me plaisait pas.

Pour le copier/coller, je ne pourrai pas avait ce soir car là je suis sous Windows (boulot) et j'ai pas confiance pour l'encodage et les retour chariots.
Ce soir, promis .................. si j'oublie pas :x

EDIT : et si tu me l'envoies, ça m'évite de passer 10 minutes à refaire l'indentation qui est perdue par forumage ^^
Back to top
View user's profile Send private message
blasserre
Veteran
Veteran


Joined: 10 Feb 2004
Posts: 1362
Location: Lille, Vlaanderen

PostPosted: Mon Nov 13, 2006 11:54 am    Post subject: Reply with quote

Temet wrote:
Bah c'était plutot la partie de sauvegarde de portage qui ne me plaisait pas.

Pour le copier/coller, je ne pourrai pas avait ce soir car là je suis sous Windows (boulot) et j'ai pas confiance pour l'encodage et les retour chariots.
Ce soir, promis .................. si j'oublie pas :x

EDIT : et si tu me l'envoies, ça m'évite de passer 10 minutes à refaire l'indentation qui est perdue par forumage ^^


pareil, la sauvegarde de /usr/portage me coûte : 9Go de distfiles
/me est un peu maniaque
/me ne jette rien

par contre pour l'indentation, si tu utilisais un vrai éditeur de texte comme emacs par exemple, tu ne la perdrais pas, et même si tu la perdais un C-x h M-x indent-region RET te la remettrait
oui je sais gnagnagnagnagana... --> []
_________________
benj

technicien professionnel, ascendant winner
Back to top
View user's profile Send private message
Magic Banana
Veteran
Veteran


Joined: 13 Dec 2005
Posts: 1912
Location: Belo Horizonte, Minas Gerais, Brasil

PostPosted: Mon Nov 13, 2006 2:56 pm    Post subject: Reply with quote

Temet wrote:
Bah c'était plutot la partie de sauvegarde de portage qui ne me plaisait pas.

Pour le copier/coller, je ne pourrai pas avait ce soir car là je suis sous Windows (boulot) et j'ai pas confiance pour l'encodage et les retour chariots.
Ce soir, promis .................. si j'oublie pas :x

EDIT : et si tu me l'envoies, ça m'évite de passer 10 minutes à refaire l'indentation qui est perdue par forumage ^^


La sauvegarde de Portage c'est juste si vous ne faites pas confiance à mon script (pour les premières versions il y avait de quoi puisque vos répertoires packages, rpm et local aurait été perdus). Vous aurez remarqué que je ne parle plus de sauvegarde depuis quelques posts puisqu'il me semble qu'à présent il n'y a plus aucun risque de pertes.

Vous pouvez même avoir vos répertoires $PORTDIR et $DISTDIR où bon vous semble. C'est prévu. :wink:

Bref, j'attends vos retours d'expérience. :wink:

blasserre wrote:
pour l'indentation, si tu utilisais un vrai éditeur de texte comme emacs par exemple, tu ne la perdrais pas, et même si tu la perdais un C-x h M-x indent-region RET te la remettrait
oui je sais gnagnagnagnagana... --> []


Ce message est adressé à Temetn'est-ce pas ? Pour ma part, j'utilise LE vrai éditeur. :P Remarque toutefois que pour copier-coller sur Firefox, j'ouvre mon script avec gedit parce que, je sais pas chez toi, mais cette tâche ne fonctionne pas sur la Fedora du labo. Remarque, il suffirait que j'utilise LE vrai éditeur pour naviguer sur le Web. :twisted:

Sinon pour ce qui est du ménage dans $DISTDIR, la commande eclean (dans gentoolkit) sans l'option --destructive est très conservatrice et te permettra sans nul doute de libérer un peu de place. Je te laisse te référer à sa man page. :wink: Mais peut-être que tu comptes ouvrir un musée du code source ! :lol:
Back to top
View user's profile Send private message
Temet
Advocate
Advocate


Joined: 14 Mar 2006
Posts: 2586
Location: 92

PostPosted: Mon Nov 13, 2006 3:49 pm    Post subject: Reply with quote

Les intéressés peuvent désormais se fournir à l'adresse suivante : http://goondy.free.fr/magicbanana

C'est plus mieux que le copier/coller.

(un répertoire par version ... vu le poids d'un fichier texte, tu peux faire péter les versions ;))
Back to top
View user's profile Send private message
Magic Banana
Veteran
Veteran


Joined: 13 Dec 2005
Posts: 1912
Location: Belo Horizonte, Minas Gerais, Brasil

PostPosted: Mon Nov 13, 2006 5:34 pm    Post subject: Reply with quote

Bon. Et bien puisque je peux faire péter les versions, je me le permets déjà ! :P

En fait remote-fetch ne fonctionnait pas comme souhaité pour le téléchargement de l'arbre Portage. Je vous passe les détails (rien de bien grâve). Du coup, j'ai modifié tout ça et voilà la version 0.1.1 ! En attendant que Temet, dans son immense bonté, upload le script sur son serveur FTP, je vous le copie ici :

remote-emerge:
#!/bin/bash
# Distributed under the terms of the GNU General Public License v2
# AUTHOR: Magic Banana

# Variables definitions
source /etc/make.globals
source /etc/make.conf
if [ -z "$MOVINGDIR" ]
    then
    echo "
MOVINGDIR must be the name of a directory on an amovible device.
Please set this variable in /etc/make.conf.

You can, for instance, adapt the following command:
echo 'MOVINGDIR=\"/media/usbdisk/moving-portage\"' >> /etc/make.conf"
    exit
fi

# If there is a distfiles directory on the amovible device copy its content in "$DISTDIR"
if [ ! -d "$MOVINGDIR" ]
    then
    mkdir -p -m 755 "$MOVINGDIR"
elif [ -d "$MOVINGDIR"/distfiles ]
    then
    for sourcefile in "$MOVINGDIR"/distfiles/*
      do
      if ! grep "${sourcefile##*/}" "$MOVINGDIR"/.partial_fetch &> /dev/null
     then
     mv "$sourcefile" "$DISTDIR"
      fi
    done
# I love clean permissions :
    chmod 644 "$DISTDIR"/*
fi

# remote-emerge --oldactions
if [ "$*" = "--oldactions" ]
    then
    if [ -d "$MOVINGDIR"/urls ]
   then
   for URLlist in "$MOVINGDIR"/urls/*
     do
     remote-emerge "${URLlist##*/}"
   done
    fi
    SNAPSHOT=`ls "$MOVINGDIR"/portage-[2-9][0-9][0-9][0-9][0-1][0-9][0-3][0-9].tar.bz2 2> /dev/null`
    if [ -n "$SNAPSHOT" ]
   then
# There is a new Portage tree
   if ! grep ^portage$ "$MOVINGDIR"/.partial_fetch &> /dev/null
       then
# It was totally downloaded
# Remove the old one (but keep the precious disfiles, the packages and the rpms)
       for file in "$PORTDIR"/*
         do
         if [ "$file" != "$DISTDIR" -a "$file" != "$PKGDIR" -a "$file" != "$RPMDIR" -a "$file" != "$PORTDIR"/../local ]
        then
        rm -rf "$file"
         fi
       done
# Install the new Portage tree
       tar -xvjf "$SNAPSHOT" -C "$PORTDIR"/..
# Update Portage cache
       /usr/bin/emerge --metadata
       rm "$SNAPSHOT"
   fi
    fi
else

# For any operation which does not require any fetch, use directly emerge
    for arg in $*
      do
      case $arg in
     --help|-*h*       ) echo "
remote-emerge allows you to administrate offline your system in exactly the
same way and with the same syntax as emerge. However the option --sync is not
used since fetching the Portage tree is considered as a permanent request.
To perform every action previously requested and synchronize your Portage
tree (in the limit of what has been fetched), symply run
'remote-emerge --oldactions'." && /usr/bin/emerge $* && exit;;
     --oldactions      ) echo "
To perform every action previously requested and synchronize your Portage
tree (in the limit of what has been fetched), symply run
'remote-emerge --oldactions' without other option." && exit;;
     --sync            ) echo "
The option --sync is not used since fetching the Portage is considered
as a permanent request. To perform every action previously requested and
synchronize your Portage tree (in the limit of what has been fetched),
symply run 'remote-emerge --oldactions'." && exit;;
     --version|-*V*    ) echo "
remote-emerge 0.1.1" && /usr/bin/emerge $* && exit;;
     --clean|--depclean|--info|--metadata|--pretend|--prune|--regen|--search|--searchdesc|-*c*|-*p*|-*P*|-*s*|-*S* ) /usr/bin/emerge $* && exit;;
      esac
    done

# Create "$MOVINGDIR"/urls if not already there
    if [ ! -d "$MOVINGDIR"/urls ]
   then
   mkdir -m 755 "$MOVINGDIR"/urls
    fi

# Create the list of urls to fetch in order to perform the requested action
    newline='
'
    tempfile1=`tempfile`
    /usr/bin/emerge -fp $* 1> /dev/null 2> "$tempfile1"
    tempfile2=`tempfile`
# Strip out fetch-restrict messages, turn spaces into newlines and remove blank lines
    cat "$tempfile1" | grep -v '^!!!' | cut -d " " -f 1- --output-delim="$newline" | grep -v '^$' > "$tempfile2"
    rm "$tempfile1"
    if [ -f "$MOVINGDIR/urls/$*" ]
   then
# This command has been invoked earlier without being satisfied, remove the old urls
   rm "$MOVINGDIR/urls/$*"
    fi
# Skip files already in "$DISTDIR" and write the URLs on the amovible device
    last=""
    while read url
      do
      if [ "${url##*/}" = "$last" ]
     then
     if [ -n "$isabsent" ]
         then
         echo "$url" >> "$MOVINGDIR/urls/$*"
     fi
      else
     if [ -f "$DISTDIR/${url##*/}" ]
         then
         isabsent=""
     else
         echo "$url" >> "$MOVINGDIR/urls/$*"
         isabsent="t"
     fi
     last="${url##*/}"
      fi
    done < "$tempfile2"
    if [ -f "$MOVINGDIR/urls/$*" ]
   then
   echo "
From a machine connected to Internet, please run the script remote-fetch
present on your amovible device."
    else
   rmdir --ignore-fail-on-non-empty "$MOVINGDIR"/urls
# "$DISTDIR" already contains everything needed to proceed. Let's do it!
   /usr/bin/emerge $*
    fi
    rm "$tempfile2"   
fi

# "$MOVINGDIR"/remote-fetch
if [ -n "$SNAPSHOT" -o ! -x "$MOVINGDIR"/remote-fetch ]
    then
# Update or create (first run) "$MOVINGDIR"/remote-fetch
    echo '#!/bin/sh
# Distributed under the terms of the GNU General Public License v2
' > "$MOVINGDIR"/remote-fetch
    echo "GENTOO_MIRRORS=\"$GENTOO_MIRRORS\"" >> "$MOVINGDIR"/remote-fetch
    if [ -n "$SNAPSHOT" ]
   then
   SNAPSHOT_FILE=${SNAPSHOT##*/}
   echo "LAST_SNAPSHOT_INSTALLED=${SNAPSHOT_FILE:8:8}" >> "$MOVINGDIR"/remote-fetch
    else
   echo "LAST_SNAPSHOT_INSTALLED=0" >> "$MOVINGDIR"/remote-fetch
    fi
    echo '
# Priority for the distfiles on the Portage tree
rm -f portage-*.tar.bz2

# Fetch the distfiles
if [ -d urls ]
    then
    if [ ! -d distfiles ]
        then
        mkdir -m 755 distfiles
    fi
    lastfilefetched=""
    for URLlist in urls/*
      do
      while read url
   do
   file="${url##*/}"
   if [ "$file" != "$lastfilefetched" ]
       then
       echo "$file" >> .partial_fetch
       if wget -T 180 -t 3 -c -nd -P distfiles "$url"
      then
      grep -v "$file" .partial_fetch > .tempfile
      if [ -s .tempfile ]
          then
          mv .tempfile .partial_fetch
      else
          rm .partial_fetch .tempfile
      fi
      lastfilefetched="$file"      
       fi
   fi
      done < "$URLlist"
    done
    rmdir distfiles 2> /dev/null
fi

# Fetch the Portage tree
echo "portage" >> .partial_fetch
for i in 0 1 2 3 4 5 6 7 8 9
  do
  for mirror in "$GENTOO_MIRRORS"
    do
    snapshotdate=`date -d "$i day ago" +%Y%m%d`
    if [ $snapshotdate -eq $LAST_SNAPSHOT_INSTALLED ]
   then
   grep -v "portage" .partial_fetch > .tempfile
   if [ -s .tempfile ]
       then
       mv .tempfile .partial_fetch
   else
       rm .partial_fetch .tempfile
   fi
   exit
    fi
    rm -f wget-log
    if wget -T 180 -t 3 -nd $mirror/snapshots/portage-${snapshotdate}.tar.bz2
   then
   grep -v "portage" .partial_fetch > .tempfile
   if [ -s .tempfile ]
       then
       mv .tempfile .partial_fetch
   else
       rm .partial_fetch .tempfile
   fi
   exit
    fi
    if [ -f portage-${snapshotdate}-tar.bz2 ]
   then
# The Portage tree was only partially downloaded (I assume that the amovible device is full)
   rm portage-${snapshotdate}-tar.bz2
   grep -v "portage" .partial_fetch > .tempfile
   if [ -s .tempfile ]
       then
       mv .tempfile .partial_fetch
   else
       rm .partial_fetch .tempfile
   fi
   exit
    fi
  done
done
' >> "$MOVINGDIR"/remote-fetch
    chmod 755 "$MOVINGDIR"/remote-fetch
fi

# Cleaning
# There should not be any remaining snapshot of the Portage tree
rm -f "$MOVINGDIR"/portage-*.tar.bz2
# Update $MOVINGDIR/.partial_fetch and $MOVINGDIR/distfiles/* according to $MOVINGDIR/distfiles/*
if [ -f "$MOVINGDIR"/.partial_fetch -a -d "$MOVINGDIR"/urls ]
    then
# There may be some useful partial fetchs
    tempfile3=`tempfile`
    while read sourcefile
      do
      if [ "$sourcefile" != "portage" ]
     then
     if grep -q "$sourcefile" "$MOVINGDIR"/urls/*
         then
# $sourcefile is marked to be partially fetched but is not required to fulfill any reqested action
         rm -f "$MOVINGDIR/distfiles/$sourcefile"
     else
         echo "$sourcefile" >> "$tempfile3"
     fi
      fi
    done < "$MOVINGDIR"/.partial_fetch
    if [ -s "$tempfile3" ]
   then
   mv "$tempfile3" "$MOVINGDIR"/.partial_fetch
    else
   rm -rf "$MOVINGDIR"/distfiles "$MOVINGDIR"/.partial_fetch "$tempfile3"
    fi
else
    rm -rf "$MOVINGDIR"/distfiles "$MOVINGDIR"/.partial_fetch
fi
Back to top
View user's profile Send private message
Temet
Advocate
Advocate


Joined: 14 Mar 2006
Posts: 2586
Location: 92

PostPosted: Mon Nov 13, 2006 6:04 pm    Post subject: Reply with quote

Fait ;)
Back to top
View user's profile Send private message
Magic Banana
Veteran
Veteran


Joined: 13 Dec 2005
Posts: 1912
Location: Belo Horizonte, Minas Gerais, Brasil

PostPosted: Fri Nov 17, 2006 10:57 am    Post subject: Reply with quote

Voilà la version 0.2 de remote-emerge !

Les deux problèmes évoqués précédemment ont été résolus. En fait le problème des téléchargements intérompus par manque de place sur le périphérique amovible ont été repensés en profondeur (remote-fetch a été totalement refondé) et l'approche suivie est, je pense, optimale. Un début de téléchargement pouvant être utile dans le futur n'est supprimé que si la place vient à manquer et suivant la précédence : vieux snapshot incomplet < moins vieux snapshot incomplet < distfile (jamais supprimé).

De plus "remote-emerge --oldactions" maintenant indique les actions en attente d'un téléchargement et quelques bugs ont été corrigés (notamment concernant le téléchargement de l'arbre Portage).

Les sources sont gentiment mises à disposition par Temet sur son serveur FTP. Si jamais ce serveur était down, les voici :

/usr/bin/remote-emerge:
#!/bin/bash
# Distributed under the terms of the GNU General Public License v2
# AUTHOR: Magic Banana

# Exit status codes
EX_OK=0
EX_USAGE=64

# Variables definitions
source /etc/make.globals
source /etc/make.conf
if [ -z "$MOVINGDIR" ]
    then
    echo "
MOVINGDIR must be the name of a directory on an amovible device.
Please set this variable in /etc/make.conf.

You can, for instance, adapt the following command:
echo 'MOVINGDIR=\"/media/usbdisk/moving-portage\"' >> /etc/make.conf"
    exit $EX_USAGE
fi

# If there is a distfiles directory on the amovible device copy its content in "$DISTDIR"
if [ ! -d "$MOVINGDIR"/distfiles ]
    then
    mkdir -p -m 755 "$MOVINGDIR"/distfiles
else
    for sourcefile in "$MOVINGDIR"/distfiles/*
      do
      if ! grep "${sourcefile##*/}" "$MOVINGDIR"/.partial_fetch &> /dev/null
     then
     mv "$sourcefile" "$DISTDIR" 2> /dev/null
      fi
    done
# I love clean permissions :
    chmod 644 "$DISTDIR"/*
fi

# remote-emerge --oldactions
if [ "$*" = "--oldactions" ]
    then
    if [ -d "$MOVINGDIR"/urls ]
   then
   for URLlist in "$MOVINGDIR"/urls/*
     do
     remote-emerge "${URLlist##*/}"
   done
    fi
    snapshot=`ls "$MOVINGDIR"/portage-[2-9][0-9][0-9][0-9][0-1][0-9][0-3][0-9].tar.bz2 2> /dev/null | awk 'NR==1 {print}'`
    if test -n "$snapshot" && ! grep ^${snapshot}$ "$MOVINGDIR"/.partial_fetch &> /dev/null
   then
# A new snapshot was totally downloaded
# Remove the one currently installed (but keep the precious disfiles, the packages, the rpms and the local directory)
       for file in "$PORTDIR"/*
         do
         if [ "$file" != "$DISTDIR" -a "$file" != "$PKGDIR" -a "$file" != "$RPMDIR" -a "$file" != "$PORTDIR"/../local ]
        then
        rm -rf "$file"
         fi
       done
# Install the new Portage tree
       tar -xvjf "$snapshot" -C "$PORTDIR"/..
# Update Portage cache
       /usr/bin/emerge --metadata
       rm "$snapshot"
    fi
else

# For any operation which does not require any fetch, use directly emerge
    for arg in $*
      do
      case $arg in
     --help|-*h*       ) echo "
remote-emerge allows you to administrate offline your system in exactly the
same way and with the same syntax as emerge. However the option --sync is not
used since fetching the Portage tree is considered as a permanent request.
To perform every action previously requested and synchronize your Portage
tree (in the limit of what has been fetched), symply run
'remote-emerge --oldactions'." && /usr/bin/emerge $* && exit $EX_OK;;
     --oldactions      ) echo "
To perform every action previously requested and synchronize your Portage
tree (in the limit of what has been fetched), symply run
'remote-emerge --oldactions' without other option." && exit $EX_USAGE;;
     --sync            ) echo "
The option --sync is not used since fetching the Portage is considered
as a permanent request. To perform every action previously requested and
synchronize your Portage tree (in the limit of what has been fetched),
symply run 'remote-emerge --oldactions'." && exit $EX_USAGE;;
     --version|-*V*    ) echo "remote-emerge 0.2" && /usr/bin/emerge $* && exit $EX_OK;;
     --clean|--depclean|--info|--metadata|--pretend|--prune|--regen|--search|--searchdesc|-*c*|-*p*|-*P*|-*s*|-*S* ) /usr/bin/emerge $* && exit $EX_OK;;
      esac
    done

# Create "$MOVINGDIR"/urls if not already there
    if [ ! -d "$MOVINGDIR"/urls ]
   then
   mkdir -m 755 "$MOVINGDIR"/urls
    fi

# Create the list of urls to fetch in order to perform the requested action
    newline='
'
    tempfile1=`tempfile`
    /usr/bin/emerge -fp $* 1> /dev/null 2> "$tempfile1"
    tempfile2=`tempfile`
# Strip out fetch-restrict messages, turn spaces into newlines and remove blank lines
    if cat "$tempfile1" | grep -v "^!!!" | cut -d " " -f 1- --output-delim="$newline" | grep -v "^$" > "$tempfile2"
   then
   if [ -f "$MOVINGDIR/urls/$*" ]
       then
# This command has been invoked earlier without being satisfied, remove the old urls
       rm "$MOVINGDIR/urls/$*"
   fi
# Skip files already in "$DISTDIR" and write the URLs on the amovible device
   last=""
   while read url
     do
     if [ "${url##*/}" = "$last" ]
         then
         if [ -n "$isabsent" ]
        then
        echo "$url" >> "$MOVINGDIR/urls/$*"
         fi
     else
         if [ -f "$DISTDIR/${url##*/}" ]
        then
        isabsent=""
         else
        echo "$url" >> "$MOVINGDIR/urls/$*"
        isabsent="t"
         fi
         last="${url##*/}"
     fi
   done < "$tempfile2"
   if [ -f "$MOVINGDIR/urls/$*" ]
       then
       echo "
'remote-emerge $*' requires the execution of the file
remote-fetch (on your amovible device) from a machine connected to Internet."
   else
       rmdir --ignore-fail-on-non-empty "$MOVINGDIR"/urls
# "$DISTDIR" already contains everything needed to proceed. Let's do it!
       /usr/bin/emerge $*
   fi
    fi
    rm "$tempfile1" "$tempfile2"
fi

# "$MOVINGDIR"/remote-fetch
if [ -n "$snapshot" -o ! -x "$MOVINGDIR"/remote-fetch ]
    then
# Update or create (first run) "$MOVINGDIR"/remote-fetch
    tempfile3=`tempfile`
    echo '#!/bin/sh
# Distributed under the terms of the GNU General Public License v2
' > "$tempfile3"
    echo "GENTOO_MIRRORS=\"$GENTOO_MIRRORS\"" >> "$tempfile3"
    if [ -n "$snapshot" ]
   then
   snapshotfile=${snapshot##*/}
   echo "LAST_SNAPSHOT_INSTALLED=${snapshotfile:8:8}" >> "$tempfile3"
    else
   echo "LAST_SNAPSHOT_INSTALLED=0" >> "$tempfile3"
    fi
    cat "$tempfile3" /usr/share/remote-emerge/remote-fetch > "$MOVINGDIR"/remote-fetch
    chmod 755 "$MOVINGDIR"/remote-fetch
    rm "$tempfile3"
fi

# Cleaning (in case of a deleted action)
# Update $MOVINGDIR/.partial_fetch and $MOVINGDIR/distfiles/* according to $MOVINGDIR/urls/*
if [ -f "$MOVINGDIR"/.partial_fetch -a -d "$MOVINGDIR"/urls ]
    then
# There may be some useful partial fetchs
    tempfile4=`tempfile`
    while read sourcefile
      do
      if [ "$sourcefile" != "portage-" ]
     then
     if grep -q "$sourcefile" "$MOVINGDIR"/urls/*
         then
         echo "$sourcefile" >> "$tempfile4"
     else
# $sourcefile is marked to be partially fetched but is not required to fulfill any reqested action
         rm -f "$MOVINGDIR/distfiles/$sourcefile"
     fi
      fi
    done < "$MOVINGDIR"/.partial_fetch
    if [ -s "$tempfile4" ]
   then
   mv "$tempfile4" "$MOVINGDIR"/.partial_fetch
    else
   rm -f "$MOVINGDIR"/distfiles/* "$MOVINGDIR"/.partial_fetch "$tempfile4"
    fi
else
    rm -f "$MOVINGDIR"/distfiles/* "$MOVINGDIR"/.partial_fetch
fi


/usr/share/remote-emerge/remote-fetch:
rm_oldest_snapshot_exclude ()
{
    for snapshot in portage-[2-9][0-9][0-9][0-9][0-1][0-9][0-3][0-9].tar.bz2
      do
      if [ "$snapshot" != "$1" ]
     then
     rm snapshot
     return 0
      fi
    done
# No snapshot to remove
    return 1
}

delete_line_from_partial_fetch ()
{
    tempfile=`mktemp`
    grep -v ^"$1"$ .partial_fetch > $tempfile
    if [ -s $tempfile ]
   then
   mv $tempfile .partial_fetch
    else
   rm .partial_fetch $tempfile
    fi
}

fetch ()
{
    file="${1##*/}"
    if grep ^"$file"$ .partial_fetch &> /dev/null
   then
   PRESENT_PARTIALLY_FETCHED_SOURCE="t"
    fi
    if [ ! -f "$2/$file" -o -n "$PRESENT_PARTIALLY_FETCHED_SOURCE" ]
   then
# Try to fetch the source (new download or continuition of a previous one)
   if [ -z "$PRESENT_PARTIALLY_FETCHED_SOURCE" ]
       then
       echo "$file" >> .partial_fetch
   fi
   if wget -T 180 -t 3 -nd -c -P "$2" "$1"
       then
# The source was totally fetched
       delete_line_from_partial_fetch "$file"
       return 0
   else
       if [ ! -f "$2/$file" ]
      then
      delete_line_from_partial_fetch "$file"
       fi
# The source was only partially fetched
       return 1
   fi
    fi
# The source is already totally downloaded
    return 0
}


# Fetch the distfiles
if [ -d urls ]
    then
    if [ ! -d distfiles ]
        then
        mkdir -m 755 distfiles
    fi
    for URLlist in urls/*
      do
      while read url
   do
   ROOM="0"
   while [ "$ROOM" = "0" ]
     do
     ROOM="1"
     if ! fetch "$url" distfiles
         then
         ROOM=`df -P . | awk 'NR==2 {print $4}'`
         if [ "$ROOM" = "0" -a -f distfiles/"${url##*/}" ]
        then
        if ! rm_oldest_snapshot_exclude
            then
# There is no space left on the amovible device and no other portage snapshot to remove and make room
            exit $EX_IOERR
        fi
         fi
     fi
   done
      done < "$URLlist"
    done
    rmdir distfiles 2> /dev/null
fi

for i in 0 1 2 3 4 5 6 7 8 9
  do
  snapshotdate=`date -d "$i day ago" +%Y%m%d`
  if [ $snapshotdate -eq $LAST_SNAPSHOT_INSTALLED ]
      then
# No newer portage tree on Internet can be (totally) fetched
      exit $EX_OK
  fi
  for mirror in "$GENTOO_MIRRORS"
    do
    ROOM="0"
    while [ "$ROOM" = "0" ]
      do
      if fetch "$mirror"/snapshots/portage-${snapshotdate}.tar.bz2 .
     then
# Remove any older partially fetched snapshot
     for present_snapshot in `ls portage-*.tar.bz2 2> /dev/null`
       do
       if [ "$present_snapshot" \< portage-${snapshotdate}.tar.bz2 ]
      then
      rm "$present_snapshot"
       fi
     done
     exit $EX_OK
      else
     ROOM=`df -P . | awk 'NR==2 {print $4}'`
     if [ "$ROOM" = "0" -a -f portage-${snapshotdate}-tar.bz2 ]
         then
         if ! rm_oldest_snapshot_exclude portage-${snapshotdate}-tar.bz2
        then
# There is no space left on the amovible device and no other portage snapshot to remove and make room
        exit $EX_IOERR
         fi
     fi
      fi
    done
  done
done


Comme vous pouvez le voir, j'ai de nouveau divisé en deux fichiers mon script. Voilà la procédure d'installation (quelqu'un veut me faire un ebuild ?) :
1) Devenir root :
Code:
# su

2) Copier remote-emerge dans /usr/bin/remote-emerge et le rendre exécutable avec la commande suivante :
Code:
# chmod 755 /usr/bin/remote-emerge

NB : Le script s'appelant lui-même, il doit impérativement se trouver dans un répertoire de votre variable PATH
3) Créer le répertoire /usr/share/remote-emerge :
Code:
# mkdir /usr/share/remote-emerge

NB : Ce répertoire ne peut être changé (à moins de modifier à la main /usr/bin/remote-emerge)
4) Copier remote-fetch dans /usr/share/remote-emerge/remote-fetch
5) Définir la variable MOVINGDIR (répertoire sur le périphérique amovible) dans /etc/make.conf. Si ce n'est pas fait, le script vous le rappellera.

La commande remote-emerge a exactement la même syntaxe qu'emerge à cela près que l'option "--sync" n'est plus disponible (le script considère que la mise à jour de l'arbre Portage est une requête parmanente) et qu'une nouvelle option "--oldactions" est ajoutée pour permettre l'installation de tout ce qui a été demandé précédemment (et de l'arbre Portage). La limite de ce qui sera effectivement fait est bien entendu fixée à ce que vous aurez réussi à télécharger sur votre périphérique amovible en exécutant remote-fetch (il n'est donc pas problématique que le périphérique amovible soit un peu plein). Remote-fetch est un autre script qui se crée et se recrée sur votre périphérique amovible à chaque utilisation de remote-emerge (ne vous inquiettez pas, le script s'occupe de tout, aucune action demandée ne sera oubliée). Bref, un cycle classique d'utilisation est :
1) Quelques remote-emerge "type emerge" sur la Gentoo (par exemple "remote-emerge -uDN world")
2) Exécution de remote-fetch sur une machine connectée à internet (tout *NIX fera l'affaire)
3) De retour sur la Gentoo, exécution de "remote-emerge --oldactions"

Notez qu'entre 1 et 3 vous pouvez facilement renoncer à une action en supprimant le fichier correspondant dans le répertoire urls.
Notez également que vous pouvez sans problème d'intégrité faire de la place sur votre périphérique amovible en supprimant des sources dans le répertoire distfiles ou en supprimant un éventuel snapshot de l'arbre Portage.
Vous pouvez aussi rajouter à la main des sources dans le répertoire distfiles.

Cette version pourrait être qualifiée de release-candidate. En effet, je ne pense pas ajouter de nouvelle fonctionnalités. Une amélioration évidente (mais demandant beaucoup de travail) serait de vérifier l'intégrité des téléchargements avec les digests présents dans les snapshots de l'arbre Portage. Si quelqu'un veut s'y atteler, il est le bienvenue : remote-emerge est sous license GPL2 et est codé proprement (pour du bash).

J'espère que certains d'entre vous me donneront un coup de main en testant ce script durant le week-end. Toute remarque est la bienvenue ! Si tout semble fonctionner correctement, je posterai ce script dans le sous-forum (et probablement aussi dans la section anglophone analogue) avec une FAQ pour expliquer son utilisation/fonctionnement.

EDIT : Ajout du lien vers le serveur hébergeant remote-emerge


Last edited by Magic Banana on Fri Nov 17, 2006 1:46 pm; edited 1 time in total
Back to top
View user's profile Send private message
Temet
Advocate
Advocate


Joined: 14 Mar 2006
Posts: 2586
Location: 92

PostPosted: Fri Nov 17, 2006 1:00 pm    Post subject: Reply with quote

http://goondy.free.fr/magicbanana/remote-emerge-0.2
Back to top
View user's profile Send private message
Magic Banana
Veteran
Veteran


Joined: 13 Dec 2005
Posts: 1912
Location: Belo Horizonte, Minas Gerais, Brasil

PostPosted: Fri Nov 17, 2006 2:41 pm    Post subject: Reply with quote

Comme la dernière fois, je me permets une mise à jour imédiatement après la précédente (et m'excuse auprès de Temet).

Le problème ?
Avec la version précédente si il est impossible de télécharger des fichiers nécessaires à l'exécution d'une installation pour une raison autre que le périphérique amovible plein (par exemple si les serveurs sont down) et qu'en revanche vous téléchargez sans problème un nouveau snapshot Portage alors, de retour sur votre Gentoo, l'action impossible à réaliser ne sera pas réalisée (naturellement) et le nouveau snapshot sera installé. Jusque là tout va bien. Le problème est qu'il manquait l'étape de mettre à jour les urls nécessaires à l'action incomplète puisque cette liste peut avoir changée (comme l'arbre Portage évolue).

Cette nouvelle version corrige ce problème en ajoutant cette étape. En bonus les performances de remote-fetch ont été améliorées (imperceptibles ! :lol: ).

En attendant que Temet mette les nouvelles sources sur son serveur, les voici :

/usr/bin/remote-emerge:
#!/bin/bash
# Distributed under the terms of the GNU General Public License v2
# AUTHOR: Magic Banana

# Exit status codes
EX_OK=0
EX_USAGE=64

proceed_url_lists ()
{
    if [ -d "$MOVINGDIR"/urls ]
   then
   for URLlist in "$MOVINGDIR"/urls/*
     do
     remote-emerge "${URLlist##*/}"
   done
    fi
}

# Variables definitions
source /etc/make.globals
source /etc/make.conf
if [ -z "$MOVINGDIR" ]
    then
    echo "
MOVINGDIR must be the name of a directory on an amovible device.
Please set this variable in /etc/make.conf.

You can, for instance, adapt the following command:
echo 'MOVINGDIR=\"/media/usbdisk/moving-portage\"' >> /etc/make.conf"
    exit $EX_USAGE
fi

# If there is a distfiles directory on the amovible device copy its content in "$DISTDIR"
if [ ! -d "$MOVINGDIR"/distfiles ]
    then
    mkdir -p -m 755 "$MOVINGDIR"/distfiles
else
    for sourcefile in "$MOVINGDIR"/distfiles/*
      do
      if ! grep "${sourcefile##*/}" "$MOVINGDIR"/.partial_fetch &> /dev/null
     then
     mv "$sourcefile" "$DISTDIR" 2> /dev/null
      fi
    done
# I love clean permissions :
    chmod 644 "$DISTDIR"/*
fi

# remote-emerge --oldactions
if [ "$*" = "--oldactions" ]
    then
    proceed_url_lists
    snapshot=`ls "$MOVINGDIR"/portage-[2-9][0-9][0-9][0-9][0-1][0-9][0-3][0-9].tar.bz2 2> /dev/null | awk 'NR==1 {print}'`
    if test -n "$snapshot" && ! grep ^${snapshot}$ "$MOVINGDIR"/.partial_fetch &> /dev/null
   then
# A new snapshot was totally downloaded
# Remove the one currently installed (but keep the precious disfiles, the packages, the rpms and the local directory)
   for file in "$PORTDIR"/*
     do
     if [ "$file" != "$DISTDIR" -a "$file" != "$PKGDIR" -a "$file" != "$RPMDIR" -a "$file" != "$PORTDIR"/../local ]
         then
         rm -rf "$file"
     fi
   done
# Install the new Portage tree
   tar -xvjf "$snapshot" -C "$PORTDIR"/..
# Update Portage cache
   /usr/bin/emerge --metadata
   rm "$snapshot"
   proceed_url_lists
    fi
else

# For any operation which does not require any fetch, use directly emerge
    for arg in $*
      do
      case $arg in
     --help|-*h*       ) echo "
remote-emerge allows you to administrate offline your system in exactly the
same way and with the same syntax as emerge. However the option --sync is not
used since fetching the Portage tree is considered as a permanent request.
To perform every action previously requested and synchronize your Portage
tree (in the limit of what has been fetched), symply run
'remote-emerge --oldactions'." && /usr/bin/emerge $* && exit $EX_OK;;
     --oldactions      ) echo "
To perform every action previously requested and synchronize your Portage
tree (in the limit of what has been fetched), symply run
'remote-emerge --oldactions' without other option." && exit $EX_USAGE;;
     --sync            ) echo "
The option --sync is not used since fetching the Portage is considered
as a permanent request. To perform every action previously requested and
synchronize your Portage tree (in the limit of what has been fetched),
symply run 'remote-emerge --oldactions'." && exit $EX_USAGE;;
     --version|-*V*    ) echo "remote-emerge 0.2.1" && /usr/bin/emerge $* && exit $EX_OK;;
     --clean|--depclean|--info|--metadata|--pretend|--prune|--regen|--search|--searchdesc|-*c*|-*p*|-*P*|-*s*|-*S* ) /usr/bin/emerge $* && exit $EX_OK;;
      esac
    done

# Create "$MOVINGDIR"/urls if not already there
    if [ ! -d "$MOVINGDIR"/urls ]
   then
   mkdir -m 755 "$MOVINGDIR"/urls
    fi

# Create the list of urls to fetch in order to perform the requested action
    newline='
'
    tempfile1=`tempfile`
    /usr/bin/emerge -fp $* 1> /dev/null 2> "$tempfile1"
    tempfile2=`tempfile`
# Strip out fetch-restrict messages, turn spaces into newlines and remove blank lines
    if grep -v "^!!!" "$tempfile1" | cut -d " " -f 1- --output-delim="$newline" | grep -v "^$" > "$tempfile2"
   then
   if [ -f "$MOVINGDIR/urls/$*" ]
       then
# This command has been invoked earlier without being satisfied, remove the old urls
       rm "$MOVINGDIR/urls/$*"
   fi
# Skip files already in "$DISTDIR" and write the URLs on the amovible device
   last=""
   while read url
     do
     if [ "${url##*/}" = "$last" ]
         then
         if [ -n "$isabsent" ]
        then
        echo "$url" >> "$MOVINGDIR/urls/$*"
         fi
     else
         if [ -f "$DISTDIR/${url##*/}" ]
        then
        isabsent=""
         else
        echo "$url" >> "$MOVINGDIR/urls/$*"
        isabsent="t"
         fi
         last="${url##*/}"
     fi
   done < "$tempfile2"
   if [ -f "$MOVINGDIR/urls/$*" ]
       then
       echo "
'remote-emerge $*' requires the execution of the file
remote-fetch (on your amovible device) from a machine connected to Internet."
   else
       rmdir --ignore-fail-on-non-empty "$MOVINGDIR"/urls
# "$DISTDIR" already contains everything needed to proceed. Let's do it!
       /usr/bin/emerge $*
   fi
    fi
    rm "$tempfile1" "$tempfile2"
fi

# "$MOVINGDIR"/remote-fetch
if [ -n "$snapshot" -o ! -x "$MOVINGDIR"/remote-fetch ]
    then
# Update or create (first run) "$MOVINGDIR"/remote-fetch
    tempfile3=`tempfile`
    echo '#!/bin/sh
# Distributed under the terms of the GNU General Public License v2
' > "$tempfile3"
    echo "GENTOO_MIRRORS=\"$GENTOO_MIRRORS\"" >> "$tempfile3"
    if [ -n "$snapshot" ]
   then
   snapshotfile=${snapshot##*/}
   echo "LAST_SNAPSHOT_INSTALLED=${snapshotfile:8:8}" >> "$tempfile3"
    else
   echo "LAST_SNAPSHOT_INSTALLED=0" >> "$tempfile3"
    fi
    cat "$tempfile3" /usr/share/remote-emerge/remote-fetch > "$MOVINGDIR"/remote-fetch
    chmod 755 "$MOVINGDIR"/remote-fetch
    rm "$tempfile3"
fi

# Cleaning (in case of a deleted action)
# Update $MOVINGDIR/.partial_fetch and $MOVINGDIR/distfiles/* according to $MOVINGDIR/urls/*
if [ -f "$MOVINGDIR"/.partial_fetch -a -d "$MOVINGDIR"/urls ]
    then
# There may be some useful partial fetchs
    tempfile4=`tempfile`
    while read sourcefile
      do
      if [ "$sourcefile" != "portage-" ]
     then
     if grep -q "$sourcefile" "$MOVINGDIR"/urls/*
         then
         echo "$sourcefile" >> "$tempfile4"
     else
# $sourcefile is marked to be partially fetched but is not required to fulfill any reqested action
         rm -f "$MOVINGDIR/distfiles/$sourcefile"
     fi
      fi
    done < "$MOVINGDIR"/.partial_fetch
    if [ -s "$tempfile4" ]
   then
   mv "$tempfile4" "$MOVINGDIR"/.partial_fetch
    else
   rm -f "$MOVINGDIR"/distfiles/* "$MOVINGDIR"/.partial_fetch "$tempfile4"
    fi
else
    rm -f "$MOVINGDIR"/distfiles/* "$MOVINGDIR"/.partial_fetch
fi


/usr/share/remote-emerge/remote-fetch:

rm_oldest_snapshot_exclude ()
{
    for snapshot in portage-[2-9][0-9][0-9][0-9][0-1][0-9][0-3][0-9].tar.bz2
      do
      if [ "$snapshot" != "$1" ]
     then
     rm snapshot
     return 0
      fi
    done
# No snapshot to remove
    return 1
}

delete_line_from_partial_fetch ()
{
    tempfile=`mktemp`
    grep -v ^"$1"$ .partial_fetch > $tempfile
    if [ -s $tempfile ]
   then
   mv $tempfile .partial_fetch
    else
   rm .partial_fetch $tempfile
    fi
}

fetch ()
{
    file="${1##*/}"
    if grep ^"$file"$ .partial_fetch &> /dev/null
   then
   PRESENT_PARTIALLY_FETCHED_SOURCE="t"
    fi
    if [ ! -f "$2/$file" -o -n "$PRESENT_PARTIALLY_FETCHED_SOURCE" ]
   then
# Try to fetch the source (new download or continuition of a previous one)
   if [ -z "$PRESENT_PARTIALLY_FETCHED_SOURCE" ]
       then
       echo "$file" >> .partial_fetch
   fi
   if wget -T 180 -t 3 -nd -c -P "$2" "$1"
       then
# The source was totally fetched
       delete_line_from_partial_fetch "$file"
       return 0
   else
       if [ ! -f "$2/$file" ]
      then
      delete_line_from_partial_fetch "$file"
       fi
# The source was only partially fetched
       return 1
   fi
    fi
# The source is already totally downloaded
    return 0
}


# Fetch the distfiles
if [ -d urls ]
    then
    if [ ! -d distfiles ]
        then
        mkdir -m 755 distfiles
    fi
    lastfilefetched=""
    for URLlist in urls/*
      do
      while read url
   do
   file="${url##*/}"
   if [ "$file" != "$lastfilefetched" ]
       then
       ROOM="0"
       while [ "$ROOM" = "0" ]
         do
         ROOM="1"
         if fetch "$url" distfiles
        then
        lastfilefetched="$file"
         else
        ROOM=`df -P . | awk 'NR==2 {print $4}'`
        if [ "$ROOM" = "0" -a -f distfiles/"${url##*/}" ]
            then
            if ! rm_oldest_snapshot_exclude
           then
# There is no space left on the amovible device and no other portage snapshot to remove and make room
           exit $EX_IOERR
            fi
        fi
         fi
       done
   fi
      done < "$URLlist"
    done
    rmdir distfiles 2> /dev/null
fi

for i in 0 1 2 3 4 5 6 7 8 9
  do
  snapshotdate=`date -d "$i day ago" +%Y%m%d`
  if [ $snapshotdate -eq $LAST_SNAPSHOT_INSTALLED ]
      then
# No newer portage tree on Internet can be (totally) fetched
      exit $EX_OK
  fi
  for mirror in "$GENTOO_MIRRORS"
    do
    ROOM="0"
    while [ "$ROOM" = "0" ]
      do
      if fetch "$mirror"/snapshots/portage-${snapshotdate}.tar.bz2 .
     then
# Remove any older partially fetched snapshot
     for present_snapshot in `ls portage-*.tar.bz2 2> /dev/null`
       do
       if [ "$present_snapshot" \< portage-${snapshotdate}.tar.bz2 ]
      then
      rm "$present_snapshot"
       fi
     done
     exit $EX_OK
      else
     ROOM=`df -P . | awk 'NR==2 {print $4}'`
     if [ "$ROOM" = "0" -a -f portage-${snapshotdate}-tar.bz2 ]
         then
         if ! rm_oldest_snapshot_exclude portage-${snapshotdate}-tar.bz2
        then
# There is no space left on the amovible device and no other portage snapshot to remove and make room
        exit $EX_IOERR
         fi
     fi
      fi
    done
  done
done


Je vous invite à relire la fin de mon message précédent (après les sources).

Merci pour votre aide.
Back to top
View user's profile Send private message
Temet
Advocate
Advocate


Joined: 14 Mar 2006
Posts: 2586
Location: 92

PostPosted: Fri Nov 17, 2006 5:31 pm    Post subject: Reply with quote

Je me suis permis de rajouter un "#!/bin/bash" au début du deuxième script.
Il n'avait pas l'icône d'un script bash, ça m'a mis la puce ;)

http://goondy.free.fr/magicbanana/remote-emerge-0.2.1
Back to top
View user's profile Send private message
Magic Banana
Veteran
Veteran


Joined: 13 Dec 2005
Posts: 1912
Location: Belo Horizonte, Minas Gerais, Brasil

PostPosted: Fri Nov 17, 2006 5:42 pm    Post subject: Reply with quote

En fait, tu ne devais pas te permettre ! :lol:

Le début du script (Sha-Bang compris) est pris depuis remote-emerge et me permet de stocker la liste des mirroirs Gentoo et surtout la date du dernier snapshot installé. Donc, s'il te plaît, pourrais-tu retirer ton ajout (mais garder la ligne blanche initiale pour raison esthétique sur le script généré :P ) ? Merci.

Merci à tous ceux qui vont tester ce script durant le week-end.
Back to top
View user's profile Send private message
Temet
Advocate
Advocate


Joined: 14 Mar 2006
Posts: 2586
Location: 92

PostPosted: Fri Nov 17, 2006 7:58 pm    Post subject: Reply with quote

Désolé :oops:

Le boulet a corrigé sa boulette :cry:
Back to top
View user's profile Send private message
Magic Banana
Veteran
Veteran


Joined: 13 Dec 2005
Posts: 1912
Location: Belo Horizonte, Minas Gerais, Brasil

PostPosted: Tue Nov 21, 2006 10:10 am    Post subject: Reply with quote

La version précédente fonctionnait bien. Toutefois, je me suis fendu de quelques ajouts finaux pour ce qui est la version 0.3 de remote-emerge :
* Supression de l'overhead pour quelquesactions (que j'avais oublié) ne nécessitant pas Internet comme "remote-emerge --unmerge" ou "remote-emerge --resume".
* Afin d'éviter la création d'une arborescence en locale si le périphérique amovible n'est pas monté, le script demande maintenant si l'abscence du répertoire $MOVINGDIR est dû à un oubli de monter ce périphérique ou non.

Encore cette fois, je l'espère, vous pourrez très bientôt télécharger les deux fichiers nécessaires à l'installation de remote-emerge depuis le serveur FTP de Temet que je remercie.

Alternativement vous pouvez les copier depuis ce message :

/usr/bin/remote-emerge:
#!/bin/bash
# Distributed under the terms of the GNU General Public License v2
# AUTHOR: Magic Banana
# e-mail: magicbanana@gmail.com

# Exit status codes
EX_OK=0
EX_USAGE=64

proceed_url_lists ()
{
    if [ -d "$MOVINGDIR"/urls ]
   then
   for URLlist in "$MOVINGDIR"/urls/*
     do
     remote-emerge "${URLlist##*/}"
   done
    fi
}

# Variables definitions
source /etc/make.globals
source /etc/make.conf
if [ -z "$MOVINGDIR" ]
    then
    echo "
MOVINGDIR must be the name of a directory on an amovible device.
Please set this variable in /etc/make.conf.

You can, for instance, adapt the following command:
echo 'MOVINGDIR=\"/media/usbdisk/moving-portage\"' >> /etc/make.conf"
    exit $EX_USAGE
fi

# Check if the amovible device seems to be plugged
if [ ! -d "$MOVINGDIR" ]
    then
    firstletteranswer=""
    while [ "$firstletteranswer" != "y" -a "$firstletteranswer" != "Y" ]
      do
      echo -n "Is your amovible device mounted? [y/N] "
      read answer
      firstletteranswer=${answer:0:1}
      if [ -z "$firstletteranswer" -o "$firstletteranswer" = "n" -o "$firstletteranswer" = "N" ]
     then
     exit $EX_USAGE
      fi
    done
fi

# If there is a distfiles directory on the amovible device copy its content in "$DISTDIR"
if [ ! -d "$MOVINGDIR"/distfiles ]
    then
    mkdir -p -m 755 "$MOVINGDIR"/distfiles
else
    for sourcefile in "$MOVINGDIR"/distfiles/*
      do
      if ! grep "${sourcefile##*/}" "$MOVINGDIR"/.partial_fetch &> /dev/null
     then
     mv "$sourcefile" "$DISTDIR" 2> /dev/null
      fi
    done
# I love clean permissions :
    chmod 644 "$DISTDIR"/*
fi

# remote-emerge --oldactions
if [ "$*" = "--oldactions" ]
    then
    proceed_url_lists
    snapshot=`ls "$MOVINGDIR"/portage-[2-9][0-9][0-9][0-9][0-1][0-9][0-3][0-9].tar.bz2 2> /dev/null | awk 'NR==1 {print}'`
    if test -n "$snapshot" && ! grep ^${snapshot}$ "$MOVINGDIR"/.partial_fetch &> /dev/null
   then
# A new snapshot was totally downloaded
# Remove the one currently installed (but keep the precious disfiles, the packages, the rpms and the local directory)
   for file in "$PORTDIR"/*
     do
     if [ "$file" != "$DISTDIR" -a "$file" != "$PKGDIR" -a "$file" != "$RPMDIR" -a "$file" != "$PORTDIR"/../local ]
         then
         rm -rf "$file"
     fi
   done
# Install the new Portage tree
   tar -xvjf "$snapshot" -C "$PORTDIR"/..
# Update Portage cache
   /usr/bin/emerge --metadata
   rm "$snapshot"
   proceed_url_lists
    fi
else

# For any operation which does not require any fetch, use directly emerge
    for arg in $*
      do
      case $arg in
     --help|-*h*    ) echo "
remote-emerge allows you to administrate offline your system in exactly the
same way and with the same syntax as emerge. However the option --sync is not
used since fetching the Portage tree is considered as a permanent request.
To perform every action previously requested and synchronize your Portage
tree (in the limit of what has been fetched), symply run
'remote-emerge --oldactions'." && /usr/bin/emerge $* && exit $EX_OK;;
     --oldactions   ) echo "
To perform every action previously requested and synchronize your Portage
tree (in the limit of what has been fetched), symply run
'remote-emerge --oldactions' without any other option." && exit $EX_USAGE;;
     --sync         ) echo "
The option --sync is not used since fetching the Portage is considered
as a permanent request. To perform every action previously requested and
synchronize your Portage tree (in the limit of what has been fetched),
symply run 'remote-emerge --oldactions'." && exit $EX_USAGE;;
     --version|-*V* ) echo "remote-emerge 0.3" && /usr/bin/emerge $* && exit $EX_OK;;
     --clean|--config|--depclean|--info|--metadata|--pretend|--prune|--regen|--resume|--search|--searchdesc|--unmerge|--changelog|--tree|--usepkgonly|-*c*|-*p*|-*P*|-*s*|-*S*|-*C*|-*l*|-*t*|-*K* ) /usr/bin/emerge $* && exit $EX_OK;;
      esac
    done

# Create "$MOVINGDIR"/urls if not already there
    if [ ! -d "$MOVINGDIR"/urls ]
   then
   mkdir -m 755 "$MOVINGDIR"/urls
    fi

# Create the list of urls to fetch in order to perform the requested action
    newline="
"
    tempfile1=`tempfile`
    /usr/bin/emerge -fp $* 1> /dev/null 2> "$tempfile1"
    tempfile2=`tempfile`
# Strip out fetch-restrict messages, turn spaces into newlines and remove blank lines
    if grep -v "^!!!" "$tempfile1" | cut -d " " -f 1- --output-delim="$newline" | grep -v "^$" > "$tempfile2"
   then
   if [ -f "$MOVINGDIR/urls/$*" ]
       then
# This command has been invoked earlier without being satisfied, remove the old urls
       rm "$MOVINGDIR/urls/$*"
   fi
# Skip files already in "$DISTDIR" and write the URLs on the amovible device
   last=""
   while read url
     do
     if [ "${url##*/}" = "$last" ]
         then
         if [ -n "$isabsent" ]
        then
        echo "$url" >> "$MOVINGDIR/urls/$*"
         fi
     else
         if [ -f "$DISTDIR/${url##*/}" ]
        then
        isabsent=""
         else
        echo "$url" >> "$MOVINGDIR/urls/$*"
        isabsent="t"
         fi
         last="${url##*/}"
     fi
   done < "$tempfile2"
   if [ -f "$MOVINGDIR/urls/$*" ]
       then
       echo "
'remote-emerge $*' requires the execution of the file
remote-fetch (on your amovible device) from a machine connected to Internet."
   else
# "$DISTDIR" already contains everything needed to proceed. Do it!
       /usr/bin/emerge $*
   fi
    fi
    rm "$tempfile1" "$tempfile2"
fi

# "$MOVINGDIR"/remote-fetch
if [ -n "$snapshot" -o ! -x "$MOVINGDIR"/remote-fetch ]
    then
# Update or create (first run) "$MOVINGDIR"/remote-fetch
    tempfile3=`tempfile`
    echo '#!/bin/sh
# Distributed under the terms of the GNU General Public License v2
' > "$tempfile3"
    echo "GENTOO_MIRRORS=\"$GENTOO_MIRRORS\"" >> "$tempfile3"
    if [ -n "$snapshot" ]
   then
   snapshotfile=${snapshot##*/}
   echo "LAST_SNAPSHOT_INSTALLED=${snapshotfile:8:8}" >> "$tempfile3"
    else
   echo "LAST_SNAPSHOT_INSTALLED=0" >> "$tempfile3"
    fi
    cat "$tempfile3" /usr/share/remote-emerge/remote-fetch > "$MOVINGDIR"/remote-fetch
    chmod 755 "$MOVINGDIR"/remote-fetch
    rm "$tempfile3"
fi

# Cleaning (in case of manually deleted actions and/or Portage snapshots)
# Update $MOVINGDIR/.partial_fetch and $MOVINGDIR/distfiles/* according to $MOVINGDIR/urls/* and $MOVINGDIR (for Portage snapshots)
rmdir "$MOVINGDIR"/urls 2> /dev/null
if [ -f "$MOVINGDIR"/.partial_fetch -a -d "$MOVINGDIR"/urls ]
    then
# There may be some useful partial fetchs
    tempfile4=`tempfile`
    while read sourcefile
      do
      if test -f "$sourcefile" || grep -q "$sourcefile" "$MOVINGDIR"/urls/*
     then
     echo "$sourcefile" >> "$tempfile4"
      else
# $sourcefile is marked to be partially fetched but is not required to fulfill any reqested action
     rm -f "$MOVINGDIR/distfiles/$sourcefile"
      fi
    done < "$MOVINGDIR"/.partial_fetch
    if [ -s "$tempfile4" ]
   then
   mv "$tempfile4" "$MOVINGDIR"/.partial_fetch
    else
   rm -f "$MOVINGDIR"/distfiles/* "$MOVINGDIR"/.partial_fetch "$tempfile4"
    fi
else
    rm -f "$MOVINGDIR"/distfiles/* "$MOVINGDIR"/.partial_fetch
fi
exit $EX_OK


/usr/share/remote-emerge/remote-fetch:
delete_line_from_partial_fetch ()
{
    tempfile=`mktemp`
    grep -v ^"$1"$ .partial_fetch > $tempfile
    if [ -s $tempfile ]
   then
   mv $tempfile .partial_fetch
    else
   rm .partial_fetch $tempfile
    fi
}

rm_oldest_snapshot_exclude ()
{
    for snapshot in portage-[2-9][0-9][0-9][0-9][0-1][0-9][0-3][0-9].tar.bz2
      do
      if [ "$snapshot" != "$1" ]
     then
     rm snapshot
     delete_line_from_partial_fetch "$snapshot"
     return 0
      fi
    done
# No snapshot to remove
    return 1
}

fetch ()
{
    file="${1##*/}"
    if grep ^"$file"$ .partial_fetch &> /dev/null
   then
   PRESENT_PARTIALLY_FETCHED_SOURCE="t"
    fi
    if [ ! -f "$2/$file" -o -n "$PRESENT_PARTIALLY_FETCHED_SOURCE" ]
   then
# Try to fetch the source (new download or continuition of a previous one)
   if [ -z "$PRESENT_PARTIALLY_FETCHED_SOURCE" ]
       then
       echo "$file" >> .partial_fetch
   fi
   if wget -T 180 -t 3 -nd -c -P "$2" "$1"
       then
# The source was totally fetched
       delete_line_from_partial_fetch "$file"
       return 0
   else
       if [ ! -f "$2/$file" ]
      then
      delete_line_from_partial_fetch "$file"
       fi
# The source was only partially fetched
       return 1
   fi
    fi
# The source is already totally downloaded
    return 0
}


# Fetch the distfiles
if [ -d urls ]
    then
    if [ ! -d distfiles ]
        then
        mkdir -m 755 distfiles
    fi
    lastfilefetched=""
    for URLlist in urls/*
      do
      while read url
   do
   file="${url##*/}"
   if [ "$file" != "$lastfilefetched" ]
       then
       ROOM="0"
       while [ "$ROOM" = "0" ]
         do
         ROOM="1"
         if fetch "$url" distfiles
        then
        lastfilefetched="$file"
         else
        ROOM=`df -P . | awk 'NR==2 {print $4}'`
        if [ "$ROOM" = "0" -a -f distfiles/"${url##*/}" ]
            then
            if ! rm_oldest_snapshot_exclude
           then
# There is no space left on the amovible device and no other portage snapshot to remove and make room
           exit $EX_IOERR
            fi
        fi
         fi
       done
   fi
      done < "$URLlist"
    done
    rmdir distfiles 2> /dev/null
fi

for i in 0 1 2 3 4 5 6 7 8 9
  do
  snapshotdate=`date -d "$i day ago" +%Y%m%d`
  if [ $snapshotdate -eq $LAST_SNAPSHOT_INSTALLED ]
      then
# No newer portage tree on Internet can be (totally) fetched
      exit $EX_OK
  fi
  for mirror in "$GENTOO_MIRRORS"
    do
    ROOM="0"
    while [ "$ROOM" = "0" ]
      do
      if fetch "$mirror"/snapshots/portage-${snapshotdate}.tar.bz2 .
     then
# Remove any older partially fetched snapshot
     for present_snapshot in `ls portage-*.tar.bz2 2> /dev/null`
       do
       if [ "$present_snapshot" \< portage-${snapshotdate}.tar.bz2 ]
      then
      rm "$present_snapshot"
      delete_line_from_partial_fetch "$present_snapshot"
       fi
     done
     exit $EX_OK
      else
     ROOM=`df -P . | awk 'NR==2 {print $4}'`
     if [ "$ROOM" = "0" -a -f portage-${snapshotdate}-tar.bz2 ]
         then
         if ! rm_oldest_snapshot_exclude portage-${snapshotdate}-tar.bz2
        then
# There is no space left on the amovible device and no other portage snapshot to remove and make room
        exit $EX_IOERR
         fi
     fi
      fi
    done
  done
done
exit $EX_IOERR


Voilà la procédure d'installation (quelqu'un veut me faire un ebuild ?) :
1) Devenir root :
Code:
# su

2) Copier remote-emerge dans /usr/bin/remote-emerge et le rendre exécutable avec la commande suivante :
Code:
# chmod 755 /usr/bin/remote-emerge

NB : Le script s'appelant lui-même, il doit impérativement se trouver dans un répertoire de votre variable PATH
3) Créer le répertoire /usr/share/remote-emerge :
Code:
# mkdir /usr/share/remote-emerge

NB : Ce répertoire ne peut être changé (à moins de modifier à la main /usr/bin/remote-emerge)
4) Copier remote-fetch dans /usr/share/remote-emerge/remote-fetch
5) Définir la variable MOVINGDIR (répertoire sur le périphérique amovible) dans /etc/make.conf. Si ce n'est pas fait, le script vous le rappellera (avec en bonus, un exemple).

La commande remote-emerge a exactement la même syntaxe qu'emerge à cela près que l'option "--sync" n'est plus disponible (le script considère que la mise à jour de l'arbre Portage est une requête parmanente) et qu'une nouvelle option "--oldactions" est ajoutée pour permettre l'installation de tout ce qui a été demandé précédemment (et de l'arbre Portage). La limite de ce qui sera effectivement fait est bien entendu fixée à ce que vous aurez réussi à télécharger sur votre périphérique amovible en exécutant remote-fetch (il n'est donc pas problématique que le périphérique amovible soit un peu plein). Remote-fetch est un autre script qui se crée et se recrée sur votre périphérique amovible à chaque utilisation de remote-emerge (ne vous inquiettez pas, le script s'occupe de tout, aucune action demandée ne sera oubliée). Bref, un cycle classique d'utilisation est :
1) Quelques remote-emerge "type emerge" sur la Gentoo (par exemple "remote-emerge -uDN world")
2) Exécution de remote-fetch sur une machine connectée à internet (tout *NIX fera l'affaire)
3) De retour sur la Gentoo, exécution de "remote-emerge --oldactions"

Notez qu'entre 1 et 3 vous pouvez facilement renoncer à une action en supprimant le fichier correspondant dans le répertoire urls.
Notez également que vous pouvez sans problème d'intégrité faire de la place sur votre périphérique amovible en supprimant des sources dans le répertoire distfiles ou en supprimant un éventuel snapshot de l'arbre Portage.
Vous pouvez aussi rajouter à la main des sources dans le répertoire distfiles.

EDIT : Version 0.3 et non 3...


Last edited by Magic Banana on Tue Nov 21, 2006 10:21 am; edited 1 time in total
Back to top
View user's profile Send private message
Temet
Advocate
Advocate


Joined: 14 Mar 2006
Posts: 2586
Location: 92

PostPosted: Tue Nov 21, 2006 10:19 am    Post subject: Reply with quote

Quand j'ai ton mail, je le fais.
Sinon, un 'ti tarball en vue d'un ebuild? ^^
Back to top
View user's profile Send private message
Magic Banana
Veteran
Veteran


Joined: 13 Dec 2005
Posts: 1912
Location: Belo Horizonte, Minas Gerais, Brasil

PostPosted: Tue Nov 21, 2006 10:27 am    Post subject: Reply with quote

Le serveur Gmail est indisponible temporairement... :oops: Je réessaie dans un moment pour t'envoyer tout cela (un tar.bz2 aussi si tu la Fedora du labo peut me faire ça).

Pour un ebuild, je ne suis pas contre un petit coup de main. Vu la complexité de la procédure d'installation, ce ne doit pas être bien dur... mais vu que je n'ai jamais fait ça et que je ne peux pas le tester (ma Gentoo étant offline... :cry: )...

Qui se porte volontaire ?
Back to top
View user's profile Send private message
Temet
Advocate
Advocate


Joined: 14 Mar 2006
Posts: 2586
Location: 92

PostPosted: Tue Nov 21, 2006 1:13 pm    Post subject: Reply with quote

[Maître Yoda]Le tout en ligne est[/Maître Yoda]
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index French All times are GMT
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum