#! /bin/sh ### BEGIN INIT INFO # Provides: hostname # Required-Start: # Required-Stop: # Should-Start: glibc # Default-Start: S # Default-Stop: # Short-Description: Set hostname based on /etc/hostname # Description: Read the machines hostname from /etc/hostname, and # update the kernel value with this value. If # /etc/hostname is empty, the current kernel value # for hostname is used. If the kernel value is # empty, the value 'localhost' is used. ### END INIT INFO global PATH := '/sbin:/bin' source /lib/init/vars.sh source /lib/lsb/init-functions proc do_start { test -f /etc/hostname && global HOSTNAME := $[cat /etc/hostname] # Keep current name if /etc/hostname is missing. test -z $HOSTNAME && global HOSTNAME := $[hostname] # And set it to 'localhost' if no setting was found test -z $HOSTNAME && global HOSTNAME := 'localhost' test $VERBOSE != no && log_action_begin_msg "Setting hostname to '$HOSTNAME'" hostname $HOSTNAME global ES := $Status test $VERBOSE != no && log_action_end_msg $ES exit $ES } proc do_status { global HOSTNAME := $[hostname] if test $HOSTNAME { return 0 } else { return 4 } } matchstr $1 { start|"" { do_start } restart|reload|force-reload { echo "Error: argument '$1' not supported" > !2 exit 3 } stop { # No-op } status { do_status exit $Status } * { echo "Usage: hostname.sh [start|stop]" > !2 exit 3 } } : (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:PATH) op: Equal rhs: {(/sbin) (Lit_Other ":") (/bin)} spids: [46] ) ] spids: [46] ) (C {(.)} {(/lib/init/vars.sh)}) (C {(.)} {(/lib/lsb/init-functions)}) (FuncDef name: do_start body: (BraceGroup children: [ (AndOr children: [ (C {(Lit_Other "[")} {(-f)} {(/etc/hostname)} {(Lit_Other "]")}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:HOSTNAME) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children:[(C {(cat)} {(/etc/hostname)})]) left_token: spids: [81 85] ) ) } spids: [79] ) ] spids: [79] ) ] op_id: Op_DAmp ) (AndOr children: [ (C {(Lit_Other "[")} {(-z)} {(DQ ($ VSub_Name "$HOSTNAME"))} {(Lit_Other "]")}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:HOSTNAME) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children:[(C {(hostname)})]) left_token: spids: [108 110] ) ) } spids: [106] ) ] spids: [106] ) ] op_id: Op_DAmp ) (AndOr children: [ (C {(Lit_Other "[")} {(-z)} {(DQ ($ VSub_Name "$HOSTNAME"))} {(Lit_Other "]")}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:HOSTNAME) op: Equal rhs: {(localhost)} spids: [131] ) ] spids: [131] ) ] op_id: Op_DAmp ) (AndOr children: [ (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$VERBOSE"))} {(KW_Bang "!") (Lit_Other "=")} {(no)} {(Lit_Other "]")} ) (C {(log_action_begin_msg)} {(DQ ("Setting hostname to '") ($ VSub_Name "$HOSTNAME") ("'"))} ) ] op_id: Op_DAmp ) (C {(hostname)} {(DQ ($ VSub_Name "$HOSTNAME"))}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:ES) op: Equal rhs: {($ VSub_QMark "$?")} spids: [167] ) ] spids: [167] ) (AndOr children: [ (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$VERBOSE"))} {(KW_Bang "!") (Lit_Other "=")} {(no)} {(Lit_Other "]")} ) (C {(log_action_end_msg)} {($ VSub_Name "$ES")}) ] op_id: Op_DAmp ) (C {(exit)} {($ VSub_Name "$ES")}) ] spids: [66] ) spids: [61 65] ) (FuncDef name: do_status body: (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:HOSTNAME) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(hostname)})]) left_token: spids: [207 209] ) } spids: [206] ) ] spids: [206] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ ($ VSub_Name "$HOSTNAME"))} {(Lit_Other "]")}) terminator: ) ] action: [(ControlFlow token: arg_word:{(0)})] spids: [-1 224] ) ] else_action: [(ControlFlow token: arg_word:{(4)})] spids: [232 240] ) ] spids: [203] ) spids: [198 202] ) (Case to_match: {(DQ ($ VSub_Number "$1"))} arms: [ (case_arm pat_list:[{(start)}{(DQ )}] action:[(C {(do_start)})] spids:[254258264-1]) (case_arm pat_list: [{(restart)} {(reload)} {(force-reload)}] action: [ (SimpleCommand words: [{(echo)} {(DQ ("Error: argument '") ($ VSub_Number "$1") ("' not supported"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[283])] ) (C {(exit)} {(3)}) ] spids: [267 272 292 -1] ) (case_arm pat_list:[{(stop)}] spids:[295296303-1]) (case_arm pat_list: [{(status)}] action: [(C {(do_status)}) (C {(exit)} {($ VSub_QMark "$?")})] spids: [306 307 318 -1] ) (case_arm pat_list: [{(Lit_Other "*")}] action: [ (SimpleCommand words: [{(echo)} {(DQ ("Usage: hostname.sh [start|stop]"))}] redirects: [(Redir op_id:Redir_GreatAnd fd:-1 arg_word:{(2)} spids:[331])] ) (C {(exit)} {(3)}) ] spids: [321 322 340 -1] ) ] spids: [245 251 342] ) (C {(Lit_Other ":")}) ] )