nix-tools/bin/deployiso.in
2016-02-25 06:40:39 +01:00

133 lines
3.7 KiB
Bash

#!/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.
version=@version@
LIBDIR='@libdir@'
SYSCONFDIR='@sysconfdir@'
[[ -r ${LIBDIR}/util-msg.sh ]] && source ${LIBDIR}/util-msg.sh
import ${LIBDIR}/util.sh
import ${LIBDIR}/util-publish.sh
show_profile(){
info "Iso: [$1]"
prepare_transfer "$1"
msg2 "src_dir: ${src_dir}"
msg2 "remote_dir: ${remote_dir}"
}
display_settings(){
show_version
show_config
msg "PROFILE:"
msg2 "sets_dir_iso: %s" "${sets_dir_iso}"
msg2 "buildsets: %s" "$(list_sets ${sets_dir_iso})"
msg2 "buildset_iso: %s" "${buildset_iso}"
msg2 "is_buildset: %s" "${is_buildset}"
msg "OPTIONS:"
msg2 "arch: %s" "${arch}"
msg2 "initsys: %s" "${initsys}"
msg2 "limit: %s kB/s" "${limit}"
msg "ARGS:"
msg2 "update: %s" "${update}"
msg2 "remote_create: %s" "${remote_create}"
msg2 "torrent_create: %s" "${torrent_create}"
msg2 "verbose: %s" "${verbose}"
msg2 "rsync_args: %s" "${rsync_args[*]}"
${torrent_create} && msg2 "mktorrent_args: %s" "${mktorrent_args[*]}"
msg "HOST:"
msg2 "dist_release: %s" "${dist_release}"
msg "REMOTE:"
msg2 "remote_url: %s" "${remote_url}"
msg2 "remote_project: %s" "${remote_project}"
msg2 "remote_target: %s" "${remote_target}"
msg2 "remote_user: %s" "${remote_user}"
if ${torrent_create};then
msg2 "tracker_url: %s" "${tracker_url}"
msg2 "piece_size: %s" "${piece_size}"
fi
msg "UPLOAD QUEUE:"
run show_profile "${buildset_iso}"
}
load_user_info
load_config "${USERCONFDIR}/manjaro-tools.conf"
load_config "${SYSCONFDIR}/manjaro-tools.conf"
run_dir=${cache_dir_iso}
pretend=false
remote_create=false
update=false
verbose=false
torrent_create=false
rsync_args=(-aP --progress -e ssh)
mktorrent_args=(-v -p)
usage() {
echo "Usage: ${0##*/} [options]"
echo " -p Source folder to upload [default:${buildset_iso}]"
echo " -a Arch to upload [default:${arch}]"
echo " -i The iso's init system [default:${initsys}]"
echo " -l Limit bandwidth in kB/s [default:${limit}]"
echo ' -c Create new remote edition_type with subtree'
echo ' -t Create a torrent from source folder'
echo ' -u Update remote iso'
echo ' -q Query settings and pretend upload'
echo ' -v Verbose output'
echo ' -h This help'
echo ''
echo ''
exit $1
}
opts='p:a:l:i:ctuvqh'
while getopts "${opts}" arg; do
case "${arg}" in
p) buildset_iso="$OPTARG" ;;
a) arch="$OPTARG" ;;
i) initsys="$OPTARG" ;;
l) limit="$OPTARG" ;;
c) remote_create=true ;;
t) torrent_create=true ;;
u) update=true; rsync_args+=(-u) ;;
v) verbose=true; rsync_args+=(-v --stats) ;;
q) pretend=true; rsync_args+=(-n) ;;
h|?) usage 0 ;;
*) echo "invalid argument '${arg}'"; usage 1 ;;
esac
done
shift $(($OPTIND - 1))
timer_start=$(get_timer)
eval_buildset "${sets_dir_iso}" "${buildset_iso}"
rsync_args+=(--bwlimit=${limit})
mktorrent_args+=(-l ${piece_size} -a ${tracker_url})
sf_url=${remote_user},${remote_project}@frs.${remote_url}:${remote_target}/${remote_project}
shell_url=${remote_user},${remote_project}@shell.${remote_url}
${pretend} && display_settings && exit 1
run sync_dir "${buildset_iso}"