Репозиторий Sisyphus
Последнее обновление: 1 октября 2023 | Пакетов: 18631 | Посещений: 37526772
en ru br
Репозитории ALT
S:0.4.9-alt1
5.1: 0.3-alt1
4.1: 0.1-alt0.M41.6
www.altlinux.org/Changes

Группа :: Система/Настройка/Прочее
Пакет: alterator-mirror

 Главная   Изменения   Спек   Патчи   Исходники   Загрузить   Gear   Bugs and FR  Repocop 

alterator-mirror-0.4.2/000075500000000000000000000000001215537232400150245ustar00rootroot00000000000000alterator-mirror-0.4.2/Makefile000064400000000000000000000004541215537232400164670ustar00rootroot00000000000000NAME=mirror

all:
clean:
install: install-module install-data install-sbin

include /usr/share/alterator/build/module.mak

install-data:
install -d $(sysconfdir)/alterator
cp -a mirror $(sysconfdir)/alterator

install-sbin:
for i in sbin/* ;do install -Dpm755 $$i $(sbindir)/`basename $$i` ; done
alterator-mirror-0.4.2/alterator-mirror.logrotate000064400000000000000000000001771215537232400222600ustar00rootroot00000000000000/var/log/alterator-mirror/*.log {
missingok
notifempty
sharedscripts
create 0644 root root
delaycompress
}
alterator-mirror-0.4.2/applications/000075500000000000000000000000001215537232400175125ustar00rootroot00000000000000alterator-mirror-0.4.2/applications/mirror.desktop000064400000000000000000000004041215537232400224150ustar00rootroot00000000000000[Desktop Entry]
Type=Application
Categories=X-Alterator-Servers
Icon=mirror
Terminal=false
Name=Updates server
X-Alterator-URI=/mirror
X-Alterator-UI=html
X-Alterator-Help=mirror
Name[ru]=п║п╣я─п╡п╣я─ п╬п╠п╫п╬п╡п╩п╣п╫п╦п╧
Name[pt_BR]=Servidor de Atualizaц╖цёo
alterator-mirror-0.4.2/backend3/000075500000000000000000000000001215537232400164765ustar00rootroot00000000000000alterator-mirror-0.4.2/backend3/mirror000075500000000000000000000240011215537232400177330ustar00rootroot00000000000000#!/bin/sh

dest_url=/mirror

dest_dir=/srv/public/mirror
config_dir=/etc/alterator/mirror/config
repository_dir=/etc/apt/repositories
mirror_dir=/etc/apt/mirrors
schedule_file=/etc/cron.d/alterator-mirror
mirror_cmd=/usr/sbin/alterator-mirror

alterator_api_version=1

url_re='^\(ftp://\|http://\|rsync://\|file:/\)[a-zA-Z0-9._/:@-]\+$'
rsync_url_re='^rsync://[a-zA-Z0-9._/-:@]\+$'

. alterator-sh-functions
. avahi-sh-functions
. shell-quote
. shell-config

### low level

repository_awk()
{
alterator-dump-desktop \
-v lang="$in_language" \
-v out="Filename;X-Path;X-Has-Noarch;X-Mirror;Name" \
-v def="noname;/notfound;no;yes" \
"$@"
}

mirror_awk()
{
alterator-dump-desktop \
-v lang="$in_language" \
-v out="Filename;X-Repositories;Name;Comment" \
-v def="noname;all" \
"$@"
}

config_get()
{
local v="$(shell_config_get "$config_dir/$1" "$2")"
string_quote_remove "$v"
}

config_set()
{
local f="$config_dir/$1"
[ -s "$f" ] || echo ". $config_dir/.common" >"$f"

shell_config_set "$f" "$2" "\"$3\""
}

tr_size()
{
sed -e "s/[::space::]*M/ `_ "Mb"`/" \
-e "s/[::space::]*K/ `_ "Kb"`/" \
-e "s/[::space::]*G/ `_ "Gb"`/" \
-e "s/[::space::]*T/ `_ "Tb"`/"
}


### high level
read_arch()
{
local arch="$(config_get "$1" ARCH)"
echo "${arch%% noarch}"
}

read_local()
{
[ "$(config_get "$1" ALTERATOR_LOCAL)" = "yes" ]
}

read_publish()
{
[ "$(config_get "$1" ALTERATOR_PUBLISH)" = "yes" ]
}

write_publish()
{
local name="$1";shift
local status="$1";shift

if test_bool "$status"; then
local mirror="$(config_get "$name" ALTERATOR_MIRROR)"
local custom_url="$(config_get "$name" ALTERATOR_CUSTOM_URL)"

[ "$mirror" = "custom" ] || custom_url=

if read_local "$name"; then
mirror=custom
custom_url="$dest_url"
fi

config_set "$name" ALTERATOR_PUBLISH yes
publish_service "alterator-mirror-$name" "System updates at %h ($name)" "_apt._tcp" 0 \
"r=$name" \
"m=$mirror" \
"u=$custom_url" \
"a=$(read_arch "$name")"
else
config_set "$name" ALTERATOR_PUBLISH no
unpublish_service "alterator-mirror-$name"
fi
}

list_repository()
{
repository_awk $repository_dir/*.desktop|
while read name path noarch mirror description;do
[ "$mirror" = "yes" ] || continue

name="${name##*/}"
name="${name%.desktop}"

