<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<atom:link href="https://dev1galaxy.org/extern.php?action=feed&amp;tid=4018&amp;type=rss" rel="self" type="application/rss+xml" />
		<title><![CDATA[Dev1 Galaxy Forum / dd command inside script.]]></title>
		<link>https://dev1galaxy.org/viewtopic.php?id=4018</link>
		<description><![CDATA[The most recent posts in dd command inside script..]]></description>
		<lastBuildDate>Tue, 29 Dec 2020 11:56:01 +0000</lastBuildDate>
		<generator>FluxBB</generator>
		<item>
			<title><![CDATA[Re: dd command inside script.]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=26479#p26479</link>
			<description><![CDATA[<p>Thanks head on a stick, i forgot to do that. This has been a good learning experience and its good to make mistakes and learn from them. I will definitely be looking into more posix orientated scripts in the future. Updated the script as per shellcheck.</p>]]></description>
			<author><![CDATA[dummy@example.com (dice)]]></author>
			<pubDate>Tue, 29 Dec 2020 11:56:01 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=26479#p26479</guid>
		</item>
		<item>
			<title><![CDATA[Re: dd command inside script.]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=26478#p26478</link>
			<description><![CDATA[<p>Thought it better to post this here rather than pollute your <a href="http://dev1galaxy.org/viewtopic.php?pid=26476#p26476" rel="nofollow">new thread</a> but just to let you know that <a href="https://shellcheck.net" rel="nofollow">https://shellcheck.net</a> thinks you should double-quote the variables:</p><div class="codebox"><pre class="vscroll"><code>Line 13:
        mkdir -p /home/${u}/${dir}
                       ^-- SC2086: Double quote to prevent globbing and word splitting.
                            ^-- SC2086: Double quote to prevent globbing and word splitting.

Did you mean: (apply this, apply all SC2086)
        mkdir -p /home/&quot;${u}&quot;/&quot;${dir}&quot;
 
Line 19:
        dd if=/dev/urandom of=${outfile} bs=${blocksize} count=1 iflag=fullblock
                              ^-- SC2086: Double quote to prevent globbing and word splitting.
                                            ^-- SC2086: Double quote to prevent globbing and word splitting.

Did you mean: (apply this, apply all SC2086)
        dd if=/dev/urandom of=&quot;${outfile}&quot; bs=&quot;${blocksize}&quot; count=1 iflag=fullblock
 
Line 27:
        losetup ${LOOPDEV} ${img}
                ^-- SC2086: Double quote to prevent globbing and word splitting.
                           ^-- SC2086: Double quote to prevent globbing and word splitting.

Did you mean: (apply this, apply all SC2086)
        losetup &quot;${LOOPDEV}&quot; &quot;${img}&quot;
 
Line 28:
        cryptsetup luksFormat ${img}
                              ^-- SC2086: Double quote to prevent globbing and word splitting.

Did you mean: (apply this, apply all SC2086)
        cryptsetup luksFormat &quot;${img}&quot;
 
Line 29:
        cryptsetup open ${img} ${name}
                        ^-- SC2086: Double quote to prevent globbing and word splitting.
                               ^-- SC2086: Double quote to prevent globbing and word splitting.

Did you mean: (apply this, apply all SC2086)
        cryptsetup open &quot;${img}&quot; &quot;${name}&quot;
 
Line 30:
        mkfs.ext4 /dev/mapper/${name}
                              ^-- SC2086: Double quote to prevent globbing and word splitting.

Did you mean: (apply this, apply all SC2086)
        mkfs.ext4 /dev/mapper/&quot;${name}&quot;
 
Line 36:
        cryptsetup open ${img} ${name}
                        ^-- SC2086: Double quote to prevent globbing and word splitting.
                               ^-- SC2086: Double quote to prevent globbing and word splitting.

Did you mean: (apply this, apply all SC2086)
        cryptsetup open &quot;${img}&quot; &quot;${name}&quot;
 
Line 42:
        mount -t ext4 /dev/mapper/${name} /home/${u}/${dir}
                                  ^-- SC2086: Double quote to prevent globbing and word splitting.
                                                ^-- SC2086: Double quote to prevent globbing and word splitting.
                                                     ^-- SC2086: Double quote to prevent globbing and word splitting.

Did you mean: (apply this, apply all SC2086)
        mount -t ext4 /dev/mapper/&quot;${name}&quot; /home/&quot;${u}&quot;/&quot;${dir}&quot;
 
Line 49:
        umount /home/${u}/${dir}
                     ^-- SC2086: Double quote to prevent globbing and word splitting.
                          ^-- SC2086: Double quote to prevent globbing and word splitting.

Did you mean: (apply this, apply all SC2086)
        umount /home/&quot;${u}&quot;/&quot;${dir}&quot;
 
Line 50:
        cryptsetup close ${name}
                         ^-- SC2086: Double quote to prevent globbing and word splitting.

Did you mean: (apply this, apply all SC2086)
        cryptsetup close &quot;${name}&quot;</code></pre></div><p>Oh, and I&#039;m pleased to see that you&#039;ve dropped bloaty old bash — POSIX sh ftw! :-)</p>]]></description>
			<author><![CDATA[dummy@example.com (Head_on_a_Stick)]]></author>
			<pubDate>Tue, 29 Dec 2020 10:31:56 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=26478#p26478</guid>
		</item>
		<item>
			<title><![CDATA[Re: dd command inside script.]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=26471#p26471</link>
			<description><![CDATA[<div class="quotebox"><cite>fsmithred wrote:</cite><blockquote><div><p>It looks like it worked. The previous error is gone. Maybe loop1 is left from before? I think you can just delete it manually.</p></div></blockquote></div><p>that seems to be the case. Thanks again.</p>]]></description>
			<author><![CDATA[dummy@example.com (dice)]]></author>
			<pubDate>Tue, 29 Dec 2020 01:03:15 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=26471#p26471</guid>
		</item>
		<item>
			<title><![CDATA[Re: dd command inside script.]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=26456#p26456</link>
			<description><![CDATA[<div class="quotebox"><cite>OalSkuul wrote:</cite><blockquote><div><p>what is it for?</p></div></blockquote></div><p>See <a href="https://manpages.debian.org/buster/manpages/urandom.4.en.html" rel="nofollow">random(4)</a>. If you have any other questions then please open a new thread rather than hijack this one, thanks.</p>]]></description>
			<author><![CDATA[dummy@example.com (Head_on_a_Stick)]]></author>
			<pubDate>Mon, 28 Dec 2020 21:52:11 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=26456#p26456</guid>
		</item>
		<item>
			<title><![CDATA[Re: dd command inside script.]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=26454#p26454</link>
			<description><![CDATA[<p>Admin, please delete.</p>]]></description>
			<author><![CDATA[dummy@example.com (OalSkuul)]]></author>
			<pubDate>Mon, 28 Dec 2020 19:33:39 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=26454#p26454</guid>
		</item>
		<item>
			<title><![CDATA[Re: dd command inside script.]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=26453#p26453</link>
			<description><![CDATA[<p>It looks like it worked. The previous error is gone. Maybe loop1 is left from before? I think you can just delete it manually.</p>]]></description>
			<author><![CDATA[dummy@example.com (fsmithred)]]></author>
			<pubDate>Mon, 28 Dec 2020 18:03:32 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=26453#p26453</guid>
		</item>
		<item>
			<title><![CDATA[Re: dd command inside script.]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=26452#p26452</link>
			<description><![CDATA[<p>still showing two loop devices, thanks for your help though.</p><div class="codebox"><pre class="vscroll"><code> ~ $ &gt; sudo ./ccreate.sh -c test.img
+ img=test.img
+ getopts :c opt
+ case &quot;${opt}&quot; in
+ crypt_create test.img
+ losetup -f
++ cat /tmp/nextloop
+ LOOPDEV=/dev/loop0
+ losetup /dev/loop0 test.img
+ cryptsetup luksFormat test.img

WARNING!
========
This will overwrite data on test.img irrevocably.

Are you sure? (Type &#039;yes&#039; in capital letters): YES
Enter passphrase for test.img:
Verify passphrase:
+ cryptsetup open test.img cryptfs
Enter passphrase for test.img:
+ mkfs.ext4 /dev/mapper/cryptfs
mke2fs 1.45.6 (20-Mar-2020)
Creating filesystem with 4096 1k blocks and 1024 inodes

Allocating group tables: done
Writing inode tables: done
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: done

+ getopts :c opt</code></pre></div><div class="codebox"><pre><code> ~ $ &gt; lsblk
NAME           MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
loop0            7:0    0    20M  0 loop
loop1            7:1    0    20M  0 loop
└─cryptfs      254:1    0     4M  0 crypt</code></pre></div><div class="codebox"><pre><code>#!/bin/bash
set -x
img=&quot;$2&quot;

crypt_create () {
        losetup -f &gt; /tmp/nextloop
        LOOPDEV=$(cat /tmp/nextloop)
        losetup ${LOOPDEV} $img
        cryptsetup luksFormat $img
        cryptsetup open $img cryptfs
        mkfs.ext4 /dev/mapper/cryptfs
}

while getopts &quot;:c&quot; opt; do
    case &quot;${opt}&quot; in
        c ) crypt_create $2
        ;;
       \? ) echo &quot;Usage: cmd [c]&quot;
        ;;
    esac
done</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (dice)]]></author>
			<pubDate>Mon, 28 Dec 2020 15:20:51 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=26452#p26452</guid>
		</item>
		<item>
			<title><![CDATA[Re: dd command inside script.]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=26451#p26451</link>
			<description><![CDATA[<p>You got this output for the line that says <span class="bbc">losetup ${LOOPDEV} $img</span> but there&#039;s nothing for $LOOPDEV in the output. &quot;No such device.&quot; The error also shows up in the first lines of the output where it shows that cat failed and LOOPDEV is empty.</p><div class="codebox"><pre><code>+ losetup test.img
losetup: test.img: failed to use device: No such device</code></pre></div><p>I think you need to define LOOPDEV after you run &#039;losetup -f&#039;.</p><div class="codebox"><pre><code>crypt_create () {
        losetup -f &gt; /tmp/nextloop
        LOOPDEV=$(cat /tmp/nextloop)
        losetup ${LOOPDEV} $img
        cryptsetup luksFormat $img
        cryptsetup open $img cryptfs
        mkfs.ext4 /dev/mapper/cryptfs
}</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (fsmithred)]]></author>
			<pubDate>Mon, 28 Dec 2020 14:56:13 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=26451#p26451</guid>
		</item>
		<item>
			<title><![CDATA[Re: dd command inside script.]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=26450#p26450</link>
			<description><![CDATA[<p>You should also be quoting your variables to avoid globbing and word substitution.</p><p><a href="https://mywiki.wooledge.org/Quotes" rel="nofollow">https://mywiki.wooledge.org/Quotes</a></p>]]></description>
			<author><![CDATA[dummy@example.com (Head_on_a_Stick)]]></author>
			<pubDate>Mon, 28 Dec 2020 14:42:24 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=26450#p26450</guid>
		</item>
		<item>
			<title><![CDATA[Re: dd command inside script.]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=26449#p26449</link>
			<description><![CDATA[<div class="quotebox"><cite>Head_on_a_Stick wrote:</cite><blockquote><div><div class="quotebox"><cite>dice wrote:</cite><blockquote><div><div class="codebox"><pre><code>    i ) crypt_img $2 $3</code></pre></div></div></blockquote></div><p>I think that should be</p><div class="codebox"><pre><code>    i) crypt_img &quot;$@&quot;</code></pre></div><p>Otherwise <span class="bbc">$2</span> &amp; <span class="bbc">$3</span> will be interpreted as the third and forth arguments applied to the script.</p><p>Not sure about the encryption stuff though, I don&#039;t use that.</p></div></blockquote></div><p>Yes that seems to work as well. Im having a hard time wrapping my head around this stuff, thanks.</p>]]></description>
			<author><![CDATA[dummy@example.com (dice)]]></author>
			<pubDate>Mon, 28 Dec 2020 13:24:03 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=26449#p26449</guid>
		</item>
		<item>
			<title><![CDATA[Re: dd command inside script.]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=26448#p26448</link>
			<description><![CDATA[<div class="quotebox"><cite>fsmithred wrote:</cite><blockquote><div><p>If you somehow end up with more than one loop device, you might use something like this:</p><div class="codebox"><pre><code>losetup -f &gt; /tmp/nextloop
LOOPDEV=$(cat /tmp/nextloop)

losetup ${LOOPDEV} ${LOOP_FILENAME}</code></pre></div><p>That&#039;s taken from refracta2usb which can make an encrypted loopback filesystem for live-usb persistence.</p></div></blockquote></div><p>Hi fsmithred, if you see this would you say this is the right way to implement loopdev?</p><p>here is just the code to the cryptsetup commands, im yet to figure out how to use that in the main script.</p><div class="codebox"><pre><code>#!/bin/bash
set -x
LOOPDEV=$(cat /tmp/nextloop)
img=&quot;$2&quot;

crypt_create () {
        losetup -f &gt; /tmp/nextloop
        losetup ${LOOPDEV} $img
        cryptsetup luksFormat $img
        cryptsetup open $img cryptfs
        mkfs.ext4 /dev/mapper/cryptfs
}

while getopts &quot;:c&quot; opt; do
    case &quot;${opt}&quot; in
        c ) crypt_create $2
        ;;
       \? ) echo &quot;Usage: cmd [c]&quot;
        ;;
    esac
done</code></pre></div><p>seems to work although set -x throws some errors?</p><p>sudo ./ccreate.sh -c test.img</p><div class="codebox"><pre class="vscroll"><code>++ cat /tmp/nextloop
cat: /tmp/nextloop: No such file or directory
+ LOOPDEV=
+ img=test.img
+ getopts :c opt
+ case &quot;${opt}&quot; in
+ crypt_create test.img
+ crypt_create test.img
+ losetup -f
+ losetup test.img
losetup: test.img: failed to use device: No such device
+ cryptsetup luksFormat test.img

WARNING!
========
This will overwrite data on test.img irrevocably.

Are you sure? (Type &#039;yes&#039; in capital letters): YES
Enter passphrase for test.img:
Verify passphrase:
+ cryptsetup open test.img cryptfs
Enter passphrase for test.img:
+ mkfs.ext4 /dev/mapper/cryptfs
mke2fs 1.45.6 (20-Mar-2020)
Creating filesystem with 4096 1k blocks and 1024 inodes

Allocating group tables: done
Writing inode tables: done
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: done

+ getopts :c opt</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (dice)]]></author>
			<pubDate>Mon, 28 Dec 2020 13:19:24 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=26448#p26448</guid>
		</item>
		<item>
			<title><![CDATA[Re: dd command inside script.]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=26446#p26446</link>
			<description><![CDATA[<div class="quotebox"><cite>dice wrote:</cite><blockquote><div><div class="codebox"><pre><code>    i ) crypt_img $2 $3</code></pre></div></div></blockquote></div><p>I think that should be</p><div class="codebox"><pre><code>    i) crypt_img &quot;$@&quot;</code></pre></div><p>Otherwise <span class="bbc">$2</span> &amp; <span class="bbc">$3</span> will be interpreted as the third and forth arguments applied to the script.</p><p>Not sure about the encryption stuff though, I don&#039;t use that.</p>]]></description>
			<author><![CDATA[dummy@example.com (Head_on_a_Stick)]]></author>
			<pubDate>Mon, 28 Dec 2020 12:40:25 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=26446#p26446</guid>
		</item>
		<item>
			<title><![CDATA[Re: dd command inside script.]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=26442#p26442</link>
			<description><![CDATA[<p>Managed to cobble this together, not in anyway portable but ill keep trying.<br />something interesting i found out, luks header keys takes up 16 mb of space so you cant have have a small img like 10mb.</p><div class="codebox"><pre><code>NAME           MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
loop0            7:0    0    20M  0 loop
└─cryptfs      254:1    0     4M  0 crypt /home/$u/crypt</code></pre></div><p>Need to look into better command structure using more positional parameters, especially with the use of the crypt.img?<br />Find out how to use getopts usage better.</p><div class="codebox"><pre class="vscroll"><code>#!/bin/bash
set -x
u=&quot;&lt;username&gt;&quot;
outfile=&quot;$2&quot;
blocksize=&quot;$3&quot;

crypt_img () {
	dd if=/dev/urandom of=$outfile bs=$blocksize count=1 iflag=fullblock
}

crypt_create () {
	losetup --find
	losetup /dev/loop0 crypt.img
	cryptsetup luksFormat crypt.img
	cryptsetup open crypt.img cryptfs
	mkfs.ext4 /dev/mapper/cryptfs
}

crypt_open () {
	cryptsetup open crypt.img cryptfs
}

crypt_mount () {
	mount -t ext4 /dev/mapper/cryptfs /home/$u/crypt
}

crypt_umount () {
	umount /home/$u/crypt
	cryptsetup close cryptfs
	losetup -d /dev/loop0
}

while getopts &quot;:iComu&quot; opt; do
  case ${opt} in
    i ) crypt_img $2 $3
      ;;
    C ) crypt_create
      ;;
    o ) crypt_open
      ;;
    m ) crypt_mount
      ;;
    u ) crypt_umount
      ;;
    \? ) echo &quot;Usage: cmd [-i] [-C] [-o] [-m] [-u]&quot;
      ;;
  esac
done</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (dice)]]></author>
			<pubDate>Mon, 28 Dec 2020 09:59:47 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=26442#p26442</guid>
		</item>
		<item>
			<title><![CDATA[Re: dd command inside script.]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=26440#p26440</link>
			<description><![CDATA[<p>thanks chris, set -x is quite helpful.</p><p>thanks fsmithred, that is exactly where i am stuck right now having two loop devices. </p><p>This not anything serious btw, just trying to learn. Think i would rather use tomb to be quite honest <img src="https://dev1galaxy.org/img/smilies/wink.png" width="15" height="15" alt="wink" /></p>]]></description>
			<author><![CDATA[dummy@example.com (dice)]]></author>
			<pubDate>Mon, 28 Dec 2020 03:03:21 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=26440#p26440</guid>
		</item>
		<item>
			<title><![CDATA[Re: dd command inside script.]]></title>
			<link>https://dev1galaxy.org/viewtopic.php?pid=26438#p26438</link>
			<description><![CDATA[<p>If you somehow end up with more than one loop device, you might use something like this:</p><div class="codebox"><pre><code>losetup -f &gt; /tmp/nextloop
LOOPDEV=$(cat /tmp/nextloop)

losetup ${LOOPDEV} ${LOOP_FILENAME}</code></pre></div><p>That&#039;s taken from refracta2usb which can make an encrypted loopback filesystem for live-usb persistence.</p>]]></description>
			<author><![CDATA[dummy@example.com (fsmithred)]]></author>
			<pubDate>Sun, 27 Dec 2020 23:19:14 +0000</pubDate>
			<guid>https://dev1galaxy.org/viewtopic.php?pid=26438#p26438</guid>
		</item>
	</channel>
</rss>
