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.
|
|
|
|
|
2020-02-29 10:59:50 +01:00
|
|
|
local MINIMAL
|
|
|
|
|
2016-07-15 00:50:50 +02:00
|
|
|
connect(){
|
2018-04-15 15:59:44 +02:00
|
|
|
${alt_storage} && server="storage-in" || server="storage"
|
2018-04-15 15:54:20 +02:00
|
|
|
local storage="@${server}.osdn.net:/storage/groups/m/ma/"
|
2018-04-11 23:53:33 +02:00
|
|
|
echo "${account}${storage}${project}"
|
2016-07-15 00:50:50 +02:00
|
|
|
}
|
|
|
|
|
2020-02-19 20:26:23 +01:00
|
|
|
connect_shell(){
|
|
|
|
local shell="@shell.osdn.net:/home/groups/m/ma/"
|
|
|
|
echo "${account}${shell}${project}"
|
2019-12-02 00:35:24 +01: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
|
2020-02-19 20:26:23 +01:00
|
|
|
isos=$(ls ${src_dir}/*.iso)
|
|
|
|
for iso in ${isos}; do
|
2018-04-27 11:19:36 +02:00
|
|
|
local seed=https://${host}/dl/${project}/${iso##*/}
|
2018-04-15 12:19:15 +02:00
|
|
|
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)"
|
2019-12-02 00:35:24 +01:00
|
|
|
server=$(connect)
|
2017-02-12 19:19:18 +01:00
|
|
|
|
2020-02-19 20:26:23 +01:00
|
|
|
webshell=$(connect_shell)
|
|
|
|
htdocs="htdocs/${profile}"
|
|
|
|
|
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}"
|
2016-02-18 00:02:11 +01:00
|
|
|
}
|
|
|
|
|
2018-04-15 20:10:20 +02:00
|
|
|
start_agent(){
|
|
|
|
msg2 "Initializing SSH agent..."
|
|
|
|
ssh-agent | sed 's/^echo/#echo/' > "$1"
|
|
|
|
chmod 600 "$1"
|
|
|
|
. "$1" > /dev/null
|
|
|
|
ssh-add
|
|
|
|
}
|
|
|
|
|
|
|
|
ssh_add(){
|
|
|
|
local ssh_env="$USER_HOME/.ssh/environment"
|
|
|
|
|
|
|
|
if [ -f "${ssh_env}" ]; then
|
|
|
|
. "${ssh_env}" > /dev/null
|
|
|
|
ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
|
|
|
|
start_agent ${ssh_env};
|
|
|
|
}
|
|
|
|
else
|
|
|
|
start_agent ${ssh_env};
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-11-17 17:04:04 +01:00
|
|
|
sync_dir(){
|
2018-04-16 00:29:15 +02:00
|
|
|
count=1
|
|
|
|
max_count=10
|
2018-04-15 03:36:45 +02:00
|
|
|
prepare_transfer "$1" "${hidden}"
|
2018-04-15 17:02:39 +02:00
|
|
|
|
2018-04-15 17:28:48 +02:00
|
|
|
${torrent} && make_torrent
|
|
|
|
${sign} && signiso "${src_dir}"
|
2018-04-15 20:10:20 +02:00
|
|
|
${ssh_agent} && ssh_add
|
2018-04-15 17:02:39 +02:00
|
|
|
|
2018-04-14 20:11:30 +02:00
|
|
|
msg "Start upload [%s] to [%s] ..." "$1" "${project}"
|
2019-12-02 00:35:24 +01:00
|
|
|
|
|
|
|
while [[ $count -le $max_count ]]; do
|
2020-03-01 18:40:24 +01:00
|
|
|
rsync ${rsync_args[*]} --exclude '.latest*' --exclude 'index.html' --exclude 'links.txt' ${src_dir}/ ${server}/${target_dir}/
|
2018-04-15 02:28:18 +02:00
|
|
|
if [[ $? != 0 ]]; then
|
2018-04-16 00:29:15 +02:00
|
|
|
count=$(($count + 1))
|
|
|
|
msg "Upload failed. retrying (%s/%s) ..." "$count" "$max_count"
|
2018-04-15 02:28:18 +02:00
|
|
|
sleep 2
|
|
|
|
else
|
2018-04-16 00:29:15 +02:00
|
|
|
count=$(($max_count + 1))
|
2020-02-19 20:26:23 +01:00
|
|
|
|
2020-03-01 18:40:24 +01:00
|
|
|
${upd_homepage} && pull_hp_repo
|
2020-02-29 10:59:50 +01:00
|
|
|
${shell_upload} && upload_permalinks
|
2020-02-19 20:26:23 +01:00
|
|
|
|
2018-04-15 02:28:18 +02:00
|
|
|
msg "Done upload [%s]" "$1"
|
|
|
|
show_elapsed_time "${FUNCNAME}" "${timer_start}"
|
|
|
|
fi
|
2018-03-11 16:45:27 +01:00
|
|
|
done
|
2019-12-02 00:35:24 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-02-29 10:59:50 +01:00
|
|
|
upload_permalinks(){
|
|
|
|
## permalinks for full ISO
|
2020-02-19 21:29:50 +01:00
|
|
|
if [[ -f "${src_dir}/.latest" ]]; then
|
2020-02-29 10:59:50 +01:00
|
|
|
msg "Uploading permalinks ..."
|
2020-02-19 20:26:23 +01:00
|
|
|
LATEST_ISO=$(sed -e 's/\"/\n/g' < "${src_dir}/.latest" | grep -Eo 'http.*iso$' -m1 | awk '{split($0,x,"/"); print x[6]}')
|
|
|
|
PKGLIST="${LATEST_ISO/.iso/-pkgs.txt}"
|
|
|
|
|
2020-02-29 10:59:50 +01:00
|
|
|
## upload redirector files
|
2020-02-19 20:26:23 +01:00
|
|
|
[[ -f "${src_dir}/.latest" ]] && sync_latest_html
|
|
|
|
[[ -f "${src_dir}/.latest.php" ]] && sync_latest_php
|
|
|
|
|
2020-02-29 10:59:50 +01:00
|
|
|
## upload verification files, torrent and package list
|
2020-02-19 20:26:23 +01:00
|
|
|
[[ -f "${src_dir}/${LATEST_ISO}.torrent" ]] && sync_latest_torrent
|
|
|
|
[[ -f "${src_dir}/${LATEST_ISO}.sig" ]] && sync_latest_signature
|
|
|
|
[[ -f "${src_dir}/${LATEST_ISO}.sha1" ]] && sync_latest_checksum_sha1
|
|
|
|
[[ -f "${src_dir}/${LATEST_ISO}.sha256" ]] && sync_latest_checksum_sha256
|
2020-02-19 21:15:43 +01:00
|
|
|
[[ -f "${src_dir}/${PKGLIST}" ]] && sync_latest_pkg_list
|
2020-03-01 18:40:24 +01:00
|
|
|
|
|
|
|
${upd_homepage} && upd_dl_checksum
|
2020-02-29 10:59:50 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
## permalinks for minimal ISO
|
|
|
|
if [[ -f "${src_dir}/.latest-minimal" ]]; then
|
|
|
|
msg "Uploading permalinks (minimal) ..."
|
|
|
|
MINIMAL="yes"
|
|
|
|
LATEST_ISO=$(sed -e 's/\"/\n/g' < "${src_dir}/.latest-minimal" | grep -Eo 'http.*iso$' -m1 | awk '{split($0,x,"/"); print x[6]}')
|
|
|
|
PKGLIST="${LATEST_ISO/.iso/-pkgs.txt}"
|
|
|
|
|
|
|
|
## upload redirector files
|
|
|
|
[[ -f "${src_dir}/.latest-minimal" ]] && sync_latest_html
|
|
|
|
[[ -f "${src_dir}/.latest-minimal.php" ]] && sync_latest_php
|
|
|
|
|
|
|
|
## upload verification files, torrent and package list
|
|
|
|
[[ -f "${src_dir}/${LATEST_ISO}.torrent" ]] && sync_latest_torrent
|
|
|
|
[[ -f "${src_dir}/${LATEST_ISO}.sig" ]] && sync_latest_signature
|
|
|
|
[[ -f "${src_dir}/${LATEST_ISO}.sha1" ]] && sync_latest_checksum_sha1
|
|
|
|
[[ -f "${src_dir}/${LATEST_ISO}.sha256" ]] && sync_latest_checksum_sha256
|
|
|
|
[[ -f "${src_dir}/${PKGLIST}" ]] && sync_latest_pkg_list
|
2020-03-01 18:40:24 +01:00
|
|
|
|
|
|
|
${upd_homepage} && upd_dl_checksum_minimal
|
2020-02-19 21:29:50 +01:00
|
|
|
fi
|
2020-03-01 18:40:24 +01:00
|
|
|
|
|
|
|
${upd_homepage} && upd_dl_version && push_hp_repo
|
2020-02-19 20:26:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sync_latest_pkg_list(){
|
|
|
|
msg2 "Uploading package list ..."
|
|
|
|
local pkglist="latest-pkgs.txt"
|
2020-02-29 10:59:50 +01:00
|
|
|
[[ ${MINIMAL} == "yes" ]] && pkglist="latest-minimal-pkgs.txt"
|
2020-02-29 17:42:20 +01:00
|
|
|
chmod g+w "${src_dir}/${PKGLIST}"
|
2020-03-01 09:21:14 +01:00
|
|
|
scp -p "${src_dir}/${PKGLIST}" "${webshell}/${htdocs}/${pkglist}"
|
2020-02-19 20:26:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sync_latest_checksum_sha256(){
|
|
|
|
msg2 "Uploading sha256 checksum file ..."
|
|
|
|
local filename="${LATEST_ISO}.sha256"
|
|
|
|
local checksum_file="latest.sha256"
|
2020-02-29 10:59:50 +01:00
|
|
|
[[ ${MINIMAL} == "yes" ]] && checksum_file="latest-minimal.sha256"
|
2020-02-29 17:42:20 +01:00
|
|
|
chmod g+w "${src_dir}/${filename}"
|
2020-03-01 09:21:14 +01:00
|
|
|
scp -p "${src_dir}/${filename}" "${webshell}/${htdocs}/${checksum_file}"
|
2020-02-19 20:26:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sync_latest_checksum_sha1(){
|
|
|
|
msg2 "Uploading sha1 checksum file ..."
|
|
|
|
local filename="${LATEST_ISO}.sha1"
|
|
|
|
local checksum_file="latest.sha1"
|
2020-02-29 10:59:50 +01:00
|
|
|
[[ ${MINIMAL} == "yes" ]] && checksum_file="latest-minimal.sha1"
|
2020-02-29 17:42:20 +01:00
|
|
|
chmod g+w "${src_dir}/${filename}"
|
2020-03-01 09:21:14 +01:00
|
|
|
scp -p "${src_dir}/${filename}" "${webshell}/${htdocs}/${checksum_file}"
|
2020-02-19 20:26:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sync_latest_signature(){
|
|
|
|
msg2 "Uploading signature file ..."
|
|
|
|
local filename="${LATEST_ISO}.sig"
|
|
|
|
local signature="latest.sig"
|
2020-02-29 10:59:50 +01:00
|
|
|
[[ ${MINIMAL} == "yes" ]] && signature="latest-minimal.sig"
|
2020-02-29 17:42:20 +01:00
|
|
|
chmod g+w "${src_dir}/${filename}"
|
2020-03-01 09:21:14 +01:00
|
|
|
scp -p "${src_dir}/${filename}" "${webshell}/${htdocs}/${signature}"
|
2020-02-19 20:26:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sync_latest_torrent(){
|
|
|
|
msg2 "Uploading torrent file ..."
|
|
|
|
local filename="${LATEST_ISO}.torrent"
|
|
|
|
local torrent="latest.torrent"
|
2020-02-29 10:59:50 +01:00
|
|
|
[[ ${MINIMAL} == "yes" ]] && torrent="latest-minimal.torrent"
|
2020-02-29 17:42:20 +01:00
|
|
|
chmod g+w "${src_dir}/${filename}"
|
2020-03-01 09:21:14 +01:00
|
|
|
scp -p "${src_dir}/${filename}" "${webshell}/${htdocs}/${torrent}"
|
2015-11-12 19:03:21 +01:00
|
|
|
}
|
2020-01-24 14:33:30 +01:00
|
|
|
|
|
|
|
sync_latest_php(){
|
|
|
|
msg2 "Uploading php redirector ..."
|
2020-02-29 17:42:20 +01:00
|
|
|
local filename=".latest.php"
|
2020-01-24 14:33:30 +01:00
|
|
|
local php="latest.php"
|
2020-03-01 09:49:06 +01:00
|
|
|
[[ ${MINIMAL} == "yes" ]] && filename=".latest-minimal.php" && php="latest-minimal.php"
|
2020-02-29 17:42:20 +01:00
|
|
|
chmod g+w "${src_dir}/${filename}"
|
2020-03-01 09:21:14 +01:00
|
|
|
scp -p "${src_dir}/.${php}" "${webshell}/${htdocs}/${php}"
|
2020-02-19 20:26:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sync_latest_html(){
|
|
|
|
msg2 "Uploading url redirector ..."
|
2020-02-29 17:42:20 +01:00
|
|
|
local filename=".latest"
|
2020-02-19 20:26:23 +01:00
|
|
|
local html="latest"
|
2020-03-01 09:42:14 +01:00
|
|
|
[[ ${MINIMAL} == "yes" ]] && filename=".latest-minimal" && html="latest-minimal"
|
2020-02-29 17:42:20 +01:00
|
|
|
chmod g+w "${src_dir}/${filename}"
|
2020-03-01 09:21:14 +01:00
|
|
|
scp -p "${src_dir}/.${html}" "${webshell}/${htdocs}/${html}"
|
2020-01-24 14:33:30 +01:00
|
|
|
}
|
2020-03-01 18:40:24 +01:00
|
|
|
|
|
|
|
pull_hp_repo(){
|
|
|
|
load_vars "$USER_HOME/.makepkg.conf" || load_vars /etc/makepkg.conf
|
|
|
|
[[ -z $SRCDEST ]] && SRCDEST=${cache_dir}
|
|
|
|
|
|
|
|
hp_repo=manjaro-homepage
|
2020-03-24 16:39:47 +01:00
|
|
|
[[ ${edition} == "manjaro" ]] && _edition="official" || _edition=${edition}
|
|
|
|
dl_file="${SRCDEST}/${hp_repo}/site/content/downloads/${_edition}/${profile}.md"
|
2020-03-01 18:40:24 +01:00
|
|
|
|
|
|
|
cd "${SRCDEST}"
|
|
|
|
if [[ ! -d "${hp_repo}" ]]; then
|
|
|
|
msg "Cloning manjaro.org"
|
|
|
|
git clone "ssh://git@gitlab.manjaro.org:22277/webpage/${hp_repo}.git"
|
|
|
|
else
|
|
|
|
cd "${hp_repo}"
|
|
|
|
msg "Pulling manjaro.org"
|
|
|
|
git pull
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
push_hp_repo(){
|
|
|
|
cd "${SRCDEST}/${hp_repo}"
|
|
|
|
msg "Updating manjaro.org"
|
|
|
|
git add ${dl_file}
|
|
|
|
git commit -m "update download ${profile}"
|
|
|
|
git push
|
|
|
|
}
|
|
|
|
|
|
|
|
upd_dl_checksum(){
|
|
|
|
local checksum=$(cat "${src_dir}/${LATEST_ISO}.sha1" | cut -d' ' -f1)
|
|
|
|
msg "Updating download page:"
|
|
|
|
msg2 "checksum > ${checksum}"
|
|
|
|
sed -i "/Download_x64_Checksum/c\Download_x64_Checksum = \"${checksum}\"" ${dl_file}
|
|
|
|
}
|
|
|
|
|
|
|
|
upd_dl_checksum_minimal(){
|
|
|
|
local checksum=$(cat "${src_dir}/${LATEST_ISO}.sha1" | cut -d' ' -f1)
|
|
|
|
msg "Updating download page:"
|
|
|
|
msg2 "checksum_minimal > ${checksum}"
|
|
|
|
sed -i "/Download_Minimal_x64_Checksum/c\Download_Minimal_x64_Checksum = \"${checksum}\"" ${dl_file}
|
|
|
|
}
|
|
|
|
|
|
|
|
upd_dl_version(){
|
|
|
|
timestamp=$(date -u +%Y-%m-%dT%T%Z)
|
|
|
|
msg2 "Version > ${dist_release}"
|
|
|
|
sed -i "/Version/c\Version = \"${dist_release}\"" ${dl_file}
|
|
|
|
msg2 "date > ${timestamp}"
|
2020-06-12 22:29:03 +02:00
|
|
|
sed -i "/^date/c\date = \"${timestamp}\"" ${dl_file}
|
2020-03-01 18:40:24 +01:00
|
|
|
}
|