2020-07-14 19:29:13 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2021-02-11 04:49:32 +00:00
|
|
|
if [ ! -z $CI_COMMIT_BRANCH ];then
|
2021-02-11 05:03:47 +00:00
|
|
|
echo Gitlab CI Detected!
|
|
|
|
echo $NEOCITIES_USER > .env
|
|
|
|
echo $NEOCITIES_PASS >> .env
|
|
|
|
echo $NEOCITIES_KEY >> .env
|
2021-02-11 05:08:57 +00:00
|
|
|
else
|
|
|
|
source ./.env
|
2021-02-11 04:49:32 +00:00
|
|
|
fi
|
2020-07-14 19:29:13 +00:00
|
|
|
|
|
|
|
url="https://neocities.org"
|
|
|
|
auth="Authorization: Bearer $KEY"
|
|
|
|
site=.mirror
|
|
|
|
|
2020-07-14 23:39:30 +00:00
|
|
|
_upload_html() {
|
2020-07-25 01:46:38 +00:00
|
|
|
# fix this comparison cuz its busted
|
2020-07-14 23:39:30 +00:00
|
|
|
if [ ${1:0:1} = "" ];then
|
|
|
|
echo Path must start with ./
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-07-25 01:46:38 +00:00
|
|
|
for f in $@;do
|
|
|
|
remote_path=${f:1}
|
2021-02-11 04:41:38 +00:00
|
|
|
echo curl -s -o /dev/null -w '%{http_code}' -H "auth" -F "$remote_path=@$f" $url/api/upload
|
|
|
|
curl -s -o /dev/null -w '%{http_code}' -H "auth" -F "$remote_path=@$f" $url/api/upload
|
2020-07-25 01:46:38 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
_upload_media() {
|
|
|
|
[[ "${1:0:1}" == "./" ]] && \
|
|
|
|
echo 'Path must start with ./' && \
|
|
|
|
exit 1
|
|
|
|
|
2020-07-14 23:39:30 +00:00
|
|
|
for f in $@;do
|
2020-07-14 19:29:13 +00:00
|
|
|
remote_path=${f:1}
|
2021-02-11 04:41:38 +00:00
|
|
|
echo curl -s -o /dev/null -w '%{http_code}' -H "auth" -F "$remote_path=@$f" $url/api/upload
|
|
|
|
curl -s -o /dev/null -w '%{http_code}' -H "auth" -F "$remote_path=@$f" $url/api/upload
|
2020-07-14 19:29:13 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2021-02-09 03:49:08 +00:00
|
|
|
_upload_all_media() {
|
2021-02-09 04:43:59 +00:00
|
|
|
for file in $(find media -type f);do
|
2021-02-09 03:49:08 +00:00
|
|
|
echo Uploading media: $file
|
2021-02-09 04:43:59 +00:00
|
|
|
curl -H "$auth" -F "$file=@$file" $url/api/upload -s > /dev/null
|
2021-02-09 03:49:08 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2020-07-14 23:39:30 +00:00
|
|
|
html() {
|
|
|
|
# Total reupload of the site's html
|
|
|
|
_upload_html $(find -name '*.html')
|
|
|
|
}
|
|
|
|
|
|
|
|
roots() {
|
|
|
|
_upload_html ./*.html
|
|
|
|
}
|
|
|
|
|
|
|
|
folder() {
|
|
|
|
if [ -z $1];then
|
|
|
|
echo No folder specified > /dev/stderr
|
|
|
|
else
|
|
|
|
pushd $1 > /dev/null
|
|
|
|
_upload_html ./*.html
|
|
|
|
popd > /dev/null
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
_help() {
|
2020-07-14 19:29:13 +00:00
|
|
|
cat <<EOF
|
2020-07-25 01:46:38 +00:00
|
|
|
PATHS:
|
|
|
|
Use a fake relative path as if we were in "$site"
|
|
|
|
Example: gensite -m ./media/img/some-post/image.jpg ...
|
2020-07-14 19:29:13 +00:00
|
|
|
Options:
|
2020-07-14 23:39:30 +00:00
|
|
|
h => Reuploads all the html content
|
|
|
|
r => Uploads all root html pages
|
|
|
|
f [FOLDER] => Upload all html in [FOLDER]
|
2020-07-22 05:27:23 +00:00
|
|
|
s [PATH] => Upload single html page with mirrord path
|
2020-07-25 01:46:38 +00:00
|
|
|
m [PATH] => Upload any amount of media files
|
2021-02-09 03:49:08 +00:00
|
|
|
M => Upload all available media
|
2020-07-14 19:29:13 +00:00
|
|
|
EOF
|
2020-07-14 23:39:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if [ -z $1 ];then
|
|
|
|
_help
|
2020-07-14 19:29:13 +00:00
|
|
|
else
|
2020-07-14 23:39:30 +00:00
|
|
|
pushd $site > /dev/null
|
2021-02-09 03:49:08 +00:00
|
|
|
while getopts ':Hhrf:s:m:M' opt;do
|
2020-07-14 23:39:30 +00:00
|
|
|
case $opt in
|
|
|
|
H) _help;;
|
|
|
|
h) _upload_html $(find -name '*.html');; # Upload all html content
|
|
|
|
r) _upload_html ./*.html;; # Upload all root html pages
|
2020-07-14 23:42:54 +00:00
|
|
|
f) _upload_html $2/*.html;;# Upload html in the spec'd folder
|
2020-07-22 05:27:23 +00:00
|
|
|
s) _upload_html $2;;# upload single html page
|
2020-07-25 01:46:38 +00:00
|
|
|
m) _upload_media $2;;# upload raw file
|
2021-02-09 03:49:08 +00:00
|
|
|
M) _upload_all_media;;
|
2020-07-14 23:39:30 +00:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
popd > /dev/null
|
2020-07-14 19:29:13 +00:00
|
|
|
fi
|
|
|
|
|