Initial Commit

This commit is contained in:
Grzegorz Budny 2020-03-23 21:41:45 +01:00
parent 2f897350bc
commit 9bd877b7fa
3 changed files with 139 additions and 0 deletions

65
RouterOS_Config_Fetch.rsc Normal file
View file

@ -0,0 +1,65 @@
# RouterOS Function
# Copyright (c) Grzegorz Budny
# Version 1.0
# Last update: 22/22/2020
# Fetches RouterOS script (dedicated for initial config) adds scheduler entry to start it on startup
:global FetchConfig do={
:log info "...:::Configuration fetch process started:::...";
:do {
/tool fetch address=$repositoryIP user=$userName password=$password \
port=21 mode=ftp src-path=($sourcePath.$sourceFileName) dst-path=($destinationPath.$destinationFileName);
} on-error={
:put "An error occured when dowloading configuration file!";
:log critical "...:::An error occured when dowloading configuration file!:::...";
};
:if($isRun)do={
:do {
:log info "...:::Configuration import started:::...";
/import ($destinationPath.$destinationFileName);
} on-error={
:put "An error occured during configuration import!";
:log critical "...:::An error occured during configuration import!:::...";
};
:delay 5;
:log warning "...:::Import secessful. Rebooting device:::...";
/system reboot;
}\
else={
:log info "...:::Configuring import on startup:::...";
:do {
/system scheduler \
add interval=($interval.h) name=$taskName on-event=("system script run ".($destinationPath.$destinationFileName)) \
policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \
start-date=jan/01/1970 start-time=$startTime;
} on-error={
:put "An error occured during import job schedule!";
:log critical "...:::An error occured during import job schedule!:::...";
}
:log info "...:::Configuration job scheduled for next startup!:::...";
}
}
FetchConfig isRun=true;

View file

@ -0,0 +1,32 @@
# RouterOS Function
# Copyright (c) Grzegorz Budny
# Version 1.0
# Last update: 3/22/2020
# Measures script execution time
:global MeasureExecutionTime do={
:local timeDifferance;
:local startTime [/system clock get time];
/system script run $scriptName;
:local endTime [/system clock get time]
:set $timeDifferance ($endTime-$startTime);
:if($return) do={
:return $timeDifferance;
}\
else={
:put ("Script executed in : ".$timeDifferance);
}
:set $timeDifferance;
}
$MeasureExecutionTime scriptName=scriptName return=true;

View file

@ -0,0 +1,42 @@
# RouterOS Function
# Copyright (c) Grzegorz Budny
# Version 1.0
# Last update: 3/23/2020
# DUDE Server initial setup on RB750GR3 with microSD or USB drive
:global SetupDudeRB750GR3 do={
:local isDude [/system packages find name=dude];
:if ($isDude) do={
:log info "...:::Started DUDE Server Setup:::...";
:log warning "...:::Formatting drive:::...";
/disk eject-drive $driveNumber;
:do {
/disk format-drive $driveNumber file-system=ext3 label=$driveLabel;
} on-error={
:log critical "...:::Formatting failed. Check your drive:::...";
}
:log info "...:::Formatting finished:::...";
/dude set data-directory=$dudeDirectory;
/dude set enabled=yes;
}\
else={
:log critical "...:::Setup failed. Install DUDE package first:::...";
}
}
$SetupDudeRB750GR3 driveNumber=driveNumber driveLabel=driveLabel dudeDirectory=directoryName;