#!/bin/sh set -x global MOUNTPOINT := $1 test -z $MOUNTPOINT && echo "No mountpoint specified" && exit 1 mkdir -p $MOUNTPOINT proc mount_drive { # TODO fix for multiple disks, cdroms etc global DEVS := $[find /dev -maxdepth 1 -type b ! -name 'loop*' ! -name 'nbd*' | grep -v '[0-9]$' | sed 's@.*/dev/@@' | sort] for DEV in [$DEVS] { global DRIVE := ""/dev/$(DEV)"" # see if it has a partition table if sfdisk -d $(DRIVE) >/dev/null !2 >/dev/null { # 83 is Linux partition identifier global DATA := $[sfdisk -J $DRIVE | jq -e -r '.partitiontable.partitions | map(select(.type=="83")) | .[0].node] if test $Status -eq 0 { mount $DATA $MOUNTPOINT && return } } } echo "WARNING: Failed to mount a persistent volume (is there one?)" } mount_drive (CommandList children: [ (C {(set)} {(-x)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:MOUNTPOINT) op: Equal rhs: {(DQ ($ VSub_Number "$1"))} spids: [9] ) ] spids: [9] ) (AndOr children: [ (C {(Lit_Other "[")} {(-z)} {(DQ ($ VSub_Name "$MOUNTPOINT"))} {(Lit_Other "]")}) (AndOr children: [(C {(echo)} {(DQ ("No mountpoint specified"))}) (C {(exit)} {(1)})] op_id: Op_DAmp ) ] op_id: Op_DAmp ) (C {(mkdir)} {(-p)} {(DQ ($ VSub_Name "$MOUNTPOINT"))}) (FuncDef name: mount_drive body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:DEVS) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(find)} {(/dev)} {(-maxdepth)} {(1)} {(-type)} {(b)} {(KW_Bang "!")} {(-name)} {(SQ <"loop*">)} {(KW_Bang "!")} {(-name)} {(SQ <"nbd*">)} ) (C {(grep)} {(-v)} {(SQ <"[0-9]$">)}) (C {(sed)} {(SQ <"s@.*/dev/@@">)}) (C {(sort)}) ] negated: False ) ] ) left_token: spids: [62 112] ) ) } spids: [60] ) ] spids: [60] ) (ForEach iter_name: DEV iter_words: [{($ VSub_Name "$DEVS")}] do_arg_iter: False body: (DoGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:DRIVE) op: Equal rhs: {(DQ (/dev/) (${ VSub_Name DEV))} spids: [129] ) ] spids: [129] ) (If arms: [ (if_arm cond: [ (SimpleCommand words: [{(sfdisk)} {(-d)} {(DQ (${ VSub_Name DRIVE))}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [155] ) (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [158] ) ] ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:DATA) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(sfdisk)} {(-J)} {(DQ ($ VSub_Name "$DRIVE"))}) (C {(jq)} {(-e)} {(-r)} { (SQ < ".partitiontable.partitions | map(select(.type==\"83\")) | .[0].node" > ) } ) ] negated: False ) ] ) left_token: spids: [170 190] ) } spids: [169] ) ] spids: [169] ) (If arms: [ (if_arm cond: [ (C {(Lit_Other "[")} {($ VSub_QMark "$?")} {(-eq)} {(0)} {(Lit_Other "]")} ) ] action: [ (AndOr children: [ (C {(mount)} {(DQ ($ VSub_Name "$DATA"))} {(DQ ($ VSub_Name "$MOUNTPOINT"))} ) (ControlFlow token: ) ] op_id: Op_DAmp ) ] spids: [-1 206] ) ] spids: [-1 224] ) ] spids: [-1 162] ) ] spids: [-1 227] ) ] spids: [126 230] ) spids: [122 -1] ) (C {(echo)} {(DQ ("WARNING: Failed to mount a persistent volume (is there one?)"))}) ] spids: [53] ) spids: [49 52] ) (C {(mount_drive)}) ] )