if [ ! -s "$config_dir/$name" ];then
write_table_item \
name "$name" \
description "$description" \
mirror "" \
arch "" \
local_status "off" \
local_du "" \
publish "off"
continue
fi

local r_mirror="$(config_get "$name" ALTERATOR_MIRROR)"

local r_path=
if [ "$r_mirror" = "custom" ];then
r_path="$(config_get "$name" ALTERATOR_CUSTOM_URL)"
elif [ -n "$r_mirror" ];then
r_path="$(alterator-dump-desktop -v lang="$in_language" -v out=Name "$mirror_dir/$r_mirror.desktop")"
fi

local r_arch="$(read_arch "$name")"

local r_local_du="($(run_localized du -sh "$dest_dir/$path" 2>/dev/null| cut -f1| tr_size))"
local r_local_status=
if read_local "$name"; then
[ "$r_local_du" != '()' ] || r_local_du="(0 `_ "Kb"`)"
r_local_status="on"
else
[ "$r_local_du" != "()" ] || r_local_du=""
r_local_status="off"
fi

r_publish=
if read_publish "$name"; then
r_publish="on"
else
r_publish="off"
fi

write_table_item \
name "$name" \
description "$description" \
mirror "$r_path" \
arch "$r_arch" \
local_status "$r_local_status" \
local_du "$r_local_du" \
publish "$r_publish"
done
}

list_mirror()
{
local repo="$1";shift
local IFS=" "

mirror_awk $mirror_dir/*.desktop|
while read id repolist name comment; do

repolist=";$repolist;"
[ "$repolist" = ";all;" -o -z "${repolist##*;$repo;*}" ] || continue

id="${id##*/}"
id="${id%.desktop}"

printf '%s\t%s (%s)\n' "$id" "$name" "$comment"
done | write_enum

write_enum_item "custom" "`_ "Custom url"`"
}

list_arch()
{
write_enum_item "i586"
write_enum_item "x86_64"
local r_file="$repository_dir/$in_name.desktop"
local r_arepo="$(shell_config_get "$r_file" X-Has-Arepo)"
local r_arm="$(shell_config_get "$r_file" X-Has-ARM)"
if [ "$r_arepo" = "yes" ]; then
write_enum_item "x86_64-i586"
fi
if [ "$r_arm" = "yes" ]; then
write_enum_item "arm"
fi
}


read_storage()
{
local real_dest_dir="$(readlink -e "$dest_dir")"
run_localized df -lhP |
sed 1d |
sort -r -k 6,6 |
while read fs total use avail percent mpoint; do
[ -z "${real_dest_dir##$mpoint*}" ] || continue
write_string_param "storage_avail" "$(echo "$avail"|tr_size)"
break
done
}

