<?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>Björn Schießle&#039;s Weblog &#187; bash</title>
	<atom:link href="http://blog.schiessle.org/tag/bash/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.schiessle.org</link>
	<description></description>
	<lastBuildDate>Fri, 12 Feb 2010 01:37:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>My Backup Solution</title>
		<link>http://blog.schiessle.org/2009/07/16/my-backup-solution/</link>
		<comments>http://blog.schiessle.org/2009/07/16/my-backup-solution/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 08:07:56 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[hacking]]></category>

		<guid isPermaLink="false">http://www.schiessle.org/blog/?p=344</guid>
		<description><![CDATA[For a long time I have made backups of my home partition by hand, starting from time to time rdiff-backup. But as you can imagine, this approach doesn&#8217;t generate regular and reliable backups. I couldn&#8217;t put this task into a simple cronjob because of two reasons. First I use encrypted hard disks and my backup [...]]]></description>
			<content:encoded><![CDATA[<p>For a long time I have made backups of my home partition by hand, starting from time to time <a href="http://rdiff-backup.nongnu.org/">rdiff-backup</a>. But as you can imagine, this approach doesn&#8217;t generate regular and reliable backups.</p>
<p>I couldn&#8217;t put this task into a simple cronjob because of two reasons. First I use encrypted hard disks and my backup disk is connected via USB and not always on. So before a backup starts I have to turn on my backup disk and make sure, that my home partition and my backup disk is decrypted and mounted. Second I don&#8217;t want the backup happen during my regular work. In my experience such processes often starts in the most annoying moments.</p>
<p>So I decided that I need an semi-automatic backup, which runs during shutdown. The result is this small script which I put in /etc/rc0.d/K05backup.sh:</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
48
49
</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: #007800;">currentTime</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>s<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">timeUntilNextBackup</span>=<span style="color: #000000;">604800</span>                 <span style="color: #666666; font-style: italic;"># 604800sec = 1week</span>
<span style="color: #007800;">startBackup</span>=<span style="color: #c20cb9; font-weight: bold;">false</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># check if it's time for the next backup</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: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>nextBackup.log <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #007800;">nextBackupTime</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">cat</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>nextBackup.log<span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$currentTime</span> - <span style="color: #007800;">$nextBackupTime</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #660033;">-gt</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: #007800;">startBackup</span>=<span style="color: #c20cb9; font-weight: bold;">true</span>                       <span style="color: #666666; font-style: italic;">#time for the next backup</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">else</span>
    <span style="color: #007800;">startBackup</span>=<span style="color: #c20cb9; font-weight: bold;">true</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$startBackup</span> == <span style="color: #c20cb9; font-weight: bold;">true</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;It's time for another Backup!&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Don't forget to switch on your backup hard disk before you start!&quot;</span>
    <span style="color: #007800;">repeat</span>=<span style="color: #c20cb9; font-weight: bold;">true</span>
    <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #007800;">$repeat</span>; <span style="color: #000000; font-weight: bold;">do</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Start backup procedure now? (y)es or (n)o? &quot;</span>
        <span style="color: #c20cb9; font-weight: bold;">read</span> char
        <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #007800;">$char</span> <span style="color: #000000; font-weight: bold;">in</span>
            <span style="color: #7a0874; font-weight: bold;">&#91;</span>y,Y<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span> 
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-d</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>schiesbn <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;encrypted HOME partition has to be mounted...&quot;</span>
                    cryptsetup luksOpen <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda6 secureHome
                    <span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>mapper<span style="color: #000000; font-weight: bold;">/</span>secureHome <span style="color: #000000; font-weight: bold;">/</span>home
                <span style="color: #000000; font-weight: bold;">fi</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;encrypted BACKUP partition has to be mounted...&quot;</span>
                cryptsetup luksOpen <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sdd1 secureBackup
                <span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>mapper<span style="color: #000000; font-weight: bold;">/</span>secureBackup <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>backup
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Starting Backup...&quot;</span>;
                rdiff-backup <span style="color: #660033;">--print-statistics</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>schiesbn <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>backup
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;umount backup disk...&quot;</span>
                <span style="color: #c20cb9; font-weight: bold;">umount</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>backup
                cryptsetup luksClose secureBackup
                <span style="color: #666666; font-style: italic;"># calculate the time for the next backup and write it to the log</span>
                <span style="color: #007800;">nextBackup</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #007800;">$currentTime</span> + <span style="color: #007800;">$timeUntilNextBackup</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$nextBackup</span> <span style="color: #000000; font-weight: bold;">&gt;</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>nextBackup.log
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;DONE.&quot;</span>
                <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">10</span>   <span style="color: #666666; font-style: italic;">#give me some time to look at the backup statistics</span>
                <span style="color: #007800;">repeat</span>=<span style="color: #c20cb9; font-weight: bold;">false</span><span style="color: #000000; font-weight: bold;">;;</span>
            <span style="color: #7a0874; font-weight: bold;">&#91;</span>n,N<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span>
                <span style="color: #007800;">repeat</span>=<span style="color: #c20cb9; font-weight: bold;">false</span><span style="color: #000000; font-weight: bold;">;;</span>
        <span style="color: #000000; font-weight: bold;">esac</span>
    <span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></td></tr></table></div>

<p>If the last backup is older than 1 week the script asks me, if I want to do another backup. Than I can decide to postpone it or to start it now. If I decide to start the backup procedure I get the opportunity to decrypt my backup and home partition before rdiff-backup starts. After that I can leave the room and be sure that the computer will shutdown after the backup is finished.</p>
<p>Until now this is the best and most reliable, least annoying and most automated solution I could found.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.schiessle.org/2009/07/16/my-backup-solution/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Fedora and gpg-agent</title>
		<link>http://blog.schiessle.org/2009/05/12/fedora-and-gpg-agent/</link>
		<comments>http://blog.schiessle.org/2009/05/12/fedora-and-gpg-agent/#comments</comments>
		<pubDate>Tue, 12 May 2009 16:28:37 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[fedora]]></category>
		<category><![CDATA[gnupg]]></category>
		<category><![CDATA[smartcard]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://www.schiessle.org/blog/?p=260</guid>
		<description><![CDATA[While it was quite easy to set up my Fellowship smartcard for SSH logins on Debian GNU/Linux following this instructions I never managed to get it working on Fedora GNU/Linux. At some point of time I just gave up. Today finally I found a solution in an on-line forum. The problem was that gpg-agent always [...]]]></description>
			<content:encoded><![CDATA[<p>While it was quite easy to set up my <a href="http://fellowship.fsfe.org">Fellowship</a> smartcard for SSH logins on Debian GNU/Linux following this <a href="http://blogs.fsfe.org/greve/?p=64">instructions</a> I never managed to get it working on Fedora GNU/Linux. At some point of time I just gave up. Today finally I found a solution in an on-line forum.</p>
<p>The problem was that gpg-agent always stopped with the error message:</p>
<pre>
$ gpg-agent
gpg-agent[2857]: can't connect to `/home/schiesbn/.gnupg/S.gpg-agent': No such file or directory
gpg-agent: no gpg-agent running in this session
</pre>
<p>By default the gpg-agent on Fedora creates the socket in /tmp instead of in /home/schiesbn/.gnupg. So you have to move it manually over to your home directory once gpg-agent has started.</p>
<p>To do this I use this script:</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;"># Decide whether to start gpg-agent daemon.</span>
<span style="color: #666666; font-style: italic;"># Create necessary symbolic link in $HOME/.gnupg/S.gpg-agent</span>
&nbsp;
<span style="color: #007800;">SOCKET</span>=S.gpg-agent
<span style="color: #007800;">PIDOF</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">pidof</span> gpg-agent<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">RETVAL</span>=<span style="color: #007800;">$?</span>
&nbsp;
<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;">$RETVAL</span>&quot;</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">1</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;Starting gpg-agent daemon.&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">eval</span> <span style="color: #000000; font-weight: bold;">`</span>gpg-agent <span style="color: #660033;">--daemon</span> <span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">else</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Daemon gpg-agent already running.&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Nasty way to find gpg-agent's socket file...</span>
<span style="color: #007800;">GPG_SOCKET_FILE</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">find</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>gpg-<span style="color: #000000; font-weight: bold;">*</span> <span style="color: #660033;">-name</span> <span style="color: #007800;">$SOCKET</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Updating socket file link.&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #660033;">-fs</span> <span style="color: #007800;">$GPG_SOCKET_FILE</span> <span style="color: #007800;">$HOME</span><span style="color: #000000; font-weight: bold;">/</span>.gnupg<span style="color: #000000; font-weight: bold;">/</span>S.gpg-agent</pre></div></div>

<p>To execute this script during log-in I have added this to my ~/.bashrc:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># GPG-AGENT stuff</span>
<span style="color: #007800;">GET_TTY</span>=<span style="color: #000000; font-weight: bold;">`</span>tty<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">$GET_TTY</span>
<span style="color: #007800;">$HOME</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>gpg-agent-start.sh</pre></div></div>

<p>I still wonder why it works that easy on Debian and on Fedora i need all this scripting. But for the moment I&#8217;m just happy that I have found a solution to use my smartcard for SSH login on my Fedora systems.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.schiessle.org/2009/05/12/fedora-and-gpg-agent/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
