<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Void And Any &#187; script</title>
	<atom:link href="http://voidandany.free.fr/index.php/tag/script/feed/" rel="self" type="application/rss+xml" />
	<link>http://voidandany.free.fr</link>
	<description>mon bazar...</description>
	<lastBuildDate>Sat, 09 Dec 2017 09:24:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Allumer / éteindre un PC sous Linux à distance (scripts)</title>
		<link>http://voidandany.free.fr/index.php/allumer-eteindre-un-pc-sous-linux-a-distance-scripts/</link>
		<comments>http://voidandany.free.fr/index.php/allumer-eteindre-un-pc-sous-linux-a-distance-scripts/#comments</comments>
		<pubDate>Wed, 08 Jun 2011 09:15:58 +0000</pubDate>
		<dc:creator>voidAndAny</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[Non classé]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://voidandany.free.fr/?p=4057</guid>
		<description><![CDATA[J&#8217;ai déjà indiqué comment allumer/démarrer un PC à distance via le wakeonlan et comment éteindre un PC à distance via ssh. Pour mon usage personnel j&#8217;ai intégré ces commandes dans des scripts afin d&#8217;y ajouter quelques fonctionnalités. Le script de &#8230; <a href="http://voidandany.free.fr/index.php/allumer-eteindre-un-pc-sous-linux-a-distance-scripts/">Continuer la lecture <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/tom-z/4159208974/"><img class="alignleft size-medium wp-image-4097" title="4159208974_0c34f5cd54" src="http://voidandany.free.fr/wp-content/uploads/4159208974_0c34f5cd54-199x300.jpg" alt="" width="199" height="300" /></a>J&#8217;ai déjà indiqué comment <a title="Démarrer un PC via le réseau : Wake on LAN" href="http://voidandany.free.fr/index.php/demarrer-un-pc-via-le-reseau-wake-on-lan/">allumer/démarrer un PC à distance via le wakeonlan</a> et comment <a title="Eteindre un PC à distance depuis linux" href="http://voidandany.free.fr/index.php/eteindre-un-pc-a-distance-depuis-linux/">éteindre un PC à distance</a> via ssh.</p>
<p>Pour mon usage personnel j&#8217;ai intégré ces commandes dans des scripts afin d&#8217;y ajouter quelques fonctionnalités.</p>
<p>Le script de démarrage que j&#8217;ai nommé wakeonlan.sh (original) prend en paramètre l&#8217;adresse MAC et l&#8217;adresse IP de la machine à réveiller et permet de faire n essais de réveil espacés de m secondes avant de rendre la main.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;"># Wake up remote machine</span>
<span style="color: #666666; font-style: italic;"># Usage: $0 mac_adress ip_adress</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Check interval</span>
<span style="color: #007800;">SLEEPTIME</span>=<span style="color: #000000;">60</span>
<span style="color: #666666; font-style: italic;"># Temp directory where to store a file to indicate that the computer was already turn on (used for shutdow)</span>
<span style="color: #007800;">TEMP_DIRECTORY</span>=<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$HOME</span><span style="color: #000000; font-weight: bold;">/</span>tmp
<span style="color: #666666; font-style: italic;"># Number of retries</span>
<span style="color: #007800;">RETRY</span>=<span style="color: #000000;">20</span>
&nbsp;
die <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
 <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">2</span> <span style="color: #ff0000;">&quot;$@&quot;</span>
 <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$#&quot;</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">2</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">||</span> die <span style="color: #ff0000;">&quot;Usage : $0 Mac_adress IP_adress&quot;</span>
<span style="color: #007800;">HOST_MAC</span>=<span style="color: #007800;">$1</span>
<span style="color: #007800;">HOST_IP</span>=<span style="color: #007800;">$2</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-d</span> <span style="color: #007800;">$directory</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">||</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #007800;">$directory</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">ping</span> <span style="color: #660033;">-c</span> <span style="color: #000000;">2</span> <span style="color: #660033;">-w</span> <span style="color: #000000;">15</span> <span style="color: #007800;">$HOST_IP</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
<span style="color: #007800;">RESULT</span>=<span style="color: #007800;">$?</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$RESULT</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
 <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Host <span style="color: #007800;">$HOST_IP</span> is already up - exiting&quot;</span>
 <span style="color: #c20cb9; font-weight: bold;">touch</span> <span style="color: #007800;">$TEMP_DIRECTORY</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$HOST_IP</span>
 <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span>
<span style="color: #000000; font-weight: bold;">else</span>  
 <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Trying to wake up <span style="color: #007800;">$HOST_IP</span>&quot;</span>
 <span style="color: #007800;">TEST_NUMBER</span>=<span style="color: #000000;">0</span>
 <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$RESULT</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">do</span>
  <span style="color: #007800;">TEST_NUMBER</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #007800;">$TEST_NUMBER</span> + <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">`</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Test #<span style="color: #007800;">$TEST_NUMBER</span>)&quot;</span>
  wakeonlan <span style="color: #007800;">$HOST_MAC</span>
  <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #007800;">$SLEEPTIME</span>
  <span style="color: #c20cb9; font-weight: bold;">ping</span> <span style="color: #660033;">-c</span> <span style="color: #000000;">2</span> <span style="color: #660033;">-w</span> <span style="color: #000000;">15</span> <span style="color: #007800;">$HOST_IP</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
  <span style="color: #007800;">RESULT</span>=<span style="color: #007800;">$?</span>
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$RESULT</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$TEST_NUMBER</span> <span style="color: #660033;">-eq</span> <span style="color: #007800;">$RETRY</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
   <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$RETRY</span> retry unsuccessful - leave&quot;</span>
   <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
  <span style="color: #000000; font-weight: bold;">fi</span>
 <span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<p>On pourra remarquer que si la machine est déjà allumé, le script crée un fichier portant son adresse IP, ce fichier est utilisé par le script d&#8217;arrêt.</p>
<p>Pour fonctionner ce script à besoin du paquet wakeonlan.</p>
<p>&nbsp;</p>
<p>Ce dernier nommé shutdown.sh (encore original) n&#8217;arrête l&#8217;ordinateur que si ce dernier n&#8217;était pas déjà allumé avant le wakeonlan (état connu par la présence au non du fichier nommé de l&#8217;adresse IP de la machine à réveiller / éteindre)</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;"># Shutdown a remote machine</span>
<span style="color: #666666; font-style: italic;"># Usage: $0 user ip_adress</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Temp directory where to check a file that indicate if the computer doesn't need to shutdown (file created by wakeonlan script)</span>
<span style="color: #007800;">TEMP_DIRECTORY</span>=<span style="color: #007800;">$HOME</span><span style="color: #000000; font-weight: bold;">/</span>tmp
&nbsp;
die <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
 <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">2</span> <span style="color: #ff0000;">&quot;$@&quot;</span>
 <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$#&quot;</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">2</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">||</span> die <span style="color: #ff0000;">&quot;Usage : $0 user IP_adress&quot;</span>
 <span style="color: #007800;">USER</span>=<span style="color: #007800;">$1</span>
 <span style="color: #007800;">HOST_IP</span>=<span style="color: #007800;">$2</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$TEMP_DIRECTORY</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$HOST_IP</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>  
 <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;The host <span style="color: #007800;">$HOST_IP</span> was already turned on so we don't shutdown it&quot;</span>
 <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #007800;">$TEMP_DIRECTORY</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$HOST_IP</span>
 <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Shuting down <span style="color: #007800;">$HOST_IP</span>&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #007800;">$USER</span><span style="color: #000000; font-weight: bold;">@</span><span style="color: #007800;">$HOST_IP</span> <span style="color: #ff0000;">&quot;sudo shutdown -h now&quot;</span></pre></div></div>

<p>Ce script prend en paramètre l&#8217;adresse IP de la machine à éteindre et l&#8217;utilisateur qui  lancera la commande shutdown via SSH.</p>
<p>La machine cible doit avoir sudo (toujours le cas sur Ubuntu) et la commande shutdown ne doit pas demander de mot de passe (paramétré dans le sudoer)</p>
<p>&nbsp;</p>
<p>Image par <a href="http://www.flickr.com/photos/tom-z/">tom.z</a> sous CC BY-NY-SA<strong id="yui_3_3_0_3_1307447442090976"><br />
 </strong></p>
]]></content:encoded>
			<wfw:commentRss>http://voidandany.free.fr/index.php/allumer-eteindre-un-pc-sous-linux-a-distance-scripts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Logs NGINX et Logrotate</title>
		<link>http://voidandany.free.fr/index.php/logs-nginx-et-logrotate/</link>
		<comments>http://voidandany.free.fr/index.php/logs-nginx-et-logrotate/#comments</comments>
		<pubDate>Tue, 31 May 2011 13:38:56 +0000</pubDate>
		<dc:creator>voidAndAny</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[logrotate]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://voidandany.free.fr/?p=4009</guid>
		<description><![CDATA[J&#8217;ai déjà parlé de NGINX, ce formidable serveur web rapide et surtout léger installé sur mon Dockstar. J&#8217;ai aussi installé logrotate sur mon serveur, outil qui permet de faire tourner et d&#8217;archiver les fichiers de logs Pour que les 2 &#8230; <a href="http://voidandany.free.fr/index.php/logs-nginx-et-logrotate/">Continuer la lecture <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>J&#8217;ai déjà parlé de <a href="http://voidandany.free.fr/index.php/tag/nginx/">NGINX</a>, ce formidable serveur web rapide et surtout léger installé sur mon <a title="Marques-pages : Un mini serveur le Seagate Dockstar" href="http://voidandany.free.fr/index.php/marques-pages-un-mini-serveur-le-seagate-dockstar/">Dockstar</a>.</p>
<p>J&#8217;ai aussi<a href="http://voidandany.free.fr/index.php/configuration-de-base-du-dockstar/"> installé logrotate sur mon serveur</a>, outil qui permet de faire tourner et d&#8217;archiver les fichiers de logs</p>
<p>Pour que les 2 fonctionnent ensemble il  faut ajouter une configuration dans logrotate pour qu&#8217;il prennent en compte NGINX, ce dernier n&#8217;étant pas reconnu  par logrotate lors de son installation.</p>
<p>Il faut donc créer un fichier nginx sous /etc/logrotate.d/ et y coller ceci (à adapter) :</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">/var/log/nginx/*.log {
	#rotate the logfile(s) daily
	daily
	# adds extension like YYYYMMDD instead of simply adding a number
	dateext
	# If log file is missing, go on to next one without issuing an error msg
	missingok
	# Save logfiles for the last 10 days
	rotate 10
	# Old versions of log files are compressed with gzip
	compress
	# Postpone compression of the previous log file to the next rotation cycle
	delaycompress
	# Do not rotate the log if it is empty
	notifempty
	#after logfile is rotated and nginx.pid exists, send the USR1 signal
	postrotate
		[ ! -f /var/run/nginx.pid  ] || kill -USR1 `cat /var/run/nginx.pid`
	endscript
}</pre></div></div>

<p>C&#8217;est la directive postrotate qui est spécifique à NGINX et qui est  importante : une fois les log tournées / archivées on lance un signal  d&#8217;arrêt à NGINX pour qu&#8217;il recrée les fichiers de logs.</p>
<p>On testera la configuration avec la commande :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> logrotate <span style="color: #660033;">-d</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>logrotate.d<span style="color: #000000; font-weight: bold;">/</span>nginx</pre></div></div>

<p>Voila pour le paramétrage de base.</p>
<p>&nbsp;</p>
<p>J&#8217;y ai personnellement ajouté l&#8217;appel à un script de mon crû avant que logrotate ne fasse tourner les logs.</p>
<p>Ce script analyse les logs d&#8217;accès de NGINX et effectue une petite analyse des IPs et des utilisateurs qui se connectent :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">dirname</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${0}</span>&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">log</span>=<span style="color: #7a0874; font-weight: bold;">&#91;</span>nom et chemin <span style="color: #c20cb9; font-weight: bold;">du</span> fichier log<span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">date</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #007800;">$log</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>  <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$log</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/*</span>access.log
<span style="color: #000000; font-weight: bold;">do</span>
     <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${file}</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$log</span>
&nbsp;
     <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Nb accès par IP&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$log</span>
     <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #800000;">${file}</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $1}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">uniq</span> -c  <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$log</span>
     <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-i</span> <span style="color: #ff0000;">'s/\(81..125.231.15$\)/\1 : Travail/'</span> <span style="color: #007800;">$log</span>
     <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-i</span> <span style="color: #ff0000;">'s/\(89.5.45.52$\)/\1 : Maison/'</span>  <span style="color: #007800;">$log</span>
&nbsp;
     <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Nb accès par utilisateur&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$log</span>
     <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #800000;">${file}</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $3}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">uniq</span> <span style="color: #660033;">-c</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$log</span>
&nbsp;
     <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>-------------------------<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$log</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>&nbsp;</p>
<p>qui produit ce genre de rapport :</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">jeudi 14 avril 2011, 13:35:21 (UTC+0200)
&nbsp;
/var/log/nginx/access.log
&nbsp;
Nb accès par IP
1 121.162.199.215
6 192.168.1.100 : Maison
1 208.80.194.29
1 222.187.222.26
&nbsp;
Nb accès par utilisateur
4 -
5 mon_utilisateur
&nbsp;
-------------------------
/var/log/nginx/xxxx.access.log
&nbsp;
Nb accès par IP
250 125.54.42.12
&nbsp;
Nb accès par utilisateur
250 utilisateur2
-------------------------
/var/log/nginx/yyyy.access.log
Nb accès par IP
Nb accès par utilisateur
-------------------------</pre></div></div>

<p>Pour prendre en compte ce script et le faire exécuter j&#8217;ai ajouté les directives suivantes au fichier nginx de logrotate  :</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;"># scripts are runned only once
sharedscripts
&nbsp;
# before rotation log are analyzed
prerotate
    /chemin/statistiques_nginx.sh
endscript</pre></div></div>

<p>Ainsi avant de faire tourner les logs NGINX logrotate exécute une seule fois le script que j&#8217;ai nommé statistiques_nginx.sh. Ce dernier produit un rapport que je m’envoie par email (via un autre script)</p>
<p>&nbsp;</p>
<p>A noter qu&#8217;il existe des solutions clé en main et beaucoup plus  évoluées, complètes d&#8217;analyse et de statistiques pour les logs des  serveurs Web (voir dans les sources), mais cela me semble un peu trop  pour mon usage.</p>
<p>&nbsp;</p>
<p><em><strong>Sources : </strong></em></p>
<p>Logrotate :</p>
<ul>
<li><a href="http://serverfault.com/questions/248096/nginx-logrotate-config">nginx logrotate config</a></li>
<li><a href="https://wincent.com/wiki/nginx_log_rotation">nginx log rotation</a></li>
<li><a href="http://ahabdo.wordpress.com/2010/10/16/how-to-configure-logrotate-nginx-log-in-freebsd-and-linux-machine/">How To Configure Logrotate Nginx Log in FreeBSD and Linux Machine.</a></li>
</ul>
<p>Autres solutions de rotation des logs :</p>
<ul>
<li><a href="http://serverfault.com/questions/65118/proper-way-to-rotate-nginx-logs">Proper way to rotate Nginx logs</a></li>
<li><a href="http://pjkh.com/articles/2007/03/15/nginx-and-cronolog/">Nginx and Cronolog</a></li>
</ul>
<p>Script analyse des logs :</p>
<ul>
<li><a href="http://fak3r.com/geek/howto-sort-web-server-logs-to-find-top-users/">HOWTO sort web-server logs to find top users</a></li>
<li><a href="http://bash.cyberciti.biz/web-server/find-top-ipaddress-hitting-webserver/">Shell Script List All Top IP Address Accessing Apache / Lighttpd</a></li>
</ul>
<p>Analyse des logs plus évoluées :</p>
<ul>
<li><a title="Permanent Link to Analysis access logs of Nginx by awstats" rel="bookmark" href="http://www.goitworld.com/analysis-access-logs-of-nginx-by-awstats/">Analysis access logs of Nginx by awstats</a></li>
<li><a title="Permanent Link to nginx log rotation and analysis with webalizer" rel="bookmark" href="http://www.edoxy.net/weblog/2009/08/nginx-log-rotation-and-analysis-with-webalizer/">nginx log rotation and analysis with webalizer</a></li>
<li><a href="http://www.w3perl.com/">w3perl</a></li>
<li><a href="http://awstats.sourceforge.net/">awstats</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://voidandany.free.fr/index.php/logs-nginx-et-logrotate/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Utiliser des listes de blocage personnalisées (blocklist) avec le démon Transmission</title>
		<link>http://voidandany.free.fr/index.php/utiliser-des-listes-de-blocage-personnalisees-blocklist-avec-le-demon-transmission/</link>
		<comments>http://voidandany.free.fr/index.php/utiliser-des-listes-de-blocage-personnalisees-blocklist-avec-le-demon-transmission/#comments</comments>
		<pubDate>Thu, 26 May 2011 13:04:02 +0000</pubDate>
		<dc:creator>voidAndAny</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[torrent]]></category>
		<category><![CDATA[Transmission]]></category>

		<guid isPermaLink="false">http://voidandany.free.fr/?p=4038</guid>
		<description><![CDATA[Une blocklist est une liste d&#8217;adresse IP dans un format pré-défini pouvant être utilisée par divers logiciels (notamment les clients torrents) pour bloquer l&#8217;accès du dit logiciel aux utilisateurs des ces IPs (= liste noire d&#8217;adresses IP). Transmission supporte évidemment &#8230; <a href="http://voidandany.free.fr/index.php/utiliser-des-listes-de-blocage-personnalisees-blocklist-avec-le-demon-transmission/">Continuer la lecture <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/louect/4796593945/"><img class="alignleft size-full wp-image-4039" title="4796593945_03585924eb" src="http://voidandany.free.fr/wp-content/uploads/4796593945_03585924eb.jpg" alt="" width="263" height="350" /></a>Une <strong>blocklist </strong>est une liste d&#8217;adresse IP dans un format pré-défini pouvant être utilisée par divers logiciels (notamment les clients torrents) pour bloquer l&#8217;accès du dit logiciel aux utilisateurs des ces IPs (<strong>= liste noire d&#8217;adresses IP</strong>).</p>
<p>Transmission supporte évidemment les blocklists, mais la liste utilisée n&#8217;est pas paramétrable, Transmission télécharge une liste de niveau 1 sur son <a href="http://update.transmissionbt.com/level1.gz">URL mirroir</a></p>
<p>De plus la mise à jour de la liste n&#8217;est pas automatique. Sur le client lourd (transmission GTK) il existe un bouton permettant de mettre à jour la liste, mais évidemment sur le démon il n&#8217;ya pas de bouton.</p>
<p>Nous allons donc voir comment dans un premier temps <strong>mettre à jour la liste lorsque l&#8217;on utilise le démon</strong> puis ensuite comment<strong> utiliser des listes personnalisées </strong>et les mettre à jour automatiquement&#8230;</p>
<p>Dans les 2 cas il faut que le paramètre blocklist-enabled soit positionné à true dans votre fichier settings.json</p>
<p>&nbsp;</p>
<p>Pour mettre à jour la liste de blocage Transmission lorsqu&#8217;on utilise le démon il faut passer par le commande transmission-remote du paquet transmission-cli :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /bin/sh</span>
<span style="color: #007800;">username</span>=<span style="color: #ff0000;">'username'</span>
<span style="color: #007800;">password</span>=<span style="color: #ff0000;">'password'</span>
transmission-remote <span style="color: #660033;">--auth</span> <span style="color: #007800;">$username</span>:<span style="color: #007800;">$password</span> <span style="color: #660033;">--blocklist-update</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>transmission-daemon restart</pre></div></div>

<p>A la fin on re-démarre le démon pour qu&#8217;il prenne ne compte la nouvelle liste, si comme moi vous utilisez sudo et que vous exécutez ce script avec votre utilisateur il faudra autoriser la commande de re-démarrage dans votre sudoer (voir en fin de éème solution)</p>
<p>Il suffira alors de mettre ce script dans une tache cron et le tour est joué&#8230;</p>
<p><strong>Rque :</strong> comme ce script contient les login et mot de passe en clair de transmission RPC il conviendra de restreindre ses droits d&#8217;accès (chmod 700 script.sh)</p>
<p>&nbsp;</p>
<p>Je n&#8217;ai pas testé ce script puisque j&#8217;utilise la deuxième solution qui consiste à gérer la <strong>mise à jour et l&#8217;origine de la liste</strong> de blocage :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;"># Télécharge des blockslist à partir de http://iblocklist.com/lists.php</span>
<span style="color: #666666; font-style: italic;"># et les intégre dans le répertoire de Transmission</span>
<span style="color: #666666; font-style: italic;"># répertoire de travail</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># répertoire de travail / temporaire</span>
<span style="color: #007800;">travail</span>=<span style="color: #007800;">$HOME</span><span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>blocklists
<span style="color: #666666; font-style: italic;"># réperoire où Transmission stock les fichiers blocklist</span>
<span style="color: #007800;">transmissionBlocklist</span>=<span style="color: #007800;">$HOME</span><span style="color: #000000; font-weight: bold;">/</span>.config<span style="color: #000000; font-weight: bold;">/</span>transmission-daemon<span style="color: #000000; font-weight: bold;">/</span>blocklists
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;******** Compilation d'une Bloclist pour Transmissionbt ***********&quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-e</span> <span style="color: #007800;">$travail</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;Répertoire de travail <span style="color: #007800;">$travail</span> &quot;</span>
<span style="color: #000000; font-weight: bold;">else</span>
    <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #007800;">$travail</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #007800;">$travail</span><span style="color: #000000; font-weight: bold;">/*</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#récupération des fichiers http://iblocklist.com/lists.php</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>********* Téléchargements des listes de blocage *******************&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>list.iblocklist.com<span style="color: #000000; font-weight: bold;">/</span>?<span style="color: #007800;">list</span>=bt_level1 <span style="color: #660033;">-O</span> <span style="color: #007800;">$travail</span><span style="color: #000000; font-weight: bold;">/</span>bt_level1.gz
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>list.iblocklist.com<span style="color: #000000; font-weight: bold;">/</span>?<span style="color: #007800;">list</span>=bt_level2 <span style="color: #660033;">-O</span> <span style="color: #007800;">$travail</span><span style="color: #000000; font-weight: bold;">/</span>bt_level2.gz
&nbsp;
<span style="color: #666666; font-style: italic;">#décompression</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>********* Décompression des listes téléchargées *******************&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">gunzip</span> <span style="color: #660033;">-v</span> <span style="color: #007800;">$travail</span><span style="color: #000000; font-weight: bold;">/*</span>.gz
&nbsp;
<span style="color: #666666; font-style: italic;">#concaténer les fichiers</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>********* Création d'une seule liste sans redondance des données **&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;traitement en cours ...Patientez SVP...&quot;</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #007800;">$travail</span>
<span style="color: #007800;">list1</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">ls</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #660033;">-u</span> <span style="color: #007800;">$list1</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> blocklist <span style="color: #000000; font-weight: bold;">&amp;&amp;</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> -
&nbsp;
<span style="color: #666666; font-style: italic;">#Déplacement du fichier blocklist dans le répertoire de Transmission</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>********* Déplacement de la Blocklist *****************************&quot;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-d</span> <span style="color: #007800;">$transmissionBlocklist</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> ;<span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;Copie de sauvegarde de l'ancien fichier&quot;</span>
    <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$transmissionBlocklist</span><span style="color: #000000; font-weight: bold;">/</span>blocklist <span style="color: #007800;">$travail</span><span style="color: #000000; font-weight: bold;">/</span>blocklist.bak
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;Déplacement du nouveau fichier dans le répertoire de Transmission&quot;</span>
    <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$travail</span><span style="color: #000000; font-weight: bold;">/</span>blocklist <span style="color: #007800;">$transmissionBlocklist</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Rechargement de Transmission</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;Rechargement de la configuration de Transmission&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>transmission-deamon reload
<span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #007800;">$transmissionBlocklist</span><span style="color: #000000; font-weight: bold;">/</span>blocklist <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>*********** Opération terminée ************************************&quot;</span>
<span style="color: #000000; font-weight: bold;">else</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span> *** KO **** !! Le fichier bloklist est vide !! *** KO *** &quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<p>Le script télécharge les listes voulues (ici les niveaux 1 et 2), les dézippe et les concatène en excluant les doublons, la liste résultante est ensuite copié dans le répertoire utilisé par Transmission et le démon est rechargé.</p>
<p>Comme indiqué précédemment pour que la commande de rechargement du démon puisse être exécuté via sudo sans demande de mot de passe il faut modifier le sudoer ce qui se fait en lançant la commande</p>
<p>&nbsp;</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> visudo</pre></div></div>

<p>&nbsp;</p>
<p>Et en ajoutant une ligne du type :</p>
<p>&nbsp;</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">mon_utilisateur ALL= NOPASSWD: /etc/init.d/transmission-daemon</pre></div></div>

<p>&nbsp;</p>
<p>De même que pour la première solution on mettra ce script dans une tache cron (à la semaine par exemple)</p>
<p>&nbsp;</p>
<p>Pour finir quelques mots sur les listes de blocage.</p>
<p>Transmission supporte les formats P2P Plaintext (Nom:IP_Début:IP_Fin) et DAT (format binaire non éditable)</p>
<p>On pourra trouver des listes de blocage P2P sur les sites suivants :</p>
<ul>
<li><a href="http://tbg.iblocklist.com/">http://tbg.iblocklist.com/</a></li>
<li> <a href="http://iblocklist.com/lists.php">http://iblocklist.com/</a></li>
</ul>
<p>On recommande la liste de iblocklist de <a href="http://www.iblocklist.com/list.php?list=bt_level1">niveau 1</a> (IP impliqués dans la lutte contre le piratage)  en général et la liste de <a href="http://www.iblocklist.com/list.php?list=bt_level2">niveau 2 </a>(IP des sociétés en général, des laboratoires et proxy) éventuellement.</p>
<p>&nbsp;</p>
<p><em>Edit : </em>31/05/2011 : correction la variable d&#8217;environnement $USER n&#8217;est pas connu dans CRON, utilisation de $HOME à la place (mieux en plus)</p>
<p><span style="text-decoration: underline;"><em><strong>Sources : </strong></em></span></p>
<ul>
<li><a href="http://papillon-butineur.blogspot.com/2010/08/blocklists-avec-transmissionrecopie.html">Papillon-butineur: Blocklists avec Transmission</a> : source du script initial que j&#8217;ai modifié</li>
<li><a href="https://trac.transmissionbt.com/wiki/Blocklists">Blocklists – Transmission</a> : documentation officielle sur les blocklist</li>
<li><a href="https://trac.transmissionbt.com/wiki/Scripts/BlockListUpdater">Scripts/BlockListUpdater – Transmission</a> : script de mise à jour des blocklist (beaucoup moins évolué que celui de papillon-butineur)</li>
<li><a href="http://blog.shvetsov.com/2010/09/automatically-update-transmission-block.html">Random Stuff: Automatically update Transmission&#8217;s block list </a>: Script moins complet</li>
<li><a href="https://forum.transmissionbt.com/viewtopic.php?f=2&amp;t=9790&amp;sid=669acbc24cad9feef9355797fbf358fc">transmission-remote and blocklist-update</a> : script pour mettre à jour la blocklist</li>
</ul>
<p>Image par <a href="http://www.flickr.com/photos/louect/">Lou Ect</a> sous CC BY-NC-ND<strong><br />
 </strong></p>
]]></content:encoded>
			<wfw:commentRss>http://voidandany.free.fr/index.php/utiliser-des-listes-de-blocage-personnalisees-blocklist-avec-le-demon-transmission/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Installer de façon automatique une liste de package et les dépôts associés</title>
		<link>http://voidandany.free.fr/index.php/installer-de-facon-automatique-une-liste-de-package-et-les-depots-associes/</link>
		<comments>http://voidandany.free.fr/index.php/installer-de-facon-automatique-une-liste-de-package-et-les-depots-associes/#comments</comments>
		<pubDate>Tue, 11 May 2010 12:06:21 +0000</pubDate>
		<dc:creator>voidAndAny</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[desktop]]></category>
		<category><![CDATA[installation]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://voidandany.free.fr/?p=2140</guid>
		<description><![CDATA[Dans le cadre de la sortie de Lucid Lynx (Ubuntu 10.04), je vais (oui je sais je suis en retard) ré-installer complétement mon système, puisqu&#8217;à cette occasion je change complétement mon PC. Il va donc me falloir retrouver/lister toutes les &#8230; <a href="http://voidandany.free.fr/index.php/installer-de-facon-automatique-une-liste-de-package-et-les-depots-associes/">Continuer la lecture <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/luvi/3963847696/in/set-72157604048061288/"><img class="alignleft size-medium wp-image-2141" style="margin-left: 10px; margin-right: 10px;" title="lynx_3963847696_2f6feed69e" src="http://voidandany.free.fr/wp-content/uploads/lynx_3963847696_2f6feed69e-300x200.jpg" alt="" width="300" height="200" /></a></p>
<p>Dans le cadre de la sortie de Lucid Lynx (Ubuntu 10.04), je vais (oui je sais je suis en retard) <span style="font-weight: bold;">ré-installer complétement</span> mon système, puisqu&#8217;à cette occasion je change complétement mon PC.</p>
<p><br class="spacer_" /></p>
<p>Il va donc me falloir retrouver/lister toutes les applications que j&#8217;utilise et les ré-installer toutes.</p>
<p><br class="spacer_" /></p>
<p>Pour le premier point, lister les applications utilisé, je peux me baser sur un fichier que je maintiens depuis que je suis sur Ubuntu (avec plus ou moins d&#8217;assiduité).</p>
<p><br class="spacer_" /></p>
<p>Pour le deuxième point (ré-installation), il y a peu de temps je suis tombé sur cet article <a rel="bookmark" href="http://silverwav.wordpress.com/2010/03/18/a-cleanstart-for-your-new-ubuntu-install-packages-from-a-list/">A Cleanstart for your new Ubuntu (Install Packages  from a list)</a> qui met a disposition un<span style="font-weight: bold;"> script bash</span> pour ré-<span style="font-weight: bold;">installer </span>complétement un PC à partir d&#8217;un fichier contenant une<span style="font-weight: bold;"> liste de package</span>.</p>
<p><br class="spacer_" /></p>
<p>Donc en mettant en forme mon fichier listant les applications utilisées avec le script réalisé par SilverWav, je peux gagner pas mal de temps.</p>
<p>Mais je n&#8217;étais pas complétement satisfait du script, ce dernier nécessite que tous les dépôts nécessaires soit préalablement configurés, or pour moi c&#8217;est 1 seul et même opération que d&#8217;ajouter le dépôt et d&#8217;installer les packages correspondant.</p>
<p>J&#8217;ai donc modifié le script d&#8217;installation et le format du fichier de configuration.</p>
<p><br class="spacer_" /></p>
<h2>Fichier de configuration</h2>
<p>Voici un exemple de fichier de configuration :</p>
<p><br class="spacer_" /></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># ********************** Accessoires ******************************</span>
&nbsp;
parcellite <span style="color: #666666; font-style: italic;"># gestion du presse-papier</span>
&nbsp;
ppa:shutter<span style="color: #000000; font-weight: bold;">/</span>ppa
shutter <span style="color: #666666; font-style: italic;"># logiciel de capture d'écran évolué</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># ********************** Autres ******************************</span>
&nbsp;
deb http:<span style="color: #000000; font-weight: bold;">//</span>www-personal.umich.edu<span style="color: #000000; font-weight: bold;">/</span>~tjwatt<span style="color: #000000; font-weight: bold;">/</span>suldr<span style="color: #000000; font-weight: bold;">/</span> debian extra <span style="color: #000000; font-weight: bold;">&gt;</span> samsungCLX3175_driver.list
http:<span style="color: #000000; font-weight: bold;">//</span>www-personal.umich.edu<span style="color: #000000; font-weight: bold;">/</span>~tjwatt<span style="color: #000000; font-weight: bold;">/</span>suldr<span style="color: #000000; font-weight: bold;">/</span>suldr.gpg
samsungmfp-configurator-data samsungmfp-configurator-qt4 samsungmfp-driver samsungmfp-data samsungmfp-scanner <span style="color: #666666; font-style: italic;"># driver imprimante Samsung CLX 3175</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># ********************** Bureautique ******************************</span>
&nbsp;
ppa:claydoh<span style="color: #000000; font-weight: bold;">/</span>ppa
kmymoney2 <span style="color: #666666; font-style: italic;"># gestion des finances personnels</span>
&nbsp;
gcstar <span style="color: #666666; font-style: italic;"># gestionnaire de collections (livres)</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># ********************** Education ******************************</span>
&nbsp;
gcompris tuxpaint <span style="color: #666666; font-style: italic;"># gcompris + logiciel de dessin matriciel pour les enfants</span>
&nbsp;
childsplay childsplay-alphabet-sounds-fr <span style="color: #666666; font-style: italic;"># Childsplay + langue française</span>
&nbsp;
pysycache pysycache-buttons-beerabbit pysycache-buttons-crapaud pysycache-buttons-wolf pysycache-click-sea pysycache-dblclick-butterfly pysycache-move-animals pysycache-move-food pysycache-move-plants pysycache-move-sky pysycache-move-sports pysycache-puzzle-cartoons pysycache-puzzle-photos <span style="color: #666666; font-style: italic;"># Psycache + extensions</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># ********************** Graphisme ******************************</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">gimp</span> gimp-help-fr <span style="color: #666666; font-style: italic;"># retouche d'image matriciels</span>
&nbsp;
inkscape <span style="color: #666666; font-style: italic;"># logiciel de dessin vectoriel</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Logiciels Photo</span>
ppa:dlynch3<span style="color: #000000; font-weight: bold;">/</span>ppa
rapid-photo-downloader <span style="color: #666666; font-style: italic;"># Copie et renommage de photos depuis un appareil photo numérique</span>
&nbsp;
deb http:<span style="color: #000000; font-weight: bold;">//</span>jbrout.free.fr<span style="color: #000000; font-weight: bold;">/</span>download<span style="color: #000000; font-weight: bold;">/</span>debian binary<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">&gt;</span> jbrout.list
jbrout <span style="color: #666666; font-style: italic;"># tagging des photos</span>
&nbsp;
ppa:damien-moore<span style="color: #000000; font-weight: bold;">/</span>ppa
phraymd <span style="color: #666666; font-style: italic;"># tagging des photos</span>
&nbsp;
hugin <span style="color: #666666; font-style: italic;"># assemblage de photos en panorama</span>
&nbsp;
<span style="color: #660033;">-f-spot</span> <span style="color: #666666; font-style: italic;"># suppression de f-spot (mono+lourd)</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># ********************** Internet ******************************</span>
&nbsp;
ppa:deluge-team<span style="color: #000000; font-weight: bold;">/</span>ppa
deluge-common deluge-gtk <span style="color: #666666; font-style: italic;"># IHM GTK du client torrent deluge</span>
&nbsp;
<span style="color: #660033;">-transmission-common</span> transmission-gtk <span style="color: #666666; font-style: italic;"># suppression de transmission client torrent installé par défaut dans Gnome</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Nouveautés : DAILY &gt; BETA &gt; DEV &gt; STABLE (n'existe pas sous Linux)</span>
<span style="color: #666666; font-style: italic;">#ppa:chromium-daily/ppa</span>
<span style="color: #666666; font-style: italic;">#ppa:chromium-daily/beta</span>
ppa:chromium-daily<span style="color: #000000; font-weight: bold;">/</span>dev
chromium-browser <span style="color: #666666; font-style: italic;"># navigateur web</span>
&nbsp;
pidgin <span style="color: #666666; font-style: italic;"># messagerie instantannée</span>
&nbsp;
<span style="color: #660033;">-empathy</span> empathy-common nautilus-sendto-empathy <span style="color: #666666; font-style: italic;"># suppression d'empathy loiciel de messagerie instantannée installé par défaut dans Gnome et de son intégration dans Nautilus</span>
&nbsp;
thunderbird thunderbird-locale-fr thunderbird-gnome-support <span style="color: #666666; font-style: italic;"># client email</span>
&nbsp;
deb http:<span style="color: #000000; font-weight: bold;">//</span>linux.dropbox.com<span style="color: #000000; font-weight: bold;">/</span>ubuntu lucid main <span style="color: #000000; font-weight: bold;">&gt;</span> dropbox.list
key:FC918B335044912E
nautilus-dropbox <span style="color: #666666; font-style: italic;"># stockage on-line et synchronisation de fichiers</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># ********************** Jeux ******************************</span>
&nbsp;
frozen-bubble <span style="color: #666666; font-style: italic;"># jeux où il faut exploser des boules en en associant 3 par couleur</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># ********************** Outils sytèmes ******************************</span>
&nbsp;
htop <span style="color: #666666; font-style: italic;"># monitoring mémoire / cpu ...</span>
&nbsp;
language-pack-fr language-pack-gnome-fr <span style="color: #666666; font-style: italic;"># pack de langue pour completement franciser Ubuntu</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># ********************** Son et Vidéo ******************************</span>
&nbsp;
deb http:<span style="color: #000000; font-weight: bold;">//</span>packages.medibuntu.org<span style="color: #000000; font-weight: bold;">/</span> lucid <span style="color: #c20cb9; font-weight: bold;">free</span> non-free <span style="color: #000000; font-weight: bold;">&gt;</span> medibuntu.list
key:0C5A2783
non-free-codecs <span style="color: #666666; font-style: italic;"># codecs audio-vidéo non libres</span>
&nbsp;
asunder <span style="color: #666666; font-style: italic;"># ripp des CDs</span>
&nbsp;
ppa:handbrake-ubuntu<span style="color: #000000; font-weight: bold;">/</span>ppa
handbrake-gtk <span style="color: #666666; font-style: italic;"># ripp des DVDs</span>
&nbsp;
ppa:c-korn<span style="color: #000000; font-weight: bold;">/</span>ppa
vlc <span style="color: #666666; font-style: italic;"># lecteur multimédia (audio/vidéo)</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># ********************** Outils (non desktop) ******************************</span>
&nbsp;
autofs <span style="color: #666666; font-style: italic;"># montage automatique de système de fichier distant</span>
&nbsp;
nfs-common <span style="color: #666666; font-style: italic;"># client NFS</span>
&nbsp;
deb http:<span style="color: #000000; font-weight: bold;">//</span>archive.canonical.com<span style="color: #000000; font-weight: bold;">/</span>ubuntu lucid partner <span style="color: #000000; font-weight: bold;">&gt;</span> partner.list
sun-java6-jre <span style="color: #666666; font-style: italic;"># framework Java</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #666666; font-style: italic;"># editeur VI amélioré</span></pre></div></div>

<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p>Le fichier de configuration accepte 7 formats de lignes différentes,  correspondant chacune à différentes opérations d&#8217;installation.</p>
<p><br class="spacer_" /></p>
<h3>Commentaires</h3>
<p>Toutes les lignes commençant par un <span style="font-weight: bold;">#</span> sont considérées comme des commentaires</p>
<p><br class="spacer_" /></p>
<h3>Ajout d&#8217;un dépôt PPA</h3>
<p>Toutes les lignes du fichier de configuration commençant par &laquo;&nbsp;<span style="font-weight: bold;">ppa:</span>&nbsp;&raquo; sont considérées comme l&#8217;adresse d&#8217;un dépôt PPA et sera ajouté au système par la commande :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">add-apt-repository ppa:<span style="color: #7a0874; font-weight: bold;">&#91;</span>nom <span style="color: #c20cb9; font-weight: bold;">du</span> ppa<span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>

<p><br class="spacer_" /></p>
<p>Les PPA (Personnal Package Archives) sont des dépôts mis à disposition de tout à chacun sur le site Launchpad, c&#8217;est à dire par Canonical.</p>
<p><br class="spacer_" /></p>
<h3>Ajout d&#8217;un dépôt tierce (non PPA)</h3>
<p>Toutes les ligne du fichier de configuration commençant par &laquo;&nbsp;<span style="font-weight: bold;">deb http:</span>&nbsp;&raquo; sont considérées comme l&#8217;adresse d&#8217;un dépôt APT.</p>
<p>Ce genre de ligne doit en plus respecter la syntaxe suivante :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">deb http:<span style="color: #000000; font-weight: bold;">//</span>url.serveur <span style="color: #7a0874; font-weight: bold;">&#91;</span>branche<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>sections<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>fichier<span style="color: #7a0874; font-weight: bold;">&#93;</span>.list</pre></div></div>

<p><br class="spacer_" /></p>
<p>C&#8217;est à dire l&#8217;adresse du dépôt complet (ou ligne apt) suivi de &laquo;&nbsp;&gt;&nbsp;&raquo; et d&#8217;un nom de fichier portant l&#8217;extension .list.</p>
<p>Le programme d&#8217;installation ajoute alors l&#8217;adresse du dépôt dans le fichier spécifié dans le répertoire /etc/apt/sources.list.d où les programmes apt (apt-get/aptitude) vont chercher la liste des dépôt lors d&#8217;un update.</p>
<p><br class="spacer_" /></p>
<h3>Ajout d&#8217;une clé GPG</h3>
<p>Deux façon de faire :</p>
<ul>
<li>Commencer la ligne par le mot-clé &laquo;&nbsp;<span style="font-weight: bold;">key:</span>&nbsp;&raquo; suivi de l&#8217;identifiant de la clé (cf.<a title="Ajouter la clé publique d’un dépôt (PPA)" rel="bookmark" href="../index.php/ajouter-une-cle/">Ajouter  la clé publique d’un dépôt (PPA)</a>)</li>
<li>Donner l&#8217;url d&#8217;un fichier gpg, la ligne doit donc commencer par &laquo;&nbsp;<span style="font-weight: bold;">http:</span>&laquo;&nbsp;, finir par &laquo;&nbsp;<span style="font-weight: bold;">.gpg</span>&nbsp;&raquo; et être une URL valide</li>
</ul>
<p><br class="spacer_" /></p>
<h3>Suppression d&#8217;un package / logiciel</h3>
<p>Toutes les lignes commençant par &laquo;&nbsp;<span style="font-weight: bold;">-</span>&nbsp;&raquo; seront considérées comme une liste de nom de package que l&#8217;on veut supprimer du système</p>
<p><br class="spacer_" /></p>
<h3>Installation d&#8217;un package / logiciel</h3>
<p>Toutes les autres ligne du fichier seront considérés comme une liste de nom de package à installer.</p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<h2>Script d&#8217;installation</h2>
<p>Voici le script capable de prendre en charge le fichier de configuration et de réaliser les installation paramétrées.</p>
<p>Je ne suis pas un expert en programmation bash, il y a donc de fortes chance pour que l&#8217;on puisse améliorer le code, je suis preneur de toutes remarques et contributions.</p>
<p><br class="spacer_" /></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;">################################################################################</span>
<span style="color: #666666; font-style: italic;"># Ubuntu (&gt; 9.10) post installation script</span>
<span style="color: #666666; font-style: italic;"># by VoidAndAny</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># based on cleanstart-packages.list.sh by silverwav - OpenPGP key:03187548 15 Apr 2009</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># this script read a config file and :</span>
<span style="color: #666666; font-style: italic;">#     add PPA with add-apt-repository</span>
<span style="color: #666666; font-style: italic;">#    add other repositories (not PPA) by writing them in a .list file in /etc/apt/source.list.d</span>
<span style="color: #666666; font-style: italic;">#    add GPG keys</span>
<span style="color: #666666; font-style: italic;">#     install package using aptitude install</span>
<span style="color: #666666; font-style: italic;">#     remove pacakge using aptitude remove</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">################################################################################</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Usage:</span>
<span style="color: #666666; font-style: italic;"># installation.sh</span>
<span style="color: #666666; font-style: italic;"># (reads a file called packages.list by default).</span>
<span style="color: #666666; font-style: italic;"># or</span>
<span style="color: #666666; font-style: italic;"># installation.sh &lt;filename&gt;</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Any line starting with a # is ignored as are Blank lines.</span>
<span style="color: #666666; font-style: italic;"># Line beginning by &quot;ppa:&quot; followed by a are used to add PPA repository</span>
<span style="color: #666666; font-style: italic;"># Line beginning by &quot;deb http&quot;, containing &quot;&gt;&quot; followed by a file name with &quot;.list&quot; extension are used to add repository in /etc/apt/sources.list.d/</span>
<span style="color: #666666; font-style: italic;"># Line beginning by &quot;key:&quot; followed by a key id are used to add GPG key from keyserver.ubuntu.com</span>
<span style="color: #666666; font-style: italic;"># Line beginning by &quot;http:&quot;, ending by &quot;.gpg&quot; are used to download and add GPG key froman URL</span>
<span style="color: #666666; font-style: italic;"># Other lines are package list</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">################################################################################</span>
<span style="color: #c20cb9; font-weight: bold;">clear</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;--------------------------------------------------------------------------------&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;                 (cleanstart) Script for installing packages (client)                 &quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;--------------------------------------------------------------------------------&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># ensure script is run as root/sudo</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$(id -u)</span>&quot;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
 <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
 <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Must execute the script as root user.&quot;</span>
 <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;--------------------------------------------------------------------------------&quot;</span>
 <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># check the argument count</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$#</span> <span style="color: #660033;">-gt</span> <span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
 <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
 <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Only one file with package names allowed.&quot;</span>
 <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;--------------------------------------------------------------------------------&quot;</span>
 <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;">################################################################################</span>
<span style="color: #666666; font-style: italic;">#### Main</span>
<span style="color: #666666; font-style: italic;">#### args: (1)</span>
<span style="color: #666666; font-style: italic;">#### 1. [out] List of input package names</span>
<span style="color: #666666; font-style: italic;">################################################################################</span>
&nbsp;
<span style="color: #007800;">CONFIG_FILE</span>=<span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #666666; font-style: italic;"># package names to be installed</span>
<span style="color: #007800;">PACKAGE_NAME_LIST</span>=<span style="color: #ff0000;">&quot;&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># check if filename was supplied as comand line parameter</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$#</span> <span style="color: #660033;">-eq</span> <span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
 <span style="color: #007800;">CONFIG_FILE</span>=<span style="color: #007800;">$1</span>
<span style="color: #000000; font-weight: bold;">else</span>
 <span style="color: #007800;">CONFIG_FILE</span>=packages.list
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #007800;">PACKAGE_NAME_LIST</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #007800;">$CONFIG_FILE</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> <span style="color: #660033;">-E</span> <span style="color: #ff0000;">&quot;(^#)|(^ppa:)|(^deb http)|(^-)|(^key:)|(^http:.*\.gpg)&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span><span style="color: #ff0000;">'#'</span> <span style="color: #ff0000;">'{ print $1}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">REMOVE_PACKAGE_LIST</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #007800;">$CONFIG_FILE</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-E</span> <span style="color: #ff0000;">&quot;^-&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span><span style="color: #ff0000;">'#'</span> <span style="color: #ff0000;">'{ print $1}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/^-//g'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">PPA_NAME_LIST</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #007800;">$CONFIG_FILE</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-E</span> <span style="color: #ff0000;">&quot;^ppa:&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span><span style="color: #ff0000;">'#'</span> <span style="color: #ff0000;">'{ print $1}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">REPOSITORY_KEY_LIST</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #007800;">$CONFIG_FILE</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-E</span> <span style="color: #ff0000;">&quot;^key:&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span><span style="color: #ff0000;">'#'</span> <span style="color: #ff0000;">'{ print $1}'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/^key://g'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">GPG_URL_LIST</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #007800;">$CONFIG_FILE</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-E</span> <span style="color: #ff0000;">&quot;^http:.*\.gpg&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span><span style="color: #ff0000;">'#'</span> <span style="color: #ff0000;">'{ print $1}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Installing PPA:&quot;</span> <span style="color: #800000;">${PPA_NAME_LIST}</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;--------------------------------------------------------------------------------&quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span>  <span style="color: #007800;">$PPA_NAME_LIST</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">do</span>
 add-apt-repository <span style="color: #007800;">$i</span>;
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Installing other repositories (not PPA) &quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;--------------------------------------------------------------------------------&quot;</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #007800;">$CONFIG_FILE</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-E</span> <span style="color: #ff0000;">&quot;^deb http:.*&gt;.*\.list&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span><span style="color: #ff0000;">'&gt;'</span> <span style="color: #ff0000;">'{gsub(/[[:space:]]*/,&quot;&quot;,$2) ; print $1 &gt; &quot;/etc/apt/sources.list.d/&quot;$2 }'</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Adding GPG key of other repositories (not PPA) &quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;--------------------------------------------------------------------------------&quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$REPOSITORY_KEY_LIST</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">do</span>
 <span style="color: #c20cb9; font-weight: bold;">apt-key</span> adv <span style="color: #660033;">--keyserver</span> keyserver.ubuntu.com <span style="color: #660033;">--recv-key</span> <span style="color: #007800;">$i</span>;
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$GPG_URL_LIST</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">do</span>
 <span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #660033;">-O</span> - <span style="color: #007800;">$i</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-key</span> add - ;
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Updating... &quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;--------------------------------------------------------------------------------&quot;</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">aptitude</span> update
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Installing packages:&quot;</span> <span style="color: #800000;">${PACKAGE_NAME_LIST}</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;--------------------------------------------------------------------------------&quot;</span>
<span style="color: #666666; font-style: italic;"># ajouter le -y</span>
<span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #800000;">${PACKAGE_NAME_LIST}</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Uninstalling packages:&quot;</span> <span style="color: #800000;">${REMOVE_PACKAGE_LIST}</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;--------------------------------------------------------------------------------&quot;</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">aptitude</span> remove <span style="color: #800000;">${REMOVE_PACKAGE_LIST}</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Done&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;--------------------------------------------------------------------------------&quot;</span></pre></div></div>

<p><br class="spacer_" /></p>
<h2>Utilisation</h2>
<p>Pour utiliser ce script, il suffit de la lancer avec sudo en lui passant en paramètre le nom du fichier de configuration</p>
<p><br class="spacer_" /></p>
<p style="font-weight: bold; font-style: italic; text-decoration: underline;">Sources :</p>
<p id="post-364"><a rel="bookmark" href="http://silverwav.wordpress.com/2010/03/18/a-cleanstart-for-your-new-ubuntu-install-packages-from-a-list/">A Cleanstart for your new Ubuntu (Install Packages  from a list)</a></p>
<p>Image par <a title="Lien vers la  galerie de photos de luvi" rel="dc:creator cc:attributionURL" href="http://www.flickr.com/photos/luvi/"><strong>luvi</strong></a> sous CC BY-NC-ND</p>
]]></content:encoded>
			<wfw:commentRss>http://voidandany.free.fr/index.php/installer-de-facon-automatique-une-liste-de-package-et-les-depots-associes/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Faire la redirection d&#8217;une commande exécutée avec sudo</title>
		<link>http://voidandany.free.fr/index.php/faire-la-redirection-dune-commande-executee-avec-sudo/</link>
		<comments>http://voidandany.free.fr/index.php/faire-la-redirection-dune-commande-executee-avec-sudo/#comments</comments>
		<pubDate>Sun, 13 Sep 2009 14:47:41 +0000</pubDate>
		<dc:creator>voidAndAny</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[sudo]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://voidandany.free.fr/?p=1061</guid>
		<description><![CDATA[Admettons que l&#8217;on veuille exécuter une commande nécessitant une élévation de privilège via sudo (par exemple mount, shutdown, etc)  et que l&#8217;on veuille rediriger la sortie de cette commande dans un fichier appartenant à root nécessitant donc lui aussi une élévation de privilège &#8230; <a href="http://voidandany.free.fr/index.php/faire-la-redirection-dune-commande-executee-avec-sudo/">Continuer la lecture <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><br class="spacer_" /></p>
<p>Admettons que l&#8217;on veuille <strong>exécuter une commande</strong> nécessitant une élévation de privilège <strong>via sudo</strong> (par exemple mount, shutdown, etc)  et que l&#8217;on veuille <strong>rediriger la sortie</strong> de cette commande dans un <strong>fichier appartenant à root</strong> nécessitant donc lui aussi une élévation de privilège (un quelquonque fichier de /etc).</p>
<p><br class="spacer_" /></p>
<p>Si on fait la combinaison suivante, cela échouera :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> ma_commande <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> mon_fichier</pre></div></div>

<p><br class="spacer_" /></p>
<p>En effet le sudo &laquo;&nbsp;fait effet&nbsp;&raquo; sur ma_commande mais pas sur la redirection, 2 solutions pour palier à ce problème :</p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p>1 &#8211; Lancer un <strong>terminal en super-utilisateur</strong> et éxécuter la commande sans le sudo :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #660033;">-s</span>
ma_commande <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> mon_fichier</pre></div></div>

<p><br class="spacer_" /></p>
<p>2 &#8211; Utiliser la <strong>commande bash</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">bash</span> <span style="color: #660033;">-c</span> <span style="color: #ff0000;">&quot;ma_commande &gt;&gt; mon_fichier&quot;</span></pre></div></div>

<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p>Pour info voici la commande qui m&#8217;a fait me poser cette question :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">bash</span> <span style="color: #660033;">-c</span> <span style="color: #ff0000;">&quot;mdadm --detail --scan &gt;&gt; /etc/mdadm/mdadm.conf&quot;</span></pre></div></div>

<p><strong> </strong></p>
<p><strong><span style="text-decoration: underline;">Edit : </span></strong></p>
<p>18/01/2010 : Une autre solution : <a href="http://linux.leunen.com/?p=780">http://linux.leunen.com/?p=780</a></p>
]]></content:encoded>
			<wfw:commentRss>http://voidandany.free.fr/index.php/faire-la-redirection-dune-commande-executee-avec-sudo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Script bash, loguer et afficher des messages</title>
		<link>http://voidandany.free.fr/index.php/script-bash-loguer-et-afficher-des-messages/</link>
		<comments>http://voidandany.free.fr/index.php/script-bash-loguer-et-afficher-des-messages/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 09:00:16 +0000</pubDate>
		<dc:creator>voidAndAny</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[log]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://voidandany.free.fr/?p=863</guid>
		<description><![CDATA[Lorsque l&#8217;on écrit un script bash, on peut vouloir écrire des message à la fois sur la sortie standard à des fins d&#8217;information et/ou debuggage lorsque l&#8217;on lance le script à la main ET dans un fichier de log afin &#8230; <a href="http://voidandany.free.fr/index.php/script-bash-loguer-et-afficher-des-messages/">Continuer la lecture <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Lorsque l&#8217;on écrit un script bash, on peut vouloir écrire des <strong>message</strong> à la fois sur la <strong>sortie standard</strong> à des fins d&#8217;information et/ou debuggage lorsque l&#8217;on lance le script à la main ET dans un <strong>fichier de log</strong> afin d&#8217;avoir des traces lorsque ce script s&#8217;exécute automatiquement (via cron par exemple).</p>
<p><br class="spacer_" /></p>
<p>Jusqu&#8217;à peu ne connaissant pas la commande que je vais décrire ici, lorsque ce besoin se faisait sentir je faisais 2 echo &laquo;&nbsp;mon message&nbsp;&raquo; : </p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;mon message&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;mon message&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>ver<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>fichier.log</pre></div></div>

<p><br class="spacer_" /></p>
<p>Ca marche mais c&#8217;est pas propre, surtout qu&#8217;il existe un outils répondant au besoin dans l&#8217;immense arsenal des <a href="http://www.gnu.org/software/coreutils/manual/html_node/index.html" target="_blank">programmes de base GNU</a>.</p>
<p>Cette commande s&#8217;appelle <strong>tee</strong>.</p>
<p><br class="spacer_" /></p>
<p>Cette commande copie son entrée standard vers sa sortie standard et vers un fichier passé en paramètre.</p>
<p><br class="spacer_" /></p>
<p>Pour répondre au besoin posé, on peut donc faire :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;mon message&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tee</span> <span style="color: #660033;">-a</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>fichier.log</pre></div></div>

<p><br class="spacer_" /></p>
<p>le paramètre -a indique au programme tee qu&#8217;il faut écrire dans le fichier ne mode ajout (append) et non pas écraser le contenu du fichier à chaque fois (ce qui peut être pratique)</p>
<p><br class="spacer_" /></p>
<p>Et voila c&#8217;est tout de même plus élégant que le double echo.</p>
<p><br class="spacer_" /></p>
<p><strong><em><span style="text-decoration: underline;">Source : </span></em></strong></p>
<p><a href="http://www.libordux.org/doc/cmdline/tips.php#tee">http://www.libordux.org/doc/cmdline/tips.php#tee</a></p>
<p><a href="http://pwet.fr/man/linux/commandes/tee">http://pwet.fr/man/linux/commandes/tee</a></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
]]></content:encoded>
			<wfw:commentRss>http://voidandany.free.fr/index.php/script-bash-loguer-et-afficher-des-messages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Transfert automatique des podcasts vers un lecteur MP3</title>
		<link>http://voidandany.free.fr/index.php/transfert-automatique-des-podcasts-vers-un-lecteur-mp3/</link>
		<comments>http://voidandany.free.fr/index.php/transfert-automatique-des-podcasts-vers-un-lecteur-mp3/#comments</comments>
		<pubDate>Fri, 24 Apr 2009 07:05:11 +0000</pubDate>
		<dc:creator>voidAndAny</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[musique]]></category>
		<category><![CDATA[podcast]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[udev]]></category>

		<guid isPermaLink="false">http://voidandany.free.fr/?p=152</guid>
		<description><![CDATA[Comme je l&#8217;ai décrit ici avec Podracer et un petit script maison, il est aisé de mettre en place un système automatique de téléchargement de vos émission de radio ou internet préférées et de les traiter afin que les fichiers &#8230; <a href="http://voidandany.free.fr/index.php/transfert-automatique-des-podcasts-vers-un-lecteur-mp3/">Continuer la lecture <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Comme je l&#8217;ai décrit <a href="http://voidandany.free.fr/index.php/podracer-telechargement-automatique-de-podcasts/" target="_blank">ici</a> avec Podracer et un petit script maison, il est aisé de mettre en place un système automatique de téléchargement de vos émission de radio ou internet préférées et de les traiter afin que les fichiers mp3 récupéré soient le plus aisément possible exploitable.</p>
<p><br class="spacer_" /></p>
<p>Dans le but d&#8217;en faire toujours moins, j&#8217;ai cherché à automatiser le transfert des fichiers mp3 téléchargés vers le lecteur mp3.</p>
<p><br class="spacer_" /></p>
<p>En pré-requis il faut évidemment que le lecteur mp3 soit reconnu comme un disque USB (adieu iPod et autre systèmes à base de <a href="http://fr.wikipedia.org/wiki/Media_Transfer_Protocol" target="_blank">MTP</a>). Dans mon cas pas de problème puisqu&#8217;il s&#8217;agit de transférer les fichiers mp3 ver une carte SD (<a href="http://voidandany.free.fr/index.php/transmetteur-fm-lecteur-mp3/" target="_blank">mon &laquo;&nbsp;lecteur&nbsp;&raquo;)</a></p>
<p><br class="spacer_" /></p>
<p>Après quelques recherches je me suis orienté vers l&#8217;écriture d&#8217;une règle udev pour réaliser ce transfert automatique&#8230;</p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p>Tout d&#8217;abord Udev qu&#8217;est-ce donc ?</p>
<p>Je vous conseil la lecture de ce long <a href="http://doc.ubuntu-fr.org/udev" target="_blank">article</a> dont je vais m&#8217;inspirer pour rédiger ce post.</p>
<p>Donc en gros udev est le système servant à décrire et monter le périphériques sous linux.</p>
<p><br class="spacer_" /></p>
<p>Dans notre exemple udev va nous servir à  :</p>
<ol>
<li>identifier de façon unique le périphérique USB branché (dans mon cas un lecteur de carte SD 3 en 1 de Kingston)</li>
<li>lancer un scripts qui va se charger de copier les fichiers mp3.</li>
</ol>
<p><br class="spacer_" /></p>
<h3>Identification du périphérique USB &#8211; écriture de la règle Udev</h3>
<p><br class="spacer_" /></p>
<p>Il s&#8217;agit de la partie la plus &laquo;&nbsp;ardue&nbsp;&raquo; de la configuration et la partie pour laquelle chacun devra se débrouiller, il s&#8217;agit de trouver via udevinfo les informations qui permettront d&#8217;identifier de façon unique le périphérique USB dont le branchement déclenchera le transfert des fichiers.</p>
<p>Voici la trame des opérations à réaliser qui vous permettront d&#8217;y parvenir :</p>
<p><br class="spacer_" /></p>
<p>1 &#8211; <strong>Brancher </strong>le périphérique USB à identifier</p>
<p><br class="spacer_" /></p>
<p>2- <strong>Trouver le fichier /dev/sdxx</strong> correspondant à votre périphérique, pour cela analyser les messages affichés par dmesg lors du branchement du périphérique.</p>
<p>On aura alors quelque chose du genre :</p>
<p>SCSI device sda: 1003600 512-byte hdwr sectors (514 MB)<br />
 &#8230;<br />
 Attached scsi removable disk sda at scsi0, channel 0, id 0, lun 0<br />
 &#8230;<br />
 usb-storage: device scan complete</p>
<p>Le périphérique est donc accessible sur /dev/sda (ce qui est le cas dans la majorité des cas)</p>
<p><br class="spacer_" /></p>
<p>3- <strong>Analyser les données udevinfo</strong>. Cela se fait en exécutant :</p>
<pre><span class="search_hit">udev</span>info -a -p $(<span class="search_hit">udev</span>info -q path -n /dev/sda)</pre>
<p>Cette commande sort tout un tas de données qu&#8217;il faut analyser pour trouver les informations pertinentes.</p>
<p>Vous trouverez ci-dessous le résultat de la commande udevinfo pour sda et sda1 pour mon lecteur de carte Kingston 3 en 1</p>
<p><a href="http://voidandany.free.fr/wp-content/uploads/udevinfo-sda-flashreader-kingston.txt">udevinfo-sda-flashreader-kingston</a></p>
<p><a href="http://voidandany.free.fr/wp-content/uploads/udevinfo-sda1-flashreader-kingston.txt">udevinfo-sda1-flashreader-kingston</a></p>
<p>Dans mon cas j&#8217;ai identifié le périphérique par sa taille, ce qui est limite mais cela fonctionne.</p>
<p>Pour info pour le même lecteur de carte mais avec 2 cartes SD 2Go de marques différentes on a une taille différente dans le résultat du udevinfo (3870587 contre  3841911)</p>
<p><br class="spacer_" /></p>
<p>4 &#8211; Ecrire la <strong>règle udev</strong>, on créra le fichier 10-local.rules</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>udev<span style="color: #000000; font-weight: bold;">/</span>rules.d<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">10</span>-local.rules</pre></div></div>

<p>Puis on ajoutera :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">KERNEL</span>==<span style="color: #ff0000;">&quot;sda1&quot;</span>, <span style="color: #007800;">SUBSYSTEM</span>==<span style="color: #ff0000;">&quot;block&quot;</span>, ATTR<span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #c20cb9; font-weight: bold;">size</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>==<span style="color: #ff0000;">&quot;3841911&quot;</span>,  RUN+=<span style="color: #ff0000;">&quot;/root/transfert.sh&quot;</span></pre></div></div>

<p>Toute la première partie de la régle est dépendente de votre périphérique et de l&#8217;attribut que vous avez choisi pour l&#8217;identifier.</p>
<p>La dernière partie (RUN) est commune, on indique à udev que lorsqu&#8217;il détecte le périphérique sda1 ayant une taille de 3841911, il doit exécuter le script transfert.sh dans root.</p>
<p><br class="spacer_" /></p>
<h3>Script de transfert des fichiers mp3 vers les lecteur</h3>
<p><br class="spacer_" /></p>
<p>Créer le fichier script transfert.sh</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>transfert.sh</pre></div></div>

<p><br class="spacer_" /></p>
<p>Et y copier ceci :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># paramétrage</span>
<span style="color: #666666; font-style: italic;"># point de montage du périphérique USB</span>
<span style="color: #007800;">MOUNTPOINT</span>=<span style="color: #ff0000;">&quot;/mnt/transfertPodcast&quot;</span>
<span style="color: #666666; font-style: italic;"># fichier de log</span>
<span style="color: #007800;">LOGFILE</span>=<span style="color: #ff0000;">&quot;/root/transfertPodcast.log&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;---------- debut ----------&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOGFILE</span>
<span style="color: #c20cb9; font-weight: bold;">date</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOGFILE</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># nom du device</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;devname =&quot;</span> <span style="color: #007800;">$DEVNAME</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOGFILE</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># si le point de montage n'existe pas on le crée</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-d</span> <span style="color: #007800;">$MOUNTPOINT</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;creation repertoire&quot;</span> <span style="color: #007800;">$MOUNTPOINT</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOGFILE</span>
    <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #007800;">$MOUNTPOINT</span>;
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># montage du périphérique USB</span>
<span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #007800;">$DEVNAME</span> <span style="color: #007800;">$MOUNTPOINT</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;erreur de montage&quot;</span> <span style="color: #007800;">$MOUNTPOINT</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOGFILE</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># sauvegarde des anciens podcast</span>
<span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #007800;">$MOUNTPOINT</span><span style="color: #000000; font-weight: bold;">/</span>Podcast<span style="color: #000000; font-weight: bold;">/*</span>.mp3 <span style="color: #007800;">$MOUNTPOINT</span><span style="color: #000000; font-weight: bold;">/</span>Podcast<span style="color: #000000; font-weight: bold;">/</span>_save<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># déplacement des nouveau podcast vers le périphérique USB</span>
<span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>mon_user<span style="color: #000000; font-weight: bold;">/</span>downloads<span style="color: #000000; font-weight: bold;">/</span>podcast<span style="color: #000000; font-weight: bold;">/*</span>.mp3 <span style="color: #007800;">$MOUNTPOINT</span><span style="color: #000000; font-weight: bold;">/</span>Podcast<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOGFILE</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># démontage du périphérique USB</span>
<span style="color: #c20cb9; font-weight: bold;">umount</span> <span style="color: #007800;">$MOUNTPOINT</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;erreur de démontage&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOGFILE</span>
    <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>beep <span style="color: #660033;">-f</span> <span style="color: #000000;">1200</span> <span style="color: #660033;">-n</span> <span style="color: #660033;">-f</span> <span style="color: #000000;">1000</span> <span style="color: #660033;">-n</span> <span style="color: #660033;">-f</span> <span style="color: #000000;">1200</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># c'est fini : musique maestro</span>
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>beep <span style="color: #660033;">-f</span> <span style="color: #000000;">1000</span> <span style="color: #660033;">-r</span> <span style="color: #000000;">2</span> <span style="color: #660033;">-n</span> <span style="color: #660033;">-r</span> <span style="color: #000000;">5</span> <span style="color: #660033;">-l</span> <span style="color: #000000;">10</span> <span style="color: #660033;">--new</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;-------- end - ok --------&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOGFILE</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LOGFILE</span>
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span></pre></td></tr></table></div>

<p>Ce script monte le périphérique USB identifié par la variable d&#8217;environnement DEVNAME dans le répertoire paramétré au début du script (MOUNTPOINT).</p>
<p><br class="spacer_" /></p>
<p>Les fichiers mp3 présents dans le répertoire Podcast du périphérique USB sont sauvegardés (déplacés) dans un sous répertoire _save</p>
<p>En effet on part de l&#8217;hypothèse que l&#8217;on garde pas les podcast une fois écoutés et que l&#8217;on ne branche notre lecteur mp3 en vue de le &laquo;&nbsp;recharger&nbsp;&raquo; en podcast que lorsque ceux présents dessus ont tous été écoutés.</p>
<p>On réalise donc une sauvegarde au cas où ce ne serait pas le cas mais c&#8217;est optionnel.</p>
<p><br class="spacer_" /></p>
<p>Le podcasts présents dans le sous-répertoire downloads/podcast du user réalisant le download sont ensuite transférés (déplacés) sur le périphérique monté.</p>
<p>Il faut bien sûr mettre en cohérence le chemin où l&#8217;on va chercher les podcasts avec celui paramétré dans votre script de téléchargement des podcasts.</p>
<p><br class="spacer_" /></p>
<p>Le prériphérique est alors démonté et une petite musique à base de beep (sudo aptitude install beep) est jouée</p>
<p><br class="spacer_" /></p>
<p>Le tout étant loggué dans fichier paramétré via LOGFILE</p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p>Ce script est très largement améliorable mais je ne pas pris le temps de le faire, on pourra citer comme axe d&#8217;amélioration :</p>
<ul>
<li>Purger le répertoire _save en se basant sur la date de copie des fichier pour ne garder que la date d-1 (est-ce faisable ?)</li>
<li>Déplacement des logs</li>
<li>Purge des logs</li>
<li>&#8230;</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://voidandany.free.fr/index.php/transfert-automatique-des-podcasts-vers-un-lecteur-mp3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flexget : téléchargement automatique de torrents</title>
		<link>http://voidandany.free.fr/index.php/flexget-telechargement-automatique-de-torrents/</link>
		<comments>http://voidandany.free.fr/index.php/flexget-telechargement-automatique-de-torrents/#comments</comments>
		<pubDate>Wed, 22 Apr 2009 11:14:21 +0000</pubDate>
		<dc:creator>voidAndAny</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[serie]]></category>

		<guid isPermaLink="false">http://voidandany.free.fr/?p=150</guid>
		<description><![CDATA[Edit 6/05/2010 : Si vous utilisez Flexget v1.0x, cet article est osolète, se référer à  Téléchargement automatisé de séries avec Flexget Avertissement : Le but de ce post est de montrer comment il est possible d&#8217;automatiser le téléchargement de torrents. &#8230; <a href="http://voidandany.free.fr/index.php/flexget-telechargement-automatique-de-torrents/">Continuer la lecture <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Edit 6/05/2010 : Si vous utilisez Flexget v1.0x, cet article est osolète, se référer à <a title="Téléchargement automatisé de séries avec Flexget" rel="bookmark" href="../index.php/telechargement-automatise-de-series-avec-flexget-torrents/"><span style="font-weight: bold;"> </span>Téléchargement  automatisé de séries avec Flexget</a></p>
<div>
<div></div>
</div>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p style="border: #ff0000 thin solid;"><span style="color: #ff0000;"><strong>Avertissement : </strong></span></p>
<p>Le but de ce post est de montrer comment il est possible d&#8217;automatiser le téléchargement de torrents. Ce n&#8217;est en aucun cas l&#8217;apologie du piratage.</p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p>Cet avertissement effectué passons à la description du problème.</p>
<p>Comment faire pour automatiser le téléchargement de séries via un flux RSS ?</p>
<p>Au moment où j&#8217;ai mis ce système en place la version de Deluge utilisé ne permettait pas de s&#8217;abonner à un flux RSS. J&#8217;ai donc dû trouver une alternative qui à l&#8217;usage se révèle non seulement efficace mais aussi supérieure.</p>
<p><br class="spacer_" /></p>
<p>Cette alternative s&#8217;appelle <a href="http://flexget.com/" target="_blank">Flexget</a>.</p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p>La phrase d&#8217;introduction du site de Flexget décrit bien son usage et son rôle :</p>
<p><br class="spacer_" /></p>
<p>&laquo;&nbsp;FlexGet is a program aimed to automate downloading or processing content (torrents, podcasts, etc.) from different sources like RSS-feeds, html-pages, various sites and more. &laquo;&nbsp;</p>
<p><br class="spacer_" /></p>
<p>Soit grosso-modo en Français :</p>
<p><br class="spacer_" /></p>
<p>&laquo;&nbsp;Flexget est un programme ayant pour rôle d&#8217;automatiser le téléchargement ou le traitement de contenus (torrents, podcasts) à partir de différentes source comme les flux RSS, les pages HTML, de nombreux sites et plus encore&nbsp;&raquo;</p>
<p><br class="spacer_" /></p>
<p>Bref ce qu&#8217;il nous faut pour répondre à la problématique posée.</p>
<p>Flexget va à partir d&#8217;un flux RSS nous informant en quasi temps réél de la mise à disposition d&#8217;un torrent, télécharger ce même torrent.</p>
<p>Là où il surpasse les clients torrent ayant la capacité à s&#8217;abonner à ces même flux RSS, c&#8217;est qu&#8217;on pourra lui indiquer ses préférence (en terme de qualité de release) et qu&#8217;il ne téléchargera qu&#8217;un seul torrent pour un même épisode d&#8217;une même saison d&#8217;une série donnée.</p>
<p><br class="spacer_" /></p>
<p>En pré-requis il nous faut un flux RSS nous informant de la mise à disposition d&#8217;un torrent. Dnas le but de ne pas trop inciter au priatage je n&#8217;indiquerais volontairement pas ici où trouver ce genre de site&#8230;</p>
<p><br class="spacer_" /></p>
<h3>Installation de flexget</h3>
<p><br class="spacer_" /></p>
<p>Flexget à besoin du package permettant à Python de parser le YAML et de feedparser permettant de parser les flux RSS, on installera donc  :</p>
<p><br class="spacer_" /></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> python-yaml python-feedparser</pre></div></div>

<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p>Téléchargement de la dernière version de flexget (la 0.9.3.2 dans mon cas) :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>download.flexget.com<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0.9</span><span style="color: #000000; font-weight: bold;">/</span>FlexGet_0.9.3.2.zip</pre></div></div>

<p><br class="spacer_" /></p>
<p>Dézippage de l&#8217;archive téléchargée :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">unzip</span> FlexGet_0.9.3.2.zip</pre></div></div>

<p><br class="spacer_" /></p>
<p>Et voila flexget est installé, reste à le paramétrer.</p>
<p><br class="spacer_" /></p>
<h3>Paramétrage de flexget</h3>
<p><br class="spacer_" /></p>
<p>Le paramétrage se fait dans un fichier yml, ce dernier peut avoir le nom que l&#8217;on veut et être placé où l&#8217;on veut, dans mon cas ce fichier de configuration se nomme configFlexget.yml et est placé dans le répertoire de flexget (lui même dans le home de mon user).</p>
<p><br class="spacer_" /></p>
<p>Ouvrir le fichier et copier une configuration ressemblant à ceci :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">global:
  download: ~<span style="color: #000000; font-weight: bold;">/</span>downloads<span style="color: #000000; font-weight: bold;">/</span>torrentfiles
&nbsp;
settings:
  series:
    timeframe:
      enough: hdtv
&nbsp;
feeds:
  Serie1:
    rss: http:<span style="color: #000000; font-weight: bold;">//</span>xxxxx.net<span style="color: #000000; font-weight: bold;">/</span>serie1.xml
    series:
      - Serie1
&nbsp;
   Serie2:
    rss: http:<span style="color: #000000; font-weight: bold;">//</span>xxxxx.net<span style="color: #000000; font-weight: bold;">/</span>serie2.xml
    series:
      - Serie2</pre></td></tr></table></div>

<p><br class="spacer_" /></p>
<p><strong><span style="text-decoration: underline;">Point important</span></strong> :</p>
<p>Le YML (ou YAML) est un language structuré (comme le XML) mais il est beaucoup moins verbeux (pas de balise ouvrante et fermante)</p>
<p>En contrepartie la hierarchie des éléments est réalisé via l&#8217;indentation à base d&#8217;espace (surtout pas de tabulation).</p>
<p>Il convient donc d&#8217;être très rigoureux sur l&#8217;edition des fichiers yml.</p>
<p><br class="spacer_" /></p>
<p>La <strong>section global</strong> permet comme son nom l&#8217;indique le paramètrage global de flexget quelque soit le plugin utilisé par la suite, elle sert uniquement à définir le répertoire où les téléchargements vont êtres stockés.</p>
<p>La ruse consiste ici à mettre le même chemin que celui paramétré dans Deluge paramètre &laquo;&nbsp;Auto Add folder&nbsp;&raquo; (cf. mon article <a href="http://voidandany.free.fr/index.php/installation-dun-client-torrent-deluge/" target="_blank">Installation d’un client torrent &#8211; Deluge</a>), ainsi flexget télécharge les torrents et Deluge commence automatiquement le téléchargement.</p>
<p><br class="spacer_" /></p>
<p><strong>Section settings</strong>, on met ici le paramétrage spécifique au plugins utilisés, dans le ca présent pour le plugin series il existe 2 paramètrages :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">&nbsp;</pre></div></div>

<ul>
<li>timeframe \ hour : pas utilisé encore mais ça ne devrait pas tarder. Cela permet d&#8217;indiquer à flexget qu&#8217;il faut attendre un certain temps entre la mise à disposition d&#8217;un torrent et son téléchargement. L&#8217;utilité : attendre qu&#8217;une nouvelle release soit disponible.</li>
<li>timeframe \enough : ce paramètre est l&#8217;une des force de Flexget, il indique quelle qualité de release est suffisante. Les valeurs possibles sont 1080p, 1080, 720p, 720, hr, dvd, hdtv, dsr, dsrip. Ainsi quand on a pas de télé HD il est inutile de télécharger du 1080p.</li>
</ul>
<p> </p>
<p>Vient ensuite la section de <strong>paramétrages</strong> de chacune des <strong>séries</strong> où l&#8217;on indique le nom de la série (Serie1) et le flux RSS associé.</p>
<p>Le paramètre feeds \ Serie1 \ series, qui a dans mon cas Series1 comme valeur, permet d&#8217;indiquer quelle est la série à télécharger dans le cas d&#8217;un flux recensant plusieurs séries.</p>
<p> </p>
<p>Et voila concernant mon paramétrage, il ne faut pas hésiter à aller sur le site de Flexget pour voir les nombreuses possibilités de ce logiciel (téléchargement de comics, génération de flux RSS) et plus particulièrement les autres paramétrage du <a href="http://flexget.com/wiki/FilterSeries" target="_blank">plugin serie</a></p>
<p> </p>
<p>Pour tester votr fichier de configuration :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>flexget.py <span style="color: #660033;">-c</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>svc<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>flexget<span style="color: #000000; font-weight: bold;">/</span>configFlexGet.yml <span style="color: #660033;">--check</span></pre></div></div>

<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<h3>Exécution de flexget</h3>
<p><br class="spacer_" /></p>
<p>Pour exécuter flexget il suffit de faire :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>flexget.py <span style="color: #660033;">-c</span> ~<span style="color: #000000; font-weight: bold;">/</span>flexget<span style="color: #000000; font-weight: bold;">/</span>configFlexGet.yml</pre></div></div>

<p>On peut alors evidemment ajouter cette ligne de commande dans une tache Cron&#8230;.</p>
<p><br class="spacer_" /></p>
]]></content:encoded>
			<wfw:commentRss>http://voidandany.free.fr/index.php/flexget-telechargement-automatique-de-torrents/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Podracer : téléchargement automatique de podcasts</title>
		<link>http://voidandany.free.fr/index.php/podracer-telechargement-automatique-de-podcasts/</link>
		<comments>http://voidandany.free.fr/index.php/podracer-telechargement-automatique-de-podcasts/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 21:06:58 +0000</pubDate>
		<dc:creator>voidAndAny</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[musique]]></category>
		<category><![CDATA[podcast]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://voidandany.free.fr/?p=69</guid>
		<description><![CDATA[Article obsolète : voir l&#8217;article Quel podcast écouter Premier article sur ma linux-box. Pour situer rapidement les usages de cette machine (j&#8217;en reparlerais plus longuement plus tard), il s&#8217;agit d&#8217;un vieux PC (Duron 1GHz) avec Ubuntu minimal et qui me sert &#8230; <a href="http://voidandany.free.fr/index.php/podracer-telechargement-automatique-de-podcasts/">Continuer la lecture <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong>Article obsolète</strong> : voir l&#8217;article <a title="Quel podcast écouter" rel="bookmark" href="http://voidandany.free.fr/index.php/quel-podcast-ecouter/">Quel podcast écouter</a></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p>Premier article sur ma linux-box.</p>
<p>Pour situer rapidement les usages de cette machine (j&#8217;en reparlerais plus longuement plus tard), il s&#8217;agit d&#8217;un vieux PC (Duron 1GHz) avec Ubuntu minimal et qui me sert de <a href="http://fr.wikipedia.org/wiki/Home_Theater_Personal_Computer" target="_blank">HTPC</a>, de serveur de backup et de download.</p>
<p>Le sujet de cet article se situe dans le cadre de ce dernier point.</p>
<p>Faisant pas mal de route, j&#8217;ai le temps d&#8217;écouter la radio mais je me suis vite rendu compte qu&#8217;avec 1h matin et soir les infos avait tendance à passer en boucle.</p>
<p>D&#8217;où l&#8217;idée d&#8217;écouter des émissions qui m&#8217;intéressent vraiment, et c&#8217;est là qu&#8217;intervient le <a href="http://fr.wikipedia.org/wiki/Podcasting" target="_blank">podcast</a>.</p>
<p>Je me suis donc mis en quête d&#8217;un logiciel de podcast tournant sous linux.</p>
<p>Le besoin est le suivant :</p>
<ul>
<li>Paramétrage facile et souple</li>
<li>Pas d&#8217;interface graphique</li>
</ul>
<p><span id="more-69"></span></p>
<h3>Installation et paramétrage de podracer</h3>
<p>Après quelque recherche j&#8217;ai trouvé <a href="http://podracer.sourceforge.net/" target="_blank">podracer</a> qui est disponible dans le dépôt Universe d&#8217;Ubuntu (Gutsy dans mon cas) :</p>
<p><a href="http://packages.ubuntu.com/gutsy/podracer" target="_blank">http://packages.ubuntu.com/gutsy/podracer</a></p>
<p>L&#8217;installation se fait donc par un simple :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> podracer</pre></div></div>

<p>Il faut ensuite paramétrer les podcasts que l&#8217;on souhaite télécharger.</p>
<p>Là aussi c&#8217;est très simple il suffit d&#8217;éditer / de créer le fichier le fichier subscription :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">vim</span> ~<span style="color: #000000; font-weight: bold;">/</span>.podracer<span style="color: #000000; font-weight: bold;">/</span>subscriptions</pre></div></div>

<p>Ce dernier à une structure très simple :</p>
<pre>adresse_du_podcast sous_répertoire</pre>
<p>exemple :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># France Inter - CO2 Mon Amour</span>
http:<span style="color: #000000; font-weight: bold;">//</span>radiofrance-podcast.net<span style="color: #000000; font-weight: bold;">/</span>podcast09<span style="color: #000000; font-weight: bold;">/</span>rss_10006.xml CO2MonAmour</pre></div></div>

<p>Les lignes commençant par # étant des commentaires.</p>
<p>(on verra l&#8217;usage du sous répertoire par la suite)</p>
<p>Il n&#8217;y a plus qu&#8217;à éditer le fichier podracer.conf pour indiquer au programme le répertoire de sauvegarde :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>podracer.conf ~<span style="color: #000000; font-weight: bold;">/</span>.podracer<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">vim</span> ~<span style="color: #000000; font-weight: bold;">/</span>.podracer<span style="color: #000000; font-weight: bold;">/</span>podracer.conf</pre></div></div>

<p>Dans mon cas :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># poddir is the directory where you want podcasts to be saved</span>
<span style="color: #666666; font-style: italic;"># Directory names may be created dynamically based on time, date and many other</span>
<span style="color: #666666; font-style: italic;"># possibilities.  Directory names based on feeds are listed in the subscriptions</span>
<span style="color: #666666; font-style: italic;"># file.</span>
<span style="color: #007800;">poddir</span>=<span style="color: #007800;">$HOME</span><span style="color: #000000; font-weight: bold;">/</span>downloads<span style="color: #000000; font-weight: bold;">/</span>podcast<span style="color: #000000; font-weight: bold;">/</span>temp</pre></div></div>

<p>Et puis on lance podracer :</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">podracer</pre></div></div>

<p>Au premier lancement cela peut être long, très long, on pourra donc exécuter</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">podracer <span style="color: #660033;">--catchup</span></pre></div></div>

<p>Podracer loguera tous les podcasts comme téléchargés mais n&#8217;en téléchargera aucun en réalité.</p>
<p>Dans notre exemple on devrait donc voir sous le répertoire $HOME/downloads/podcast/temp/CO2MonAmour un/des fichier(s) mp3 de l&#8217;émission de France Inter.</p>
<p><br class="spacer_" /></p>
<h3>Traitement des podcasts téléchargés</h3>
<p>Avec podracer, on télécharge rapidement et facilement des podcasts, mais vous vous en rendrez compte à chaque site / podcasts un nom de fichier ayant un format différent.</p>
<p>Certains avec la date (avec des formats différents entre les podcast) d&#8217;autre sans, certain avec le nom de l&#8217;émission, d&#8217;autre sans.</p>
<p>De plus le lecteur mp3 que j&#8217;utilise (<a href="http://voidandany.free.fr/index.php/transmetteur-fm-lecteur-mp3transmetteur-fm-lecteur-mp3/">lien</a>), lorsqu&#8217;on l&#8217;arrête retient la piste à laquelle il est rendu mais pas l&#8217;endroit dans la piste.</p>
<p>Or les podcasts d&#8217;une émission se présentent le plus souvent (tout le temps) sous la forme d&#8217;un fichier mp3 unique et recommencer à écouter une émission complète parce que la dernière fois on s&#8217;est arrêté 10 minutes avant la fin, non merci.</p>
<p>Donc l&#8217;idée était de faire un script bash de renommage des podcasts et de découper ces dernier en tronçon de x minutes.</p>
<p>Après de nombreux tâtonnements (c&#8217;était mon premier script) et divers recherches et inspiration sur le web voici le scripts fonctionnel :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># répertoire de travail</span>
<span style="color: #007800;">PODPATH</span>=~<span style="color: #000000; font-weight: bold;">/</span>downloads<span style="color: #000000; font-weight: bold;">/</span>podcast
<span style="color: #007800;">TEMPDIR</span>=<span style="color: #007800;">$PODPATH</span><span style="color: #000000; font-weight: bold;">/</span>temp
<span style="color: #007800;">DUREE</span>=<span style="color: #000000;">2.00</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> Téléchargement des podcasts
<span style="color: #7a0874; font-weight: bold;">&#91;</span> -f  ~<span style="color: #000000; font-weight: bold;">/</span>.podracer<span style="color: #000000; font-weight: bold;">/</span>tempsub <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> ~<span style="color: #000000; font-weight: bold;">/</span>.podracer<span style="color: #000000; font-weight: bold;">/</span>tempsub
<span style="color: #666666; font-style: italic;"># lance podracer qui va télécharger les podcats</span>
podracer
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> Ménage des anciens podcasts
<span style="color: #666666; font-style: italic;">#vide les mp3 traité lors de la session précédente</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$(find $TEMPDIR -maxdepth 1 -iname '*.mp3')</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #007800;">$TEMPDIR</span><span style="color: #000000; font-weight: bold;">/*</span>.mp3
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> Renommage des podcasts téléchargés
<span style="color: #666666; font-style: italic;">#pour tous les mp3 téléchargés par podracer on les renomes</span>
<span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #007800;">$TEMPDIR</span><span style="color: #000000; font-weight: bold;">/*/*</span>.mp3<span style="color: #000000; font-weight: bold;">`</span>; <span style="color: #000000; font-weight: bold;">do</span>
 <span style="color: #666666; font-style: italic;"># date de création du fichier</span>
 <span style="color: #007800;">creationTime</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">stat</span> <span style="color: #660033;">-c</span> <span style="color: #ff0000;">&quot;%y&quot;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$i</span>&quot;</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> - <span style="color: #ff0000;">'{print substr($1,3,4)$2substr($3,1,2)}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
 <span style="color: #666666; font-style: italic;"># on déduit le nouveau nom de base du fichier en prenant le nom du répertoire le contenant (spécifié dans ~/.podracer/subscrition)</span>
 <span style="color: #007800;">podName</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">dirname</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$i</span>&quot;</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> -F<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #ff0000;">'{print $NF}'</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
 <span style="color: #666666; font-style: italic;"># renomme / deplace le fichier</span>
 <span style="color: #666666; font-style: italic;"># si un fichier ayant le même nom existe déjà (cas où plusieurs podcast d'une même emission téléchargé le même jour)</span>
 <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$TEMPDIR</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #ff0000;">&quot;<span style="color: #007800;">$creationTime</span>&quot;</span>_<span style="color: #ff0000;">&quot;<span style="color: #007800;">$podName</span>&quot;</span><span style="color: #ff0000;">&quot;.mp3&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
 <span style="color: #666666; font-style: italic;"># on ajoute un compteur</span>
 <span style="color: #007800;">COUNT</span>=<span style="color: #000000;">1</span>
 <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$TEMPDIR</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #ff0000;">&quot;<span style="color: #007800;">$creationTime</span>&quot;</span>_<span style="color: #ff0000;">&quot;<span style="color: #007800;">$podName</span>&quot;</span>_<span style="color: #ff0000;">&quot;<span style="color: #007800;">$COUNT</span>&quot;</span><span style="color: #ff0000;">&quot;.mp3&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">do</span>
 <span style="color: #7a0874; font-weight: bold;">let</span> <span style="color: #007800;">COUNT</span>=COUNT+<span style="color: #000000;">1</span>
 <span style="color: #000000; font-weight: bold;">done</span>
 <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$i</span>&quot;</span> <span style="color: #007800;">$TEMPDIR</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #ff0000;">&quot;<span style="color: #007800;">$creationTime</span>&quot;</span>_<span style="color: #ff0000;">&quot;<span style="color: #007800;">$podName</span>&quot;</span>_<span style="color: #ff0000;">&quot;<span style="color: #007800;">$COUNT</span>&quot;</span><span style="color: #ff0000;">&quot;.mp3&quot;</span>
 <span style="color: #000000; font-weight: bold;">else</span>
 <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$i</span>&quot;</span> <span style="color: #007800;">$TEMPDIR</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #ff0000;">&quot;<span style="color: #007800;">$creationTime</span>&quot;</span>_<span style="color: #ff0000;">&quot;<span style="color: #007800;">$podName</span>&quot;</span><span style="color: #ff0000;">&quot;.mp3&quot;</span>
 <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> Découpage des podcasts téléchargés
<span style="color: #666666; font-style: italic;"># pour chacun des fichiers renomés et déplacés, on split le mp3 en section de</span>
<span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #007800;">$TEMPDIR</span><span style="color: #000000; font-weight: bold;">/*</span>.mp3<span style="color: #000000; font-weight: bold;">`</span>; <span style="color: #000000; font-weight: bold;">do</span>
 <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$i</span>&quot;</span>
 <span style="color: #007800;">NICENAME</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">basename</span> <span style="color: #007800;">$i</span> .mp3<span style="color: #000000; font-weight: bold;">`</span>
 <span style="color: #666666; font-style: italic;"># Send both stderr and stdout to /dev/null so that this is a quiet cron job</span>
 mp3splt <span style="color: #660033;">-t</span> <span style="color: #007800;">$DUREE</span> <span style="color: #660033;">-aqd</span> <span style="color: #007800;">$PODPATH</span> <span style="color: #660033;">-o</span> <span style="color: #007800;">$NICENAME</span>-<span style="color: #000000; font-weight: bold;">@</span>n <span style="color: #007800;">$i</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></td></tr></table></div>

<p><br class="spacer_" /></p>
<p>Le script est normalement pas trop mal commenté, mais voici ce qu&#8217;il fait :</p>
<ul>
<li>Suppression du répertoire ~/.podracer/tempsub, ce dernier contient les fichiers temporaires que podracer crée en cours de téléchargement. Si la précédente exécution ne s&#8217;est pas terminé correctement les fichiers temporaires ne sont pas detruits et leurs présence le téléchargment ultérieur du podcast.</li>
</ul>
<ul>
<li>Pour tous les fichier mp3 présents dans un sous répertoire de ~/downloads/podcast/temp (paramétré dans podracer.conf) on les copie dans ~/downloads/podcast/temp en les renommant ainsi :</li>
</ul>
<pre>AAMMJJ_sousRepertoire_incrément.mp3</pre>
<p style="padding-left: 60px;">AAMMJJ : date<br />
 sousRépertoire : sous répertoire paramétré dans le fichier subscrition de podracer, d&#8217;où l&#8217;intérêt de mettre un nom caractérisant le podcast<br />
 incrément : optionnel au cas ou 2 podcasts de la même émission serait téléchargé le même jour</p>
<ul>
<li>Pour tous les fichier mp3 présents dans ~/downloads/podcast/tem, découpage du fichier en morceau de 2 minutes avec l&#8217;utilitaire mp3splt</li>
</ul>
<p>Il faudra préalablement à l&#8217;exécution de ce script avoir installé mp3splt (sudo aptitude install mp3splt) et avoir fait un chmod 755 sur le script.</p>
<p><br class="spacer_" /></p>
<p>Ce script pourra ensuite être planifié dans une tache cron.</p>
]]></content:encoded>
			<wfw:commentRss>http://voidandany.free.fr/index.php/podracer-telechargement-automatique-de-podcasts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
