Last active
March 17, 2020 08:46
-
-
Save kou1okada/bd80f3f787211e735d693ac7e7611d37 to your computer and use it in GitHub Desktop.
mountbsd.sh: Mount diskimage with BSD disklabel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
source hhs.bash 0.2.0 | |
function optparse_mountbsd () | |
{ | |
case "$1" in | |
-m|--mount-point) # <mountpoint> | |
# set mount point | |
nparams 1 | |
optset M "$2" | |
;; | |
*) return 1 ;; | |
esac | |
} | |
function mountbsd () # [<diskimage>] | |
# Mount diskimage with BSD disklabel | |
{ | |
disktype "$1" \ | |
| gawk -vfn="$1" -vmp="${OPT_M:-/mnt}" ' | |
function mountable(t) { | |
return t==0||t==1 ? "#" : ""; | |
} | |
function type(t) { | |
if (t==0) return "unused"; | |
if (t==1) return "swap"; | |
if (t==7) return "44bsd"; | |
return "unknown"; | |
} | |
match($0, /^ *Partition ([0-9]+):.*[^0-9]([0-9]+) bytes,.* from ([0-9]+)/, m) { | |
slice = m[1]; | |
} | |
match($0, /^ *Partition ([a-z]+):.*[^0-9]([0-9]+) bytes,.* from ([0-9]+)/, m) { | |
partition = m[1]; | |
sizelimit = m[2]; | |
offset = 512*m[3]; | |
} | |
match($0, /^ *Type *([0-9]+) *\((.*)\)/, m) { | |
typeno = m[1]; | |
typedsc = m[2]; | |
s = s sep mountable(typeno) sprintf(\ | |
"sudo mount -tufs -oro,ufstype=%s,offset=%d,sizelimit=%d \"%s\" %s", | |
type(typeno), | |
offset, | |
sizelimit, | |
fn, | |
mp); | |
sep = "\n"; | |
} | |
match($0, /^ *Last mounted at "(.*)"/, m) { | |
mountpoint = m[1]; | |
s = s mountpoint; | |
} | |
END { | |
print s"\n"; | |
} | |
' | |
} | |
invoke_command "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment