<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<atom:link href="http://forum.ubuntu-fr.org/extern.php?action=feed&amp;tid=380645&amp;type=rss" rel="self" type="application/rss+xml" />
		<title><![CDATA[Forum Ubuntu-fr.org / [bash]Script commande: option usage [résolu]]]></title>
		<link>http://forum.ubuntu-fr.org/viewtopic.php?id=380645</link>
		<description><![CDATA[Les sujets les plus récents dans [bash]Script commande: option usage [résolu].]]></description>
		<lastBuildDate>Wed, 24 Feb 2010 23:03:00 +0000</lastBuildDate>
		<generator>FluxBB</generator>
		<item>
			<title><![CDATA[Réponse à&#160;:  [bash]Script commande: option usage [résolu]]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=3301178#p3301178</link>
			<description><![CDATA[<p>j&#039;avais vu ça sur un blog <img src="http://forum.ubuntu-fr.org/img/smilies/hmm.png" width="15" height="15" alt="hmm" /><br />et merci pour la modif <img src="http://forum.ubuntu-fr.org/img/smilies/big_smile.png" width="15" height="15" alt="big_smile" /></p>]]></description>
			<author><![CDATA[dummy@example.com (wido)]]></author>
			<pubDate>Wed, 24 Feb 2010 23:03:00 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=3301178#p3301178</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  [bash]Script commande: option usage [résolu]]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=3301138#p3301138</link>
			<description><![CDATA[<p>Je me sent pas de tout lire, mais deja ça ca va pas :<br /><strong>kill -15 $MYAPP_PID 2&gt;&amp;1 &gt; /dev/null</strong><br /><strong>-15 </strong>c&#039;est deja le cas sans option.<br />la redirection correcte, c&#039;est :<br /><strong>&gt; /dev/null 2&gt;&amp;1</strong><br />ou alors <br /><strong>&amp;&gt; /dev/null </strong><br />la derniere solution est un bashism donc non POSIX.<br />Donc au final :<br /><strong>kill $MYAPP_PID &amp;&gt; /dev/null</strong></p>]]></description>
			<author><![CDATA[dummy@example.com (sputnick)]]></author>
			<pubDate>Wed, 24 Feb 2010 22:42:01 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=3301138#p3301138</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  [bash]Script commande: option usage [résolu]]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=3301078#p3301078</link>
			<description><![CDATA[<p>Voici mon script:</p><div class="codebox"><pre class="vscroll"><code>#!/bin/bash
#set -x

AUTEUR=&quot;Wido &lt;widomaker2k7 gmail.com&gt;&quot;
VERSION=&quot;0.1&quot;
LICENCE=&quot;GPL&quot;
file=$2

. ./swall.conf # Lecture du fichier de configuration

# # # # # # # # # # # # # # # # #
#   __Couleurs__ 
# # # # # # # # # # # # # # # # #
msgR () { # rouge
	local mesg=$1; shift
	printf &quot;${_RG}==&gt;${_FN} ${_BN}${mesg}${_FN}\n&quot; &quot;$@&quot; &gt;&amp;2
}

msgV () { # vert
	local mesg=$1; shift
	printf &quot;${_VR}==&gt;${_FN} ${_BN}${mesg}${_FN}\n&quot; &quot;$@&quot; &gt;&amp;2
}

msgJ () { # jaune
	local mesg=$1; shift
	printf &quot;${_JN}==&gt;${_FN} ${_BN}${mesg}${_FN}\n&quot; &quot;$@&quot; &gt;&amp;2
}

msgB () { # bleu
	local mesg=$1; shift
	printf &quot;${_BL}==&gt;${_FN} ${_BN}${mesg}${_FN}\n&quot; &quot;$@&quot; &gt;&amp;2
}

# Analyse le dossier image pour en sortir un fichier .db
wallpaper() {
    if [ -f &quot;$file&quot; ]; then
        echo &quot;C&#039;est un fichier&quot;

    elif [ -d &quot;$file&quot; ]; then

        echo &quot;c&#039;est un dossier&quot;
        create_database

    else

        echo &quot;le fichier ou dossier n&#039;existe pas&quot;
        exit 1

    fi

}

lockfile() {
if [ -e $LOCKFILE ]
 
then
   echo &quot;Actuellement $0 tourne.&quot;
   exit 1

   else
       echo $! &gt; $LOCKFILE
fi
}

resetlockfile() {

if [ -e $LOCKFILE ]
 
then
   # Read PID from lock file
   read MYAPP_PID &lt; $LOCKFILE
 
   # Kill MyApplication by sending a SIGTERM signal
   $(kill $MYAPP_PID &amp;&gt; /dev/null)
   echo &quot;MyApplication stopped.&quot;
 
   # Remove obsolete lock file and exit
   rm $LOCKFILE
else
   echo &quot;MyApplication is not running.&quot;
fi

}

dependance() {
if [ -x &quot;/usr/bin/identify&quot; ]; then

# Vérification de imagemagick
        vLONGUEUR=$(($LONGUEUR -1))
        vHAUTEUR=$(($HAUTEUR -1))
        WIDTH=`identify -format &quot;%w&quot; &quot;$ligne&quot;`
        HEIGHT=`identify -format &quot;%h&quot; &quot;$ligne&quot;`

    elif [ -x &quot;/usr/bin/feh&quot; ]; then
        vLONGUEUR=$(($LONGUEUR -1))
        vHAUTEUR=$(($HAUTEUR -1))
        WIDTH=`feh -l &quot;$ligne&quot; | grep 1 | awk &#039;{print $3}&#039;`
        HEIGHT=`feh -l &quot;$ligne&quot; | grep 1 | awk &#039;{print $4}&#039;`
    else
# Sinon on quitte le script
echo &quot;Ni feh ni imagemagick ne sont installés&quot;
    exit 1
fi
}

# Creation du fichier temporaire ( par defaut: temporaire=/tmp/wallpaper.log ).
create_temporaire() {
    if [ -f &quot;$temporaire&quot; ]; then
        msgR &quot;Suppression des anciens fichiers temporaires&quot;
        rm &quot;/tmp/wallpaper.bak&quot;
        rm &quot;/tmp/wallpaper.bak2&quot;
        msgJ &quot;creation du fichier $temporaire&quot;
        mv &quot;$temporaire&quot; &quot;/tmp/wallpaper.bak&quot;

        # Creation un log recensant toutes les images contenues dans le dossier.
        find &quot;$file&quot; -type f -name &#039;*.jpg&#039; -o -name &#039;*.png&#039; &gt;&gt; &quot;/tmp/wallpaper.bak2&quot;
        cat &quot;/tmp/wallpaper.bak&quot; &quot;/tmp/wallpaper.bak2&quot; | sort | uniq &gt; $temporaire

    else

        find &quot;$file&quot; -type f -name &#039;*.jpg&#039; -o -name &#039;*.png&#039; &gt;&gt; &quot;$temporaire&quot;

    fi
}

create_database() {
if [ ! -f &quot;$temporaire&quot; ]; then
create_temporaire

else

 while read ligne
    do
        dependance # test du dimensionnement: feh ou imagemagick

        if [ &quot;$WIDTH&quot; -gt &quot;$vLONGUEUR&quot; ] &amp;&amp; [ &quot;$HEIGHT&quot; -gt &quot;$vHAUTEUR&quot; ]; then

            sleep 1
            echo &quot;$ligne&quot; &gt;&gt; &quot;$temporaire2&quot; # image ajoutée
            msgV &quot;$ligne add&quot;
            cat &quot;$temporaire2&quot; | sort | uniq &gt; &quot;$file/$nom_database.db&quot;

        else
            msgJ &quot;$ligne non ajouté à $file/$nom_database.db&quot;
        fi
    done &lt; $temporaire

fi
resetlockfile
}

#Affiche les images contenus dans le fichier .db au format de l&#039;écran.
database() {
    if [ -f &quot;$file&quot; ]; then
        echo &quot;image: $file&quot;

        while true;
        do
            IMAGE=`cat &quot;$file&quot; | shuf -n 1`
            feh --bg-scale &quot;$IMAGE&quot; #afficher l&#039;image avec feh
            sleep $temps
        done &amp;

    elif [ -d &quot;$file&quot; ]; then
        msgJ &quot;c&#039;est un dossier&quot;
        print_info
    else
        msgJ &quot;le fichier ou dossier n&#039;existe pas&quot;
        resetlockfile
        exit 1
    fi
}

print_info() {
	cat &lt;&lt;- EOF

		swall script qui affiche les images ayant la même résolution que votre écran.

		Usage: $0 [option] &lt;package&gt; [...]

        Options: -h, --help                 Show this help
                 -v, --version              Print version

                 -d, --database &lt;fichier&gt;   Afficher les images contenues
                                            dans le fichier au format db.

                 -w, --wallpaper &lt;dossier&gt;  Analyse le dossier image 
                                            pour creer un fichier au format db.

        Paramètres à modifier: $0.conf
                                            Taille de l&#039;écran: &quot;$LONGUEUR x $LONGUEUR&quot;
                                            nom de la base de données: &quot;$nom_database&quot;
                                            temporisation: &quot;$temps&quot;

	EOF
    resetlockfile
	exit $1
}

while getopts &quot;vh-:vhw-:vhd-:&quot; opt ; do
	if [ $opt = &quot;-&quot; ] ; then
		case $OPTARG in
			help ) opt=&quot;h&quot; ;;
			version ) opt=&quot;v&quot; ;;
            wallpaper ) opt=&quot;w&quot; ;;
            database ) opt=&quot;d&quot; ;;
			* ) echo &quot;option inconnue...&quot; ;;
		esac
	fi
	case $opt in
		h )
        lockfile

        print_info
        ;;
		v )
        lockfile
        clear
        echo &quot;Version: $VERSION $AUTEUR&quot;
        echo &quot;Licence: $LICENCE&quot;
        ;;
        d )
        lockfile
        database
        ;;
        w )
        lockfile
        wallpaper
        ;;
		? ) msgJ &quot;option inconnue&quot; 
        ;;
	esac