get_rsync_url()
{
if [ "$1" = "custom" ];then
echo "$2"
else
shell_config_get "$mirror_dir/$1.desktop" X-RSYNC-URI
fi
}

read_schedule()
{
if [ -s "$schedule_file" ] ;then
while read min hour monthday month weekday rest;do
[ -n "${min%\#*}" ] || continue

write_string_param "time" "$hour:$min:00"
if [ "$monthday" = "*" -a "$month" = "*" -a "$weekday" = "*" ]; then
write_string_param "period" "daily"
elif [ "$monthday" = "*" -a "$month" = "*" -a "$weekday" != "*" ];then
write_string_param "period" "weekly"
write_string_param "weekday" "$weekday"
elif [ "$monthday" != "*" -a "$month" = "*" -a "$weekday" = "*" ]; then
write_string_param "period" "monthly"
write_string_param "monthday" "$monthday"
else
write_string_param "period" "daily"
fi
return
done <"$schedule_file"
else
write_string_param "period" "off"
write_string_param "monthday" "1"
write_string_param "weekday" "1"
write_string_param "time" "02:00:00"
fi
}

write_schedule()
{
if [ "$in_period" == "off" ];then
rm -f -- "$schedule_file"
return
fi

if [ "$in_period" = "weekly" -a -z "$in_weekday" ]; then
write_error "`_ "Day of week should be selected"`"
return
fi

if [ "$in_period" = "monthly" -a -z "$in_monthday" ];then
write_error "`_ "Day of month should be defined"`"
return
fi

in_time="${in_time%:*}"
local hour="${in_time%:*}"
local min="${in_time#*:}"

local new_schedule_file="$(mktemp "$schedule_file.XXXXXXXXXX")"
if [ -z "$new_schedule_file" ]; then
write_error "`_ "Unable to create temp file"`"
return
fi

printf "#autogenerated by alterator-mirror\n" >"$new_schedule_file"
case "$in_period" in
daily)
printf '%s %s * * * root %s\n' "$min" "$hour" "$mirror_cmd"
;;
weekly)
printf '%s %s * * %s root %s\n' "$min" "$hour" "$in_weekday" "$mirror_cmd"
;;
monthly)
printf '%s %s %s * * root %s\n' "$min" "$hour" "$in_monthday" "$mirror_cmd"
;;
esac >>"$new_schedule_file"
mv -f "$new_schedule_file" "$schedule_file"
}

list_weekday()
{
write_enum_item "1" "`_ "monday"`"
write_enum_item "2" "`_ "tuesday"`"
write_enum_item "3" "`_ "wednesday"`"
write_enum_item "4" "`_ "thursday"`"
write_enum_item "5" "`_ "friday"`"
write_enum_item "6" "`_ "saturday"`"
write_enum_item "0" "`_ "sunday"`"
}


## initial tuning
[ "$(config_get ".common" DESTROOT)" = "$dest_dir" ] ||
config_set ".common" DESTROOT "$dest_dir"

mkdir -p -- "$dest_dir"

on_message()
{
case "$in_action" in
list)
case "$in__objects" in
avail_repository)
list_repository;;
avail_arch)
list_arch;;
avail_weekday)
list_weekday;;
avail_mirror)
[ -n "$in_name" ] && list_mirror "$in_name" ;;
esac
;;
validate_mirror)
[ "$in_mirror" = "custom" ] ||
grep -qs 'X-RSYNC-URI=' "$mirror_dir/$in_mirror.desktop" ||
write_error "Not a rsync mirror"
;;
read)
case "$in__objects" in
/)
read_schedule
read_storage
;;
repository)
[ -n "$in_name" ] || return

repository_awk $repository_dir/$in_name.desktop|
(read name path noarch mirror description;
write_string_param description "$description")

