manjaro-tools/lib/util-publish.sh

68 lines
2.1 KiB
Bash
Raw Normal View History

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
}
gen_webseed(){
local webseed seed="$1"
for mirror in ${iso_mirrors[@]};do
webseed=${webseed:-}${webseed:+,}"http://${mirror}.dl.${seed}"
done
echo ${webseed}
}
make_torrent(){
find ${src_dir} -type f -name "*.torrent" -delete
if [[ -n $(find ${src_dir} -type f -name "*.iso") ]]; then
for iso in $(ls ${src_dir}/*.iso);do
2018-04-11 23:53:33 +02:00
local seed=${host}/projects/${project}/storage/${profile}/${iso##*/}
local mktorrent_args=(-c "${torrent_meta}" -p -l ${piece_size} -a ${tracker_url} -w $(gen_webseed ${seed}))
${verbose} && mktorrent_args+=(-v)
msg2 "Creating (%s) ..." "${iso##*/}.torrent"
mktorrent ${mktorrent_args[*]} -o ${iso}.torrent ${iso}
done
fi
}
prepare_transfer(){
profile="$1"
2017-02-16 10:22:42 +01:00
edition=$(get_edition "${profile}")
[[ -z ${project} ]] && project="$(get_project)"
url=$(connect)
target_dir="${profile}/${dist_release}"
src_dir="${run_dir}/${edition}/${target_dir}"
${torrent} && make_torrent
}
sync_dir(){
cont=1
max_cont=10
prepare_transfer "$1"
2018-04-14 20:11:30 +02:00
msg "Start upload [%s] to [%s] ..." "$1" "${project}"
while [[ $cont -le $max_cont ]]; do
rsync ${rsync_args[*]} ${src_dir}/ ${url}/${target_dir}/
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
done
2015-11-12 19:03:21 +01:00
}