done
OPTS=&quot;${@}&quot;</code></pre></div><p>swall.conf:</p><div class="codebox"><pre><code># Nom de la base de données (defaut: database)
nom_database=&quot;image.db&quot;
# temporisation entre deux images (defaut: 15m)
temps=15m
# Longueur de la taille de l&#039;écran (defaut 1280)
LONGUEUR=1280
# Largeur de la taille de l&#039;écran (defaut 1024)
HAUTEUR=1024

# fichier temporaire (ne pas modifier):
temporaire=&quot;/tmp/wallpaper.log&quot;
temporaire2=&quot;/tmp/wallpaper2.log&quot;
LOCKFILE=/tmp/swall.lock</code></pre></div><p>il y a peut-être des choses à modifier.</p>]]></description>
			<author><![CDATA[dummy@example.com (wido)]]></author>
			<pubDate>Wed, 24 Feb 2010 22:13:07 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=3301078#p3301078</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  [bash]Script commande: option usage [résolu]]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=3295655#p3295655</link>
			<description><![CDATA[<p>Merci à vous deux, j&#039;ai déjà du mal à coder, les exemples que tu donnes sputnick ne sont pas pour moi, beaucoup trop compliqué <img src="http://forum.ubuntu-fr.org/img/smilies/lol.png" width="15" height="15" alt="lol" /></p><p>je passerai le sujet en résolu quand je n&#039;aurais plus de question, en deux trois mots, le script permettra d&#039;analyser un dossier image pour qu&#039;il affiche uniquement les images aux résolutions de l&#039;écran comme ça on n&#039;a pas de pixel qui se balade.</p>]]></description>
			<author><![CDATA[dummy@example.com (wido)]]></author>
			<pubDate>Mon, 22 Feb 2010 16:57:42 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=3295655#p3295655</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  [bash]Script commande: option usage [résolu]]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=3295598#p3295598</link>
			<description><![CDATA[<p>Pour les options longue je source ce script ^^</p><p>http://sputnick-area.net/ftp/downloads/getopts_long.sh</p><p>http://sputnick-area.net/ftp/downloads/getopts_long_example.sh</p>]]></description>
			<author><![CDATA[dummy@example.com (sputnick)]]></author>
			<pubDate>Mon, 22 Feb 2010 16:29:46 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=3295598#p3295598</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  [bash]Script commande: option usage [résolu]]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=3295560#p3295560</link>
			<description><![CDATA[<p>j&#039;avais trouvé dans le même style:</p><div class="codebox"><pre><code>while getopts &quot;vh-:&quot; opt ; do
	if [ $opt = &quot;-&quot; ] ; then
		case $OPTARG in
			help ) opt=&quot;h&quot; ;;
			version ) opt=&quot;v&quot; ;;
			* ) echo &quot;option longue inconnue...&quot; ;;
		esac
	fi
	case $opt in
		h ) echo &quot;help....&quot;
        print_info&quot;
        ;;
		v ) echo &quot;version...&quot; 
        echo &quot;$VERSION&quot;
        ;;
		? ) echo &quot;option inconnue&quot; 
        ;;
	esac
