Скрипты для Linux
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.9 KiB

#!/bin/bash
[ "${alias_dir}" = "" ] && alias_dir=$(pwd)
source "${alias_dir}/common"
sync_2dir()
{
# Двухсторонняя синхронизация
# Использование:
# ./2sync src dest [opt1] [opt2]
src=$1
dest=$2
opt1=$3
opt2=$4
rsync -r -t -v $opt1 $opt2 --progress -s --omit-dir-times $src $dest
rsync -r -t -v $opt1 $opt2 --progress -s --omit-dir-times $dest $src
}
mkalias_with_prefix 'sync_2dir'
sync_by_filter()
{
# Двухсторонняя синхронизация с сервером всех объектов в текущей папке
# Использование:
# sync_by_filter filter dest_base opt1 opt2
# filter - маска по файлам
# dest_base - базовый путь для синхронизации, может содержать сервер, например: backup@www_server:/media/Backup
# opt1,2 - дополнительные опции rsync.
# Примеры:
# 1. Опция "-n" для теста
# 2. Опция "--delete" для удаления файлов
filter=$1
dest_base=$2
opt1=$3
opt2=$4
files=`ls -p | grep / | grep ${filter} |sort`
cur_dir="$(pwd)/"
for file in $files; do
src="${cur_dir}/${file}/"
dest="${dest_base}/${file}/"
sync_2dir $src $dest $opt1 $opt2
done
}
mkalias_with_prefix 'sync_by_filter'
syncthing_local_config()
{
port=$1
config_dir=$2
[ "$port" = "" ] && port=8396
[ "$config_dir" = "" ] && config_dir="$(pwd)/syncthing_home" && mkdir "$config_dir"
[ "$port" != "$1" || "$config_dir" != "$2" ] && printf "Запуск syncthing в папке '${config_dir}' и на порту '${port}'\n" && ask_continue && return
firefox "127.0.0.1:$port"
syncthing --gui-address="http://0.0.0.0:$port" --home="${config_dir}" --no-restart --no-upgrade --paused
}
mkalias_with_prefix 'syncthing_local_config'