#!/bin/sh # This script is a template for a self modifiying script # License: LGPLv2 # Change the following to whatever # method updates your script, for e.g. # svn update $0 proc update_method { return } # Note the exec must be read from disk # before updated_method is called, hence # why update_this_script is in a function. proc update_this_script { global old_md5 := $[md5sum $0 | cut -d' ' -f1] update_method global new_md5 := $[md5sum $0 | cut -d' ' -f1] if test $old_md5 != $new_md5 { exec $0 @Argv } } update_this_script echo "rest of script here" (CommandList children: [ (FuncDef name: update_method body: (BraceGroup children:[(ControlFlow token:)] spids:[25]) spids: [21 24] ) (FuncDef name: update_this_script body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:old_md5) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(md5sum)} {($ VSub_Number "$0")}) (C {(cut)} {(-d) (SQ <" ">)} {(-f1)}) ] negated: False ) ] ) left_token: spids: [49 64] ) } spids: [48] ) ] spids: [48] ) (C {(update_method)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:new_md5) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(md5sum)} {($ VSub_Number "$0")}) (C {(cut)} {(-d) (SQ <" ">)} {(-f1)}) ] negated: False ) ] ) left_token: spids: [71 86] ) } spids: [70] ) ] spids: [70] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$old_md5"))} {(KW_Bang "!") (Lit_Other "=")} {(DQ ($ VSub_Name "$new_md5"))} {(Lit_Other "]")} ) terminator: ) ] action: [(C {(exec)} {($ VSub_Number "$0")} {(DQ ($ VSub_At "$@"))})] spids: [-1 107] ) ] spids: [-1 119] ) ] spids: [45] ) spids: [41 44] ) (C {(update_this_script)}) (C {(echo)} {(DQ ("rest of script here"))}) ] )