done</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (wido)]]></author>
			<pubDate>Mon, 22 Feb 2010 16:15:38 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=3295560#p3295560</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  [bash]Script commande: option usage [résolu]]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=3295480#p3295480</link>
			<description><![CDATA[<p>Bonjour,</p><p>Je suis pas certain d&#039;avoir compris ton besoin.<br />Je suppose que tu souhaites trouver une solution afin de déterminer si les options --wallpaper ou --database ont été positionnées.<br />Si c&#039;est le cas, voilà comment je ferais :</p><div class="codebox"><pre><code>while getopts :-: option
do
  case ${option} in
    -) case $OPTARG in
        -wallpaper) ...;;
        -database) ... ;;
        *) ...;;
       esac;;

    :) echo &quot;Argument manquant pour l&#039;option ${OPTARG}.&quot;;;

    ?) echo &quot;Option non valide : ${OPTARG}.&quot;;;
  esac
done
shift $((OPTIND-1))</code></pre></div><p>Note : j&#039;ai pas testé</p>]]></description>
			<author><![CDATA[dummy@example.com (Totor)]]></author>
			<pubDate>Mon, 22 Feb 2010 15:39:49 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=3295480#p3295480</guid>
		</item>
		<item>
			<title><![CDATA[[bash]Script commande: option usage [résolu]]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=3295355#p3295355</link>
			<description><![CDATA[<p>Bonjour,</p><p>Je recherche des exemples de script ce basant sur cette exemple:</p><p>$sh script<br />Version 0.01<br />Usage: script --wallpaper [Dossier] #analyse la totalité du dossier et crée un fichier database (.db)<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;--database [Fichier] #Lis le fichier .db pour afficher une image avec feh.<br />&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;--autre option à définir par la suite<br />&#160; &#160; &#160;<br />le problème que j&#039;ai c&#039;est pour intégrer la partie option:</p><div class="codebox"><pre><code>sh script --wallpaper /mondossier/images/</code></pre></div><div class="codebox"><pre><code>sh script --database /mondossier/images/images.db</code></pre></div><p>comment je crée ça?</p>]]></description>
			<author><![CDATA[dummy@example.com (wido)]]></author>
			<pubDate>Mon, 22 Feb 2010 14:43:30 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=3295355#p3295355</guid>
		</item>
	</channel>
</rss>
