-
Notifications
You must be signed in to change notification settings - Fork 0
/
op.func
38 lines (37 loc) · 1.25 KB
/
op.func
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
#!/bin/bash
test ! -e "${DISK:-}" && DISK=tcl-usb.disk
lodn() { sudo losetup -D; }
loup() { sudo losetup --show -Pf $DISK; }
gtlo() { losetup -l | sed -ne "s,\([0-9]*\) .*$DISK .*,\1,p"; }
lols() { losetup -l | grep -ve "\.snap "; }
pm() { sudo mount -vo uid=${USER:-0} $(gtlo)p${1:-1} ${2:-dir}; }
pu() { sudo umount -v $(gtlo)p${1:-1}; }
gp() { sudo gparted $(gtlo); }
pt() { sudo fdisk -l $(gtlo); }
pe() { sudo fdisk -w never $(gtlo); }
fk() { sudo fsck -y $(gtlo)p${1:-1}; }
pz() {
#set -x
local n=${1:-1}
tmpdir=$(mktemp -d)
pm $n "$tmpdir" || return 1
dd if=/dev/zero bs=1M of="$tmpdir/z" 2>&1 |\
grep -ve records -ve "o space left o"
sync "$tmpdir/z"; rm -f "$tmpdir/z"
pu $n; rmdir $tmpdir
#set +x
}
dz() { local i=${1:-$DISK}; pigz -9cp8 $i >$i.gz; du -ks $i.gz; }
dx() { local a=${1:-$DISK}; a=${a%\.gz}; pigz -cdp8 $a.gz >$a; du -ms $a; }
ds() {
local target="tcl-skeleton.disk.gz"
local testsz="tcl-skeleton-$1.disk.gz"
if [ -n "$1" -a -e $testsz ]; then
ln -svf $testsz $target | tr -d \'
return $?
fi
test -e "$DISK.gz" || dz $DISK || return 1
ln -svf $DISK.gz $target | tr -d \'
}
de() { echo $DISK; }
op.stop() { unset -f ilodn loup gtlo lols pm pu gp pt pe fk pz dz dx ds de op.stop; }