write_string_param arch "$(config_get "$in_name" ARCH|tr ' ' ';')"
write_string_param mirror "$(config_get "$in_name" ALTERATOR_MIRROR)"
write_string_param custom_url "$(config_get "$in_name" ALTERATOR_CUSTOM_URL)"
write_bool_param local "$(config_get "$in_name" ALTERATOR_LOCAL)"
write_bool_param publish "$(config_get "$in_name" ALTERATOR_PUBLISH)"
;;
esac
;;
write)
case "$in__objects" in
/)
write_schedule
;;
repository)
if [ -n "$in_clear" -a -n "$in_name" ];then
repository_awk "$repository_dir/$in_name.desktop"|
(read name path noarch description;
[ -n "$path" ] && rm -rf "$dest_dir/$path")
elif [ -n "$in_commit" ];then
local r_file="$repository_dir/$in_name.desktop"
local r_path="$(shell_config_get "$r_file" X-Path)"
local r_noarch="$(shell_config_get "$r_file" X-Has-Noarch)"

#check custom_url
if [ "$in_mirror" = "custom" ] ;then
if [ -z "$in_custom_url" ];then
write_error "`_ "Custom url should be defined"`"
return
elif ! echo "$in_custom_url"|grep -qs "$url_re";then
write_error "`_ "Invalid or unsupported protocol. Should be http,ftp or rsync"`"
return
elif [ -n "$in_local" ] && ! echo "$in_custom_url"|grep -qs "$rsync_url_re";then
write_error "`_ "Can mirror only from sources with rsync procotol"`"
return
fi
fi

config_set "$in_name" LIST "$r_path"
[ -n "$in_arch" -a "$r_noarch" = "yes" ] && in_arch="${in_arch};noarch"
config_set "$in_name" ARCH "$(echo $in_arch|tr ';' ' ')"

config_set "$in_name" ALTERATOR_MIRROR "$in_mirror"
config_set "$in_name" ALTERATOR_CUSTOM_URL "$in_custom_url"

local rsync_url="$(get_rsync_url "$in_mirror" "$in_custom_url")"
if [ -n "$rsync_url" ] && test_bool "$in_local"; then
config_set "$in_name" ALTERATOR_LOCAL yes
config_set "$in_name" SRCROOT "$rsync_url"
else
config_set "$in_name" ALTERATOR_LOCAL no
config_set "$in_name" SRCROOT ""
fi

write_publish "$in_name" "$in_publish"
fi
;;
esac
;;
esac
}

message_loop
alterator-mirror-0.4.2/mirror/000075500000000000000000000000001215537232400163365ustar00rootroot00000000000000alterator-mirror-0.4.2/mirror/config/000075500000000000000000000000001215537232400176035ustar00rootroot00000000000000alterator-mirror-0.4.2/mirror/config/.common000064400000000000000000000000721215537232400210730ustar00rootroot00000000000000ARGS="-rltvhmHP --delete-delay --delete-excluded --stats"
alterator-mirror-0.4.2/sbin/000075500000000000000000000000001215537232400157575ustar00rootroot00000000000000alterator-mirror-0.4.2/sbin/alterator-mirror000075500000000000000000000013311215537232400212100ustar00rootroot00000000000000#!/bin/sh -eu

lockdir="/var/lib/alterator/.mirror-lock"
pidfile="$lockdir/pid"
configdir=/etc/alterator/mirror/config
logdir=/var/log/alterator-mirror
commonfile="$configdir/.common"

exit_handler()
{
local rc="$?"
trap - EXIT
rm -rf "$lockdir"

exit "$rc"
}

! mkdir -- "$lockdir" && [ -s "$lockdir/pid" ] && kill -0 -- "$(cat "$lockdir/pid")" && exit 0

trap exit_handler EXIT HUP PIPE INT QUIT TERM

mkdir -p -- "$lockdir"
echo $$ >"$pidfile"

[ ! -s "$commonfile" ] || . "$commonfile"

mkdir -p -- "$DESTROOT"

