#!/bin/bash # Copyright 2010 Rob Landley licensed under GPLv2 if test $1 == "-d" { global DELETE := '1' shift } # Clean up a chroot directory global ZAP := $[readlink -f $1 !2 >/dev/null] if test ! -d $ZAP { echo "usage: zapchroot [-d] dirname" exit 1 } global i := $[readlink -f $[pwd]] if test $ZAP == $(i:0:${#ZAP}) { echo "Sanity check failed: cwd is under zapdir" > !2 exit 1 } # Iterate through the second entry of /proc/mounts in reverse order for i in [$[awk '{print $2}' /proc/mounts | tac]] { # De-escape octal versions of space, tab, backslash, newline... global i := $[echo -e $i] # Skip entries that aren't under our chroot test $ZAP != $(i:0:${#ZAP}) && continue echo "Umounting: $i" umount $i } (CommandList children: [ (If arms: [ (if_arm cond: [ (C {(Lit_Other "[")} {(DQ ($ VSub_Number "$1"))} {(Lit_Other "=") (Lit_Other "=")} {(DQ (-d))} {(Lit_Other "]")} ) ] action: [ (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:DELETE) op:Equal rhs:{(1)} spids:[28])] spids: [28] ) (C {(shift)}) ] spids: [-1 25] ) ] spids: [-1 34] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:ZAP) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (SimpleCommand words: [{(readlink)} {(-f)} {(DQ ($ VSub_Number "$1"))}] redirects: [(Redir op_id:Redir_Great fd:2 arg_word:{(/dev/null)} spids:[51])] ) ] ) left_token: spids: [42 53] ) } spids: [41] ) ] spids: [41] ) (If arms: [ (if_arm cond: [ (C {(Lit_Other "[")} {(KW_Bang "!")} {(-d)} {(DQ ($ VSub_Name "$ZAP"))} {(Lit_Other "]")}) ] action: [(C {(echo)} {(DQ ("usage: zapchroot [-d] dirname"))}) (C {(exit)} {(1)})] spids: [-1 70] ) ] spids: [-1 84] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:i) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children: [ (C {(readlink)} {(-f)} { (DQ (CommandSubPart command_list: (CommandList children:[(C {(pwd)})]) left_token: spids: [95 97] ) ) } ) ] ) left_token: spids: [89 99] ) ) } spids: [87] ) ] spids: [87] ) (If arms: [ (if_arm cond: [ (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$ZAP"))} {(Lit_Other "=") (Lit_Other "=")} { (DQ (BracedVarSub token: suffix_op: (Slice begin: (ArithWord w:{(Lit_Digits 0)}) length: (ArithWord w: { (BracedVarSub token: prefix_op: VSub_Pound spids: [119 122] ) } ) ) spids: [114 123] ) ) } {(Lit_Other "]")} ) ] action: [ (SimpleCommand words: [{(echo)} {(DQ ("Sanity check failed: cwd is under zapdir"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[137])] ) (C {(exit)} {(1)}) ] spids: [-1 128] ) ] spids: [-1 145] ) (ForEach iter_name: i iter_words: [ { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [(C {(awk)} {(SQ <"{print $2}">)} {(/proc/mounts)}) (C {(tac)})] negated: False ) ] ) left_token: spids: [158 170] ) } ] do_arg_iter: False body: (DoGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:i) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [(C {(echo)} {(-e)} {(DQ ($ VSub_Name "$i"))})] ) left_token: spids: [180 188] ) } spids: [179] ) ] spids: [179] ) (AndOr children: [ (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$ZAP"))} {(KW_Bang "!") (Lit_Other "=")} { (DQ (BracedVarSub token: suffix_op: (Slice begin: (ArithWord w:{(Lit_Digits 0)}) length: (ArithWord w: { (BracedVarSub token: prefix_op: VSub_Pound spids: [211 214] ) } ) ) spids: [206 215] ) ) } {(Lit_Other "]")} ) (ControlFlow token:) ] op_id: Op_DAmp ) (C {(echo)} {(DQ ("Umounting: ") ($ VSub_Name "$i"))}) (C {(umount)} {(DQ ($ VSub_Name "$i"))}) ] spids: [172 240] ) spids: [157 -1] ) ] )