From: vados-dev <192440777+vados-dev@users.noreply.github.com> Date: Mon, 9 Mar 2026 11:14:49 +0000 (+0300) Subject: Autocommit in repo: ros.vados.ru, generated by owner: root, in 14:14:48 09.03.2026. X-Git-Url: https://git.vados.ru/gitweb.cgi?a=commitdiff_plain;h=c99255691c13520c8e02e96d8877d4c6e0f28126;p=Mikrotiks%2Fros.vados.ru.git Autocommit in repo: ros.vados.ru, generated by owner: root, in 14:14:48 09.03.2026. --- diff --git a/.config/config.mk b/.config/config.mk index b0e58c65e..335cc7c96 100644 --- a/.config/config.mk +++ b/.config/config.mk @@ -1,6 +1,17 @@ - export BOT_TOKEN ?= "8390868324:AAG3_d1hfVR2M6pGAgDK6ZvhOe4J97nyopw" - export CHAT_ID ?= "454403445" - export TGDisableWebPagePreview ?= "True" - export TGParseMode ?= "html" - export REPO_DIR ?= $(BUILD_DIR) - export DRY_RUN ?= 0 + +export DRY_RUN ?= 0 + +export DATE ?= $(shell (date '+%T %d.%m.%Y')) +export DTSTAMP_FMT ?= "+%Y%m%d%H%M" +export DTSTAMP ?= $(shell (date $(DTSTAMP_FMT))) +export VERSION ?= $(shell git symbolic-ref --short HEAD 2>/dev/null)/$(shell git rev-list --count HEAD 2>/dev/null)/$(shell git rev-parse --short=8 HEAD 2>/dev/null) +export RUN_OWNER := $(shell whoami 2>/dev/null) +export COMM_REPO := $(shell git rev-parse --show-toplevel | rev | cut -d/ -f1 | rev 2>/dev/nul) +export COMM_BRANCH := $(shell git symbolic-ref --short HEAD 2>/dev/null) +export COMMIT_ID := $(VERSION) +export COMM_INFO := $(shell echo -e "Autocommit in repo: $(COMM_REPO), generated by owner: $(RUN_OWNER), in $(DATE)." 2>/dev/null) + +export BOT_TOKEN ?= "8390868324:AAG3_d1hfVR2M6pGAgDK6ZvhOe4J97nyopw" +export CHAT_ID ?= "454403445" +export TGDisableWebPagePreview ?= "True" +export TGParseMode ?= "html" diff --git a/Makefile b/Makefile index a67e163bc..cf6daa813 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,15 @@ # Makefile BUILD_DIR = $(shell pwd) +REPO_DIR ?= $(BUILD_DIR) -BIN_DIR = bin -commitinfo.sh := $(wildcard bin/commitinfo.sh) - -HTML_DIR = html ALL_RSC := $(wildcard html/*.rsc html/*/*.rsc) +commitinfo.sh := $(wildcard bin/commitinfo.sh) GLOB_RSC := $(wildcard html/AM-GlobalFunc.rsc) -DATE ?= $(shell (date '+%T %d.%m.%Y')) -DTSTAMP_FMT ?= "+%Y%m%d%H%M" -DTSTAMP ?= $(shell (date $(DTSTAMP_FMT))) -VERSION ?= $(shell git symbolic-ref --short HEAD 2>/dev/null)/$(shell git rev-list --count HEAD 2>/dev/null)/$(shell git rev-parse --short=8 HEAD 2>/dev/null) -RUN_OWNER := $(shell whoami 2>/dev/null) -COMM_REPO := $(shell git rev-parse --show-toplevel | rev | cut -d/ -f1 | rev 2>/dev/nul) -COMM_BRANCH := $(shell git symbolic-ref --short HEAD 2>/dev/null) +SHELL := /bin/bash + +include $(BUILD_DIR)/.config/config.mk COMM_TAG := $(shell git rev-list --abbrev-commit --tags --max-count=1) # `2>/dev/null` suppress errors and `|| true` suppress the error codes. @@ -37,24 +31,13 @@ ifneq ($(shell git status --porcelain), ) TAG_VERS :=$(TAG_VERS)-dirty endif -COMMIT_ID := $(VERSION) -COMM_INFO := $(shell echo -e "Autocommit in repo: $(COMM_REPO), generated by owner: $(RUN_OWNER), in $(DATE)." 2>/dev/null) - -export BUILD_DIR BIN_DIR HTML_DIR DATE DTSTAMP VERSION COMMIT_ID COMM_TAG COMM_HASH COMM_INFO - -SHELL := /bin/bash - -export BUILD_DIR BIN_DIR HTML_DIR DATE DTSTAMP VERSION COMMIT_ID COMM_TAG COMM_HASH COMM_INFO COMM_DATE - .ONESHELL: -.DEFAULT_GOAL := run +export BUILD_DIR REPO_DIR ALL_RSC GLOB_RSC -export BUILD_DIR BIN_DIR HTML_DIR DATE DTSTAMP VERSION COMMIT_ID COMM_TAG COMM_HASH COMM_INFO - -include $(BUILD_DIR)/.config/config.mk +.DEFAULT_GOAL := run -.PHONY: run check notify test +.PHONY: run check notify checksums commitinfo test run: check @echo "[run] start main flow" @@ -68,84 +51,23 @@ check: notify: @bash bin/notify_telegram.sh "manual notify from make" -test: - @bash -n bin/check_repo.sh - @bash -n bin/notify_telegram.sh - @echo "syntax ok" - - -.DEFAULT_GOAL := all -.PHONY: all checksums git-check commitinfo clean - -define run-git = - git $@ -endef - -all: checksums git-check commitinfo - checksums: checksums.json checksums.json: bin/checksums.sh $(ALL_RSC) - bin/checksums.sh > html/tmp/$@ - -gitcheck: $(BUILD_DIR) - cd $ && - @if git diff --quiet && git diff --cached --quiet && [ -z "$$(git ls-files --others --exclude-standard)" ]; then \ - echo "The first checks have been passed, the repo seems to be clean... But... Still, let's check a little more!"; \ - git add . && \ - if [[ -n "$$(git status --porcelain)" ]]; then \ - echo "Uncommitted changes detected! Commit it..."; \ -# git commit -m "$(COMM_INFO)"; \ -# git push; \ - exit 1; \ - else \ - echo "repo clean"; \ - fi \ - else \ - @echo "Warning: Uncommitted changes detected! Go to autocommit steps..."; \ - git branch -v; \ -# git commit -am "$(COMM_INFO)"; \ -# git push; \ - fi - - -#@if [ -n "$$(git diff --quiet)" ] && [ -n "$$(git diff --cached --quiet)" ] && [ -n "$$(git ls-files --others --exclude-standard)" ]; then \ -#[ -n "$$(git status --porcelain)" ] - -check-uncommitted: - @if [ -n "$$(git diff --quiet)" ] && [ -n "$$(git diff --cached --quiet)" ] && [ -n "$$(git ls-files --others --exclude-standard)" ]; then \ - echo "Warning: Uncommitted changes detected! Go to autocommit steps..."; \ - else \ - echo "The first checks have been passed, the repo seems to be clean... But... Still, let's check a little more!"; \ - if git status --porcelain; then \ - echo "Repository is clean (no uncommitted or untracked changes). Exit 0."; \ - exit 0; \ - else \ - echo "Error! Git status is not porcelain! Check it mannualy. Exit 1."; \ - exit 1; \ - fi \ - fi - - -# if [[ -n "`$(rungit) status --porcelain`" ]];: then \ - echo "Warning: Uncommitted changes detected! Go to autocmmit..."; \ - git commit -m "$(COMM_INFO)"; \ - git push origin $(COMM_BANCH); \ - else \ - echo "Repository is clean (no uncommitted or untracked changes). Exit 0."; \ - exit 0; \ - fi + bin/checksums.sh > html/tmp/checksums.json commitinfo: $(commitinfo.sh) -.PHONY: $(commitinfo.sh) $(commitinfo.sh): $(GLOB_RSC) $(commitinfo.sh) $< > $<~ mv $<~ $< +test: + @bash -n bin/check_repo.sh + @bash -n bin/notify_telegram.sh + @bash -n bin/checksums.sh + @bash -n bin/commitinfo.sh + @echo "syntax ok" -clean: - git checkout HEAD -- . - -# rm -f $(HTML) checksums.json -# make -C contrib/ clean +#clean: +# git checkout HEAD -- . diff --git a/bin/commitinfo.orig.sh b/bin/commitinfo.orig.sh deleted file mode 100755 index 21faf9fc4..000000000 --- a/bin/commitinfo.orig.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -sed \ - -e "/^:global CommitId/c :global CommitId \"${COMMITID:-unknown}\";" \ - -e "/^:global CommitInfo/c :global CommitInfo \"${COMMITINFO:-unknown}\";" \ - < "${1}" diff --git a/bin/commitinfo.sh.bak b/bin/commitinfo.sh.bak deleted file mode 100755 index 54cc342c8..000000000 --- a/bin/commitinfo.sh.bak +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/sh - - -sed \ - -e "/^:global CommitId/c :global CommitId \"${COMMITID:-unknown}\";" \ - -e "/^:global CommitInfo/c :global CommitInfo \"${COMMITINFO:-unknown}\";" \ - < "${1}" - -GitDir=`pwd` -binDir=$GitDir"/bin/" -htmlDir=$GitDir"/html/" - -#cd $htmlDir - -set -e - - - -cd $GitDir - -git add . - -if git commit -m "Backup for ${GitDir} sucessfully created at $(date '+%b %d %T')."; then - - if git push origin main; then -# save_log "${log_msg}" - exit 0 - else -# save_log "${log_msg}" - exit 1 - fi - -else - -exit 1 -fi - diff --git a/bin/get_backups.sh b/bin/get_backups.sh deleted file mode 100644 index 6176dd88f..000000000 --- a/bin/get_backups.sh +++ /dev/null @@ -1,91 +0,0 @@ -#!/bin/bash -date=$(date +%d-%m-%Y) -time=$(date +%H-%M) -username="mikro_bak" -mikrotik=$HOME"/.mikrotiks" -backup_path=$HOME"/.bak" -tmp=$HOME"/tmp/" -log=$tmp"/log.txt" -#-------------------------------# -smb_path_backup="//192.168.1.2/Backups" -domain="WORKGROUP" -usrname="backuper" -passwd="root.mikrots.backuper" -################ -# Backup listing -################ -# Get addresses -for i in $( cat $mikrotik ); do -mkdir -p $tmp"/"$i -# Get Devices Names -RESULT=$(ssh "ssh://"$username"@"$i":2222" "system identity print" | awk ' {print $2} '); -echo "Start backup Devices" -echo "Start backup Devices Mikrotiks ($time) $RESULT" > $log -echo "Create Backup $i..." -ssh "ssh://"$username"@"$i":2222" "system backup save name=binary.backup"; -if [ $? -eq 0 ]; then -echo -n "$(tput hpa $(tput cols))$(tput cub 6)[OK]" -echo "Create Backup $i success ($time)" >> $log -echo -else -echo -n "$(tput hpa $(tput cols))$(tput cub 6)[ERROR]" -echo "Createbackup $i failed ($time)" >> $log -echo -fi - -echo "Create configuration $i..." -ssh "ssh://"$username"@"$i":2222" "export file=export.rsc"; -if [ $? -eq 0 ]; then -echo -n "$(tput hpa $(tput cols))$(tput cub 6)[OK]" -echo "Create configuration $i success ($time)" >> $log -echo -else -echo -n "$(tput hpa $(tput cols))$(tput cub 6)[ERROR]" -echo "Create configuration $i failed ($time)" >> $log -echo -fi -echo "Create backups directory..." -mkdir -p $tmp/$i/$date/ -echo "Backups directory created $i ($time)" >> $log -echo -echo "Download backup files $i..." -sftp "ssh://"$username"@"$i":2222/binary.backup" $tmp/$i/$date/$i"-"$time".backup"; -sftp "ssh://"$username"@"$i":2222/export.rsc" $tmp/$i/$date/$i"-"$time".rsc"; -if [ $? -eq 0 ]; then -echo -n "$(tput hpa $(tput cols))$(tput cub 6)[OK]" -echo "Download backups $i success ($time)" >> $log -echo -else -echo -n "$(tput hpa $(tput cols))$(tput cub 6)[ERROR]" -echo "Download backups $i failed ($time)" >> $log -echo -fi - -echo "Compress backups..." -cd $tmp/$i/ -RESULT=$(tar -czvf $date".tar.gz" $date) -echo "Backups compressed ($time)" >> $log - -#echo "Connect to network share $smb_path_backup..." -#RESULT=$(cat /home/Mikrotiks/sudos | sudo -S -u root mount -t cifs $smb_path_backup /mnt/samba -o username=$usrname,password=$passwd,domain=$domain) -#echo "Networkshare $smb_path_backup connected ($time)" >> $log - -echo "Create directory for backups device $i..." -#RESULT=$(cat /home/Mikrotiks/sudos | sudo -S -u root mkdir -p /mnt/samba/Mikrotik/$i) -RESULT=$(mkdir -p $backup_path/$i) -echo "Directory for backup device $i created in network share ($time)" >> $log - -echo "Place backups in network share" -RESULT=$(cat /home/Mikrotiks/sudos | sudo -S -u root mv $tmp/$i/$date".tar.gz" "/mnt/samba/Mikrotik/$i/$date.tar.gz") -echo "Backups $i moved to "$smb_path_backup"/$i ($time)" >> $log -echo "" >> $log - -RESULT=$(cat /home/Mikrotiks/sudos | sudo -S -u root mv $log "/mnt/samba/MIkrotik/$i/$date.log.txt") - -echo "Remove local backup files device $i" -ssh $username"@"$i "file remove binary.backup"; -ssh $username"@"$i "file remove export.rsc"; -rm -r -f $tmp - -cat /home/Mikrotiks/sudos | sudo -S -u root umount $smb_path_backup -done diff --git a/bin/notify_telegram copy.sh b/bin/notify_telegram copy.sh deleted file mode 100755 index 93c7876d1..000000000 --- a/bin/notify_telegram copy.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env bash - -msg=${1:-no message} - -if [[ "${DRY_RUN:-0}" == "1" ]]; then - echo "[notify][dry-run] $msg" - exit 0 -fi - -if [[ -z "${BOT_TOKEN:-}" || -z "${CHAT_ID:-}" ]]; then - echo "[notify] BOT_TOKEN/CHAT_ID not set, skip" - exit 0 -fi -#echo "https://api.telegram.org/bot${BOT_TOKEN}/sendMessage?chat_id=${CHAT_ID}&text=$msg&parse_mode=$TGParseMode&disable_web_page_preview=$TGDisableWebPagePreview" -#exit 0 -curl -fsS --connect-timeout 5 --max-time 10 \ - -X POST "https://api.telegram.org/bot"${BOT_TOKEN}"/sendMessage" \ - -d "chat_id=${CHAT_ID}" \ - -d "parse_mode=html" \ - -d "disable_web_page_preview=True" \ - --data-urlencode "text=${msg}" - # >/dev/null -# || true diff --git a/bin/ros-conf/README.md b/bin/ros-conf/README.md deleted file mode 100644 index 973a2a713..000000000 --- a/bin/ros-conf/README.md +++ /dev/null @@ -1,41 +0,0 @@ -# RouterOS Configuration Scripts - -Personal RouterOS configuration scripts for home network management. - -## Overview - -This repository contains RouterOS scripts to configure and diagnose a MikroTik router. Configuration scripts set up router modes (routing, bridging, NAT, DHCP). Check scripts display router settings and diagnostics. - -## Quick Start - -### Running Scripts - -Run scripts on the router using forward slashes: - -```routeros -/system script run config/firewall -/system script run check/nat -``` - -## Network Configuration - -The `combo1` port is renamed to `combo1-WAN` for routing mode or `combo1-bridge` for switching mode. The `bridge` interface is used for the internal network. - -The WAN interface uses `192.168.200.2/24` with gateway `192.168.200.1`. The bridge interface uses `192.168.88.1/24` as the gateway for the internal network. DHCP serves addresses from `192.168.88.100-192.168.88.199`. - -## Hardware - -These scripts are tested on CRS106, a MikroTik switch/router. - -## Repository Structure - -```text -routeros-config/ -├── scripts/ -│ ├── config/ # Configuration scripts -│ ├── check/ # Diagnostic scripts -│ └── README.md # Format and syntax guidelines -└── README.md # This file -``` - -For format and syntax guidelines, see [scripts/README.md](scripts/README.md). diff --git a/bin/ros-conf/setup-ssh-keys.sh b/bin/ros-conf/setup-ssh-keys.sh deleted file mode 100755 index 7fcd9f4e0..000000000 --- a/bin/ros-conf/setup-ssh-keys.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -# Setup SSH keys for RouterOS router - -ROUTER_IP="10.30.30.10" -ROUTER_USER="mikro_bak" -KEY_NAME="mikro_bak_rsa" -KEY_PATH="$HOME/.ssh/$KEY_NAME" - -# Check/create .ssh directory -if [ ! -d "$HOME/.ssh" ]; then - mkdir -p "$HOME/.ssh" - chmod 700 "$HOME/.ssh" -fi - -# Generate SSH key if it doesn't exist -if [ ! -f "$KEY_PATH" ]; then - ssh-keygen -t rsa -b 4096 -f "$KEY_PATH" -N "" -C "routeros-$ROUTER_IP" -fi - -# Upload and import key on router -scp "$KEY_PATH.pub" "$ROUTER_USER@$ROUTER_IP":/ -ssh "$ROUTER_USER@$ROUTER_IP" "/user ssh-keys import public-key-file=$KEY_NAME.pub user=$ROUTER_USER" - -# Verify key works -if ! ssh -i "$KEY_PATH" -o PasswordAuthentication=no "$ROUTER_USER@$ROUTER_IP" "/system identity print" >/dev/null 2>&1; then - echo "Error: SSH key authentication failed" - exit 1 -fi diff --git a/bin/ros-conf/sync-script.sh b/bin/ros-conf/sync-script.sh deleted file mode 100755 index f55905288..000000000 --- a/bin/ros-conf/sync-script.sh +++ /dev/null @@ -1,139 +0,0 @@ -#!/bin/bash -# Upload all scripts and sync to RouterOS - -ROUTER_IP="192.168.88.1" -ROUTER_USER="admin" -SSH_KEY="$HOME/.ssh/id_rsa_routeros" -RSC_FILE="import_scripts.rsc" - -# Require router-specific SSH key -if [ ! -f "$SSH_KEY" ]; then - echo "Error: SSH key not found at $SSH_KEY" - echo "Run ./setup-ssh-keys.sh to generate the key" - exit 1 -fi - -SSH_OPTS="-i $SSH_KEY -o PasswordAuthentication=no" - -# Generate .rsc import file -echo "Generating import file..." - -# Get git commit hash and dirty status -GIT_HASH=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown") -if [ -z "$(git status --porcelain 2>/dev/null)" ]; then - GIT_STATUS="$GIT_HASH" -else - GIT_STATUS="$GIT_HASH-dirty" -fi - -# Get current date with timezone offset -GEN_DATE=$(date '+%Y-%m-%d %H:%M:%S %z') - -# Write header -cat > "$RSC_FILE" << RSC_HEADER -# RouterOS script import file -# Generated by sync-script.sh -# Date: $GEN_DATE -# Git: $GIT_STATUS - -RSC_HEADER - -# Write header for creating scripts section -printf ':put "=== Creating scripts ==="\n' >> "$RSC_FILE" -printf '\n' >> "$RSC_FILE" - -# Create function for script creation -printf ':global createScriptIfMissing do={\n' >> "$RSC_FILE" -printf ' :if ([/system script print count-only where name=$scriptName] = 0) do={\n' >> "$RSC_FILE" -printf ' :put ("Creating script: " . $scriptName);\n' >> "$RSC_FILE" -printf ' /system script add name=$scriptName\n' >> "$RSC_FILE" -printf ' }\n' >> "$RSC_FILE" -printf '}\n\n' >> "$RSC_FILE" - -# Write all add commands first -for SCRIPT_FILE in scripts/config/*.rsc scripts/check/*.rsc; do - if [ ! -f "$SCRIPT_FILE" ]; then - continue - fi - - SCRIPT_NAME=$(sed -n '1p' "$SCRIPT_FILE" | sed 's/^# //') - POLICY=$(sed -n '3p' "$SCRIPT_FILE" | sed -n 's/^# policy=\(.*\)/\1/p') - - if [ -z "$POLICY" ]; then - echo "Error: Missing policy in $SCRIPT_FILE (line 3 should be '# policy=read,write')" - exit 1 - fi - - # Call function with script name - printf '$createScriptIfMissing scriptName="%s"\n' "$SCRIPT_NAME" >> "$RSC_FILE" -done - -# Empty line between sections -printf '\n' >> "$RSC_FILE" -printf ':put ""\n' >> "$RSC_FILE" -printf ':put "=== Updating scripts ==="\n' >> "$RSC_FILE" -printf '\n' >> "$RSC_FILE" - -# Write all set commands -for SCRIPT_FILE in scripts/config/*.rsc scripts/check/*.rsc; do - if [ ! -f "$SCRIPT_FILE" ]; then - continue - fi - - SCRIPT_NAME=$(sed -n '1p' "$SCRIPT_FILE" | sed 's/^# //') - COMMENT=$(sed -n '2p' "$SCRIPT_FILE" | sed 's/^# //') - POLICY=$(sed -n '3p' "$SCRIPT_FILE" | sed -n 's/^# policy=\(.*\)/\1/p') - - # Escape comment for RouterOS (escape quotes) - ESCAPED_COMMENT=$(echo "$COMMENT" | sed 's/"/\\"/g') - - # Read script content and escape for RouterOS .rsc format - # Loop through file line by line, escape special chars, join with \n - SCRIPT_CONTENT="" - while IFS= read -r line || [ -n "$line" ]; do - # Escape backslashes, dollar signs, and quotes - line=$(echo "$line" | sed 's/\\/\\\\/g' | sed 's/\$/\\$/g' | sed 's/"/\\"/g') - if [ -z "$SCRIPT_CONTENT" ]; then - SCRIPT_CONTENT="$line" - else - SCRIPT_CONTENT="$SCRIPT_CONTENT\\n$line" - fi - done < "$SCRIPT_FILE" - - # Write set command directly to file - printf ':put "Updating script: %s"; /system script set "%s" source="' "$SCRIPT_NAME" "$SCRIPT_NAME" >> "$RSC_FILE" - echo "$SCRIPT_CONTENT" | sed 's/\\n/\\n\\\n /g' >> "$RSC_FILE" - printf '" comment="%s" policy=%s\n\n' "$ESCAPED_COMMENT" "$POLICY" >> "$RSC_FILE" -done - -# Delete the helper function -printf '\n:set createScriptIfMissing;\n' >> "$RSC_FILE" - -# Print all scripts (excluding source/contents) -printf ':put ""\n:put "=== All system scripts ==="\n/system script print proplist=name,comment,owner,policy,dont-require-permissions,run-count,last-started,invalid\n' >> "$RSC_FILE" - -# Show generated .rsc file and ask for confirmation -echo "" -echo "=== Generated import file ($RSC_FILE) ===" -head -20 "$RSC_FILE" -echo "..." -echo "" -read -p "Upload and import this file? (y/N): " -n 1 -r -echo -if [[ ! $REPLY =~ ^[Yy]$ ]]; then - echo "Aborted" - rm -f "$RSC_FILE" - exit 1 -fi - -# Upload .rsc file -echo "Uploading import file..." -scp $SSH_OPTS "$RSC_FILE" "$ROUTER_USER@$ROUTER_IP":/ - -# Import on router -echo "Importing scripts..." -ssh $SSH_OPTS "$ROUTER_USER@$ROUTER_IP" "/import file-name=$RSC_FILE" - -# Cleanup -rm -f "$RSC_FILE" -echo "Done!" diff --git a/log.txt b/log.txt deleted file mode 100644 index e69de29bb..000000000