for i in "$configdir"/*; do
[ -s "$i" ] || continue
. "$i"
[ -n "${SRCROOT:-}" -a -n "${ARCH:-}" -a -n "${LIST:-}" ] || continue
HOME=/tmp sisyphus-mirror -c "$i" -L "$logdir"
done
alterator-mirror-0.4.2/ui/000075500000000000000000000000001215537232400154415ustar00rootroot00000000000000alterator-mirror-0.4.2/ui/mirror/000075500000000000000000000000001215537232400167535ustar00rootroot00000000000000alterator-mirror-0.4.2/ui/mirror/ajax.scm000064400000000000000000000021351215537232400204030ustar00rootroot00000000000000(define-module (ui mirror ajax)
:use-module (alterator ajax)
:use-module (alterator woo)
:use-module (alterator effect)
:export (init))

(define *parameters* '("storage_avail" "period" "weekday" "monthday" "time"))

(define (ui-read)
(catch/message
(lambda()
(form-update-value-list *parameters* (woo-read-first "/mirror" 'language (form-value "language")))
(update-effect))))

(define (ui-write)
(catch/message
(lambda()
(apply woo-write "/mirror"
'language (form-value "language")
(form-value-list *parameters*))
(ui-read))))

(define (init)
;; lists
(form-update-enum "repository" (woo-list "/mirror/avail_repository" 'language (form-value "language")))
(form-update-enum "weekday" (woo-list "/mirror/avail_weekday" 'language (form-value "language")))

;; effects
(effect-enable "weekday" "period" "weekly")
(effect-enable "monthday" "period" "monthly")
(effect-disable "time" "period" "off")
(init-effect)
;; form
(ui-read)

;; events
(form-bind "apply" "click" ui-write)
(form-bind "reset" "click" ui-read))
alterator-mirror-0.4.2/ui/mirror/index.html000064400000000000000000000060111215537232400207460ustar00rootroot00000000000000<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<!-- sources.list administration module -->
<html wf="none">
<body>
<form method="POST">
<table>
<tr>
<td>
<table name="repository" class="alterator-listbox" enumref="/mirror/avail_repository">
<thead>
<tr>
<th><span translate="_">Repository</span></th>
<th><span translate="_">Source</span></th>
<th><span translate="_">Architectures</span></th>
<th><span translate="_">Local mirror</span></th>
<th><span translate="_">Published</span></th>
</tr>
</thead>
<tbody>
<tr>
<td style="white-space:nowrap">
<a class="alterator-href" prefix-href="/mirror/repository?name=" name="name">
<span class="alterator-label" name="description"/>
</a>
</td>
<td style="white-space:nowrap"><span class="alterator-label" name="mirror"/></td>
<td><span class="alterator-label" name="arch"/></td>
<td><img suffix-src=".png" class="alterator-picture" name="local_status"/>&nbsp;<span class="alterator-label" name="local_du"/></td>
<td><img suffix-src=".png" class="alterator-picture" name="publish"/></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td>
<br/>
<span translate="_">Storage free space:</span>
&nbsp;<span class="alterator-label" name="storage_avail"/>
</td>
</tr>
<tr>
<td><p>
<strong><span translate="_">Warning:</span></strong>
<span translate="_">mirroring requires a lot of disk space.</span>
</p>
</td>
</tr>
<tr>
<td>
<table>
<tr>
<td>
<input type="radio" name="period" value="off"/>
<span name="period" translate="_">Turn off mirroring</span>
</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
<input type="radio" name="period" value="daily"/>
<span name="period" translate="_">Mirror every day</span>
</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
<input type="radio" name="period" value="weekly"/>
<span name="period" translate="_">Mirror every week at:</span>
&nbsp;
</td>
<td>
<select name="weekday"/>
</td>
</tr>
<tr>
<td>
<input type="radio" name="period" value="monthly"/>
<span name="period" translate="_">Mirror every month at day:</span>
&nbsp;
</td>
<td>
<span translate="_" style="display:none" name="monthday">Day of month:</span>
<input type="text" class="text" name="monthday" size="2"/>
</td>
</tr>
<tr><td colspan="2">&nbsp;</td></tr>
<tr><td colspan="2">
<span translate="_" name="time">Time:</span>
&nbsp;
<input type="text" class="text" size="8" name="time"/>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>
<input type="button" class="btn" name="apply" value="Apply"/>&nbsp;
<input type="button" class="btn" name="reset" value="Reset"/>
</td>
</tr>
</table>
</form>
</body>
</html>
alterator-mirror-0.4.2/ui/mirror/repository/000075500000000000000000000000001215537232400211725ustar00rootroot00000000000000alterator-mirror-0.4.2/ui/mirror/repository/ajax.scm000064400000000000000000000040601215537232400226210ustar00rootroot00000000000000(define-module (ui mirror repository ajax)
:use-module (alterator ajax)
:use-module (alterator woo)
:export (init))

(define (validate-mirror)
(catch #t
(lambda()
(woo "validate_mirror" "/mirror" 'mirror (form-value "mirror"))
#t)
(lambda args #f)))

(define (update-mirror)
(form-update-visibility "custom_url" (string=? (form-value "mirror") "custom"))
(form-update-activity "local" (validate-mirror)))

(define *parameters* '("description" "arch" "mirror" "custom_url" "local" "publish"))

(define (ui-read)
(catch/message
(lambda()
(let* ((language (form-value "language"))
(name (form-value "name"))
(mirror-list (woo-list "/mirror/avail_mirror" 'language language 'name name))
(arch-list (woo-list "/mirror/avail_arch" 'language language 'name name))
(data (woo-read-first "/mirror/repository" 'language language 'name name))
(mirror (woo-get-option data 'mirror)))
(form-update-enum "mirror" mirror-list)
(form-update-enum "arch" arch-list)
(form-update-value-list *parameters* data)
;; default mirror if we need it
(and (string-null? mirror)
(pair? mirror-list)
(form-update-value "mirror" (woo-get-option (car mirror-list) 'name)))
(update-mirror)))))

(define (ui-return)
(form-replace "/mirror"))

(define (ui-write)
(catch/message
(lambda()
(apply woo-write "/mirror/repository/"
'commit #t
'name (form-value "name")
'language (form-value "language")
(form-value-list *parameters*))
(ui-return))))

(define (ui-clear)
(and (form-confirm (_ "Are really want to clear local repository?") (_ "Question") (_ "Yes") (_ "No"))
(catch/message
(lambda()
(apply woo-write "/mirror/repository/"
'clear #t
'name (form-value "name")
'language (form-value "language")
(form-value-list *parameters*))
(ui-return)))))

(define (init)
(ui-read)
(form-bind "mirror" "change" update-mirror)
(form-bind "apply" "click" ui-write)
(form-bind "reset" "click" ui-read)
(form-bind "clear" "click" ui-clear))

alterator-mirror-0.4.2/ui/mirror/repository/index.html000064400000000000000000000033121215537232400231660ustar00rootroot00000000000000<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<!-- sources.list administration module -->
<html wf="none">
<body>
<form method="POST">
<table>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td style="text-align:right"><span translate="_">Repository:</span></td>
<td><span class="alterator-label" name="description"/></td>
</tr>

<tr>
<td colspan="2">&nbsp;</td>
</tr>

<tr>
<td style="text-align:right"><span translate="_">Source:</span></td>
<td>
<select name="mirror"/>
<br/>
<input type="text" name="custom_url" class="text" style="width:98%"/>
</td>
</tr>

<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td style="text-align:right"><span translate="_">Architectures:</span></td>
<td><table class="alterator-checklistbox" name="arch"/></td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td colspan="2">
<input type="checkbox" name="local" value="#t"/>
<span translate="_" name="local">Local mirror of repository</span>
</td>
</tr>
<tr>
<td colspan="2">
<input type="checkbox" name="publish" value="#t"/>
<span translate="_">Publish as a repository for automatic updates</span>
</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<input type="button" class="btn" name="apply" value="Apply"/>
&nbsp;
<input type="button" class="btn" name="reset" value="Reset"/>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
<input type="button" class="btn" name="clear" value="Clear local mirror"/>
</td>
</tr>
</table>
</form>
</body>
</html>
 
дизайн и разработка: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
текущий майнтейнер: Michael Shigorin