2015-11-12 19:03:21 +01:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; version 2 of the License.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
2016-07-15 00:50:50 +02:00
|
|
|
connect(){
|
2018-04-11 23:53:33 +02:00
|
|
|
local storage="@storage.osdn.net:/storage/groups/m/ma/"
|
|
|
|
echo "${account}${storage}${project}"
|
2016-07-15 00:50:50 +02:00
|
|
|
}
|
|
|
|
|
2017-02-12 19:19:18 +01:00
|
|
|
make_torrent(){
|
2017-02-13 21:38:24 +01:00
|
|
|
find ${src_dir} -type f -name "*.torrent" -delete
|
2017-02-13 09:53:21 +01:00
|
|
|
|
2017-02-13 21:38:24 +01:00
|
|
|
if [[ -n $(find ${src_dir} -type f -name "*.iso") ]]; then
|
|
|
|
for iso in $(ls ${src_dir}/*.iso);do
|
2018-04-15 12:19:15 +02:00
|
|
|
local seed=https://${host}/projects/${project}/storage/${profile}/${dist_release}/${iso##*/}
|
|
|
|
local mktorrent_args=(-c "${torrent_meta}" -p -l ${piece_size} -a ${tracker_url} -w ${seed})
|
2017-02-13 21:45:01 +01:00
|
|
|
${verbose} && mktorrent_args+=(-v)
|
2017-02-13 21:38:24 +01:00
|
|
|
msg2 "Creating (%s) ..." "${iso##*/}.torrent"
|
|
|
|
mktorrent ${mktorrent_args[*]} -o ${iso}.torrent ${iso}
|
|
|
|
done
|
|
|
|
fi
|
2017-02-12 19:19:18 +01:00
|
|
|
}
|
|
|
|
|
2015-11-30 18:59:57 +01:00
|
|
|
prepare_transfer(){
|
2017-02-13 09:53:21 +01:00
|
|
|
profile="$1"
|
2018-04-15 03:36:45 +02:00
|
|
|
hidden="$2"
|
2017-02-16 10:22:42 +01:00
|
|
|
edition=$(get_edition "${profile}")
|
2018-04-14 12:26:49 +02:00
|
|
|
[[ -z ${project} ]] && project="$(get_project)"
|
2017-02-12 23:37:18 +01:00
|
|
|
url=$(connect)
|
2017-02-12 19:19:18 +01:00
|
|
|
|
2018-02-15 11:52:53 +01:00
|
|
|
target_dir="${profile}/${dist_release}"
|
|
|
|
src_dir="${run_dir}/${edition}/${target_dir}"
|
2018-04-15 03:15:45 +02:00
|
|
|
|
2018-04-15 03:36:45 +02:00
|
|
|
${hidden} && target_dir="${profile}/.${dist_release}"
|
2017-02-12 23:37:18 +01:00
|
|
|
${torrent} && make_torrent
|
2016-02-18 00:02:11 +01:00
|
|
|
}
|
|
|
|
|
2015-11-17 17:04:04 +01:00
|
|
|
sync_dir(){
|
2018-04-15 02:28:18 +02:00
|
|
|
cont=1
|
|
|
|
max_cont=10
|
2018-04-15 03:36:45 +02:00
|
|
|
prepare_transfer "$1" "${hidden}"
|
2018-04-14 20:11:30 +02:00
|
|
|
msg "Start upload [%s] to [%s] ..." "$1" "${project}"
|
2018-03-11 18:09:29 +01:00
|
|
|
while [[ $cont -le $max_cont ]]; do
|
2018-02-15 11:52:53 +01:00
|
|
|
rsync ${rsync_args[*]} ${src_dir}/ ${url}/${target_dir}/
|
2018-04-15 02:28:18 +02:00
|
|
|
if [[ $? != 0 ]]; then
|
|
|
|
cont=$(($cont + 1))
|
|
|
|
msg "Failed to upload [%s] now try again: try $cont of $max_cont" "$1"
|
|
|
|
sleep 2
|
|
|
|
else
|
|
|
|
cont=$(($max_cont + 1))
|
|
|
|
msg "Done upload [%s]" "$1"
|
|
|
|
show_elapsed_time "${FUNCNAME}" "${timer_start}"
|
|
|
|
fi
|
2018-03-11 16:45:27 +01:00
|
|
|
done
|
2015-11-12 19:03:21 +01:00
|
|
|
}
|