Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /system script add comment="=SYS-ROS-STARTUP=" dont-require-permissions=no name=sys-ros-startup owner=admin policy=ftp,reboot,read,write,policy,test,sniff source="# ROS Start-up script [ ver. 2.3.6 ] \
- \n# Functions:\
- \n# 1. Update system note & log it to parse on remote syslog side;\
- \n# 2. Load necessery global variables;\
- \n# 3. Double reboot after ros upgrade;\
- \n# Require:\
- \n# 1. system identity must be set to reasonable value;\
- \n# 2. snmp settings must contain location field set to reasonable value;\
- \n# Links:\
- \n# https://wiki.mikrotik.com/wiki/Manual:Scripting\
- \n# https://wiki.mikrotik.com/wiki/Manual:Scripting_Tips_and_Trickss\
- \n# Dmitry Shevchenko - 11.11.2019\
- \n\
- \n# 0. Loading functions\
- \n:do { /system script run ros-functions } on-error={ \
- \n\t:log error ( \"sys-ros-startup: can't load necessery functions\" );\
- \n\t:error \"[ERR]: can't load necessery functions - inconsistent list of scrips\" ;\
- \n}\
- \n# 1. Global variables\
- \n# 1.1 Functions\
- \n:global funcIsFlash;\
- \n# 1.2 Importing global variables from file\
- \n:local globals \"globals.rsc\"\
- \n# 2. Local variables\
- \n# 2.2 System info\
- \n:local rbname [ /system resource get board-name ];\
- \n:local rbarch [ /system resource get architecture-name ];\
- \n:local rbcpun [ /system resource get cpu ];\
- \n:local rbcpuf [ /system resource get cpu-frequency ];\
- \n:local rbcpuc [ /system resource get cpu-count ];\
- \n:local rosver [ /system resource get version ];\
- \n:local roshnm [ /system identity get name ];\
- \n:local rbbldr [ /system routerboard get current-firmware ];\
- \n:local rblctn [ /snmp get value-name=location ];\
- \n# 2.3 System note file location\
- \n:local snlctn \"sys-note.txt\";\
- \n# 2.4 Second reboot after routerboard's bootloader upgrade \
- \n:local rbtFile \"ros-upgrade-once.txt\";\
- \n:local rbtDelay 180s;\
- \n# 2.5 Verbose output\
- \n:local VERBOSE false;\
- \n:local DEBUG;\
- \n\
- \n# 3. Main\
- \n# 3.0 Redefine file-paths\
- \n# TODO: Should parse \$rbname to detect which internal storage is used.\
- \nif ( [ \$funcIsFlash ] ) do={ \
- \n\t:set snlctn ( \"flash/\" . \$snlctn );\
- \n\t:set globals ( \"flash/\" . \$globals );\
- \n\t:set rbtFile ( \"flash/\" . \$rbtFile );\
- \n}\
- \n# 3.1 Allways create sys-note.txt (or upload it with initial configuration)\
- \n:system note print file=\$snlctn\
- \n# 3.2 System Info\
- \n:log info ( \"sys-ros-startup: BOARD \$rbname / LDR \$rbbldr / ROS \$rosver.\$rbarch #\$rbcpuc \$rbcpun (\$rbcpuf Mhz)\" );\
- \n# 3.3 Import global variables\
- \nif ( [ :len [ file find name=\"\$globals\" ] ] != 0 ) do={\
- \n\t:do { import \$globals } on-error={ :log error (\"sys-ros-startup: import of \$globals is failed\"); }\
- \n\t:log info ( \"sys-ros-startup: list of globals was imported successfully (\$globals)\" );\
- \n}\
- \n:if ( \$VERBOSE ) do={\
- \n\t:set DEBUG [ /system script environment find ];\
- \n\t:foreach item in=\$DEBUG do={\
- \n\t\t:local itemname [ /system script environment get \$item name ];\
- \n\t\t:local itemvalue [ /system script environment get \$item value ];\
- \n\t\t:log info ( \"startup,debug: \$itemname = \$itemvalue\" );\
- \n\t};\
- \n}\
- \n# 3.4 Update system note file\
- \n:if ( [ :len [ file find name=\"\$snlctn\" ] ] !=0 ) do={\
- \n\t:log info ( \"sys-ros-startup: update system note\" );\
- \n\t/system note set note=\"\\n[LOCATION]: \$rblctn (\$roshnm)\\n[HARDWARE]: BOARD \$rbname / LDR \$rbbldr / ROS \$rosver.\$rbarch #\$rbcpuc \$rbcpun (\$rbcpuf Mhz)\"\
- \n\t:file set \$snlctn contents=\"\\n[LOCATION]: \$rblctn (\$roshnm)\\n[HARDWARE]: BOARD \$rbname / LDR \$rbbldr / ROS \$rosver.\$rbarch #\$rbcpuc \$rbcpun (\$rbcpuf Mhz)\"\
- \n}\
- \n# 3.5 First-run after ROS-upgrade\
- \n:if ( [ :len [ file find name=\$rbtFile ] ] !=0 ) do={\
- \n\t:log warning ( \"sys-ros-startup: first run after ros upgrade\" );\
- \n\t:log info ( \"sys-ros-startup: reboot is scheduled in \$rbtDelay\" );\
- \n\t:do { /file remove \$rbtFile } on-error={\
- \n\t\t:log error ( \"sys-ros-startup: can't remove signal file - ros-upgrade-once.txt\" );\
- \n\t\t:error \"Can't remove signal file - ros-upgrade-once.txt\"\
- \n\t}\t\
- \n\t:delay \$rbtDelay;\
- \n\t/system reboot;\
- \n}\
- \n# 3.6 Environment cleanup\
- \n:do { /system script environment remove [ find name~\"func\" ] } on-error={\
- \n\t:log warning ( \"sys-ros-startup: script environment cleanup is failed\" );\
- \n};\
- \n# 4. End"
- /system scheduler
- add comment="System startup" name=sys-startup on-event=sys-ros-startup policy=ftp,reboot,read,write,policy,test,sniff start-time=startup
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement