blob: 7463e552a9c7fc16eb4336238ad1d09a26027ed9 (
plain) (
tree)
|
|
#!/usr/bin/env bash
version_file="versions.txt"
checksum_file="sha256checksum.txt"
deploy_dir="public"
mode_url="https://manaplus.germantmw.de/versions/"
mode_file="mode.txt"
mirror_file="mirrorlist"
if [[ ${CI_PROJECT_DIR} == "" ]]; then
project="docker-testing" # change me
namespace="jak89_1" # change me
version_url="https://${namespace}.gitlab.io/${project}/${version_file}"
version_url2="https://gitlab.com/${project}/${project}/-/jobs/artifacts/master/raw/$deploy_dir/${version_file}?job=pages"
echo "[NON CI] : using local paths"
local=1
else
version_url="${CI_PAGES_URL}/${version_file}"
version_url2="https://gitlab.com/${CI_PROJECT_PATH}/-/jobs/artifacts/master/raw/$deploy_dir/${version_file}?job=${CI_JOB_NAME}"
local=0
fi
version_url3="https://manaplus.germantmw.de/versions/${version_file}" # fallback to my server if gitlab breaks its own pages *blames gitlab*
#add new mirrors to the end of BOTH lines
mirror_names=("gitlab.io gertmw.de")
mirror_urls=("https://themanaworld.gitlab.io/manaplus/builder/ https://manaplus.germantmw.de/versions/") # change me
last_checksum="https://gitlab.com/${CI_PROJECT_PATH}/-/jobs/artifacts/master/raw/build/${checksum_file}?job=mxe_gcc5"
#last_checksum_d="https://gitlab.com/${CI_PROJECT_PATH}/-/jobs/artifacts/master/raw/build/debug-${checksum_file}?job=mxe_gcc5" # not handled yet
# end of variable-scrabble (move this to gitlab-ci.yml laterâ„¢)
if [[ ! -d $deploy_dir ]]; then
mkdir -p $deploy_dir
fi
# buffer for .html
_b(){
BUFFER_HTML=${BUFFER_HTML}${1}
}
# buffer for .xml
_x(){
BUFFER_XML=${BUFFER_XML}${1}
}
# buffer for .json
_j(){
BUFFER_JSON=${BUFFER_JSON}${1}
}
gen_page(){
_b "<!DOCTYPE html><html>"
_b "<head><title>MirrorList</title></head>"
_b "<body><center>"
_b "<h1>ManaPlus Mirror & Version List</h1>"
_b "<sup>hover to see checksums</sup>"
_b "<table border='1px solid black'>"
_b "<tr>"
for mirror in $mirror_names; do
_b "<th>$mirror</th>"
done
_b "</tr>"
_x "<?xml version='1.0' encoding='utf-8'?>\n"
_x "<!--\n Authors: jak1\n Copyright: (C) 2021 TheManaWorld Developers\n Generated by: Gitlab deploy (manual changes will get overwritten)\n-->\n"
_j "{\n"
_j " \"#comment\": \"Authors: jak1 Copyright: (C) 2021 TheManaWorld Developers Generated by: Gitlab deploy (manual changes will get overwritten)\",\n"
_j " \"versions\": {\n"
_x "<versions>\n";
while IFS= read -r line; do
# ${line#* } = checksum
# ${line% *} = filename
_b "<tr>"
_x " <version file='${line#* }' checksum='${line% *}'>\n";
_j " \"version\": {\n \"-file\": \"${line#* }\",\n \"-checksum\": \"${line% *}\",\n \"mirror\": [\n"
c=0
for mirror_url in $mirror_urls; do
_b "<td><a title='sha256:${line% *}' href='${mirror_url}${line#* }'>${line#* }</a></td>";
_x " <mirror url='${mirror_url}${line#* }' />\n";
_j " {\n \"-url\": \"${mirror_url}${line#* }\"\n }"
if [[ $c == ${#mirror_urls[@]} ]]; then
_j "\n"
else
_j ",\n"
fi
((c++))
done
_j " ]\n }\n }\n"
_x " </version>\n";
_b "</tr>"
done < $version_file
_x "</versions>\n";
_j "}\n"
_b "</table>"
_b "<a href='$version_file'>$version_file</a>"
_b "</center></body>"
_b "</html>"
#write out files (keep source formating for xml & json)
echo $BUFFER_HTML > $deploy_dir/$mirror_file.html
echo -e "$BUFFER_XML" > $deploy_dir/$mirror_file.xml
echo -e "$BUFFER_JSON" > $deploy_dir/$mirror_file.json
}
add_new_release(){
wget $last_checksum -O $checksum_file -q
#if #TODO: check if new tag/version exists, of if the pipeline got trigerred manualy
checksum=$(<${checksum_file})
echo $checksum >> $version_file
#fi
}
get_version_file(){
# -O is needed for artifacts!
# getting version file from deployed pages (this can break)
wget $version_url -O $version_file -q
if [[ ! -f $version_file ]]; then
echo "cant download '${version_file}' from '${version_url}'"
# getting version file from last artifacts (this can break)
wget $version_url2 -O $version_file -q
if [[ ! -f $version_file ]]; then
echo "cant download '${version_file}' from '${version_url2}'"
# getting version file from my server as fallback
wget $version_url3 -O $version_file -q
if [[ ! -f $version_file ]]; then
echo "cant download '${version_file}' from '${version_url3}'"
# this should only happen for the first build!
touch $version_file
fi
fi
fi
}
# simple mode check for testings only
get_mode(){
mode=""
wget $mode_url$mode_file -q
if grep -q testing "$mode_file"; then
echo "[deploy] test only!"
mode="test"
return 0
elif grep -q release "$mode_file"; then
echo "[deploy] release/stable!"
return 1
else # we can also add other modes here, atm just to dont deploy tonns of test versions :)
echo "[deploy] ERR: unknown mode!"
exit 1
fi
}
local_cleanup(){
rm $checksum_file
rm $mode_file
}
deploy(){
mv $version_file $deploy_dir || exit 1
if [[ $local == 0 ]]; then
scp -o StrictHostKeyChecking=no $deploy_dir/$version_file $DEPLOY_HOST:$DEPLOY_LOCATION$mode || echo "WARN: cant deploy to Server!"
scp -o StrictHostKeyChecking=no $deploy_dir/$mirror_file.xml $DEPLOY_HOST:$DEPLOY_LOCATION$mode || echo "WARN: cant deploy to Server!"
scp -o StrictHostKeyChecking=no $deploy_dir/$mirror_file.json $DEPLOY_HOST:$DEPLOY_LOCATION$mode || echo "WARN: cant deploy to Server!"
scp -o StrictHostKeyChecking=no $deploy_dir/$mirror_file.html $DEPLOY_HOST:$DEPLOY_LOCATION$mode || echo "WARN: cant deploy to Server!"
fi
# i guess i need to get old artifacts to keep pages in case it was a test build
if get_mode; then
find $deploy_dir -type f -not -name '*.xsd' -delete
#else
# deploying versions
#scp -o StrictHostKeyChecking=no $deploy_dir/.zip $DEPLOY_HOST:$DEPLOY_LOCATION$mode || echo "WARN: cant deploy to Server!"
#scp -o StrictHostKeyChecking=no $checksum_file.txt $DEPLOY_HOST:$DEPLOY_LOCATION$mode || echo "WARN: cant deploy to Server!"
fi
}
linters(){
xmllint --schema $deploy_dir/$mirror_file.xsd $deploy_dir/$mirror_file.xml --noout || exit 1
jsonlint-php $deploy_dir/$mirror_file.json || exit 1
}
get_version_file
add_new_release
gen_page
linters
deploy
local_cleanup
echo "${mode}deploy passed \\o/"
|