feat: make user and host configurable
This commit is contained in:
parent
a31ac1ee90
commit
41a02bf5e8
1 changed files with 107 additions and 57 deletions
64
rm-sync.sh
64
rm-sync.sh
|
@ -1,15 +1,53 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -e
|
set -euo pipefail
|
||||||
|
|
||||||
user=root
|
user="root"
|
||||||
host=10.11.99.1
|
host="10.11.99.1"
|
||||||
|
|
||||||
dir="$(mktemp -d)"
|
args=()
|
||||||
|
|
||||||
|
print_help() {
|
||||||
|
echo "Usage: script.sh [options] [PDF files...]"
|
||||||
|
echo ""
|
||||||
|
echo "Options:"
|
||||||
|
echo " --user <username> Specify the username (default: root)"
|
||||||
|
echo " --host <hostname> Specify the host (default: 10.11.99.1)"
|
||||||
|
echo " --help, -h Display this help message"
|
||||||
|
echo ""
|
||||||
|
echo "PDF files:"
|
||||||
|
echo " List of PDF files to be processed"
|
||||||
|
}
|
||||||
|
|
||||||
|
while [[ "$#" -gt 0 ]]; do
|
||||||
|
case $1 in
|
||||||
|
--user) user="$2"; shift ;;
|
||||||
|
--host) host="$2"; shift ;;
|
||||||
|
--help|-h) print_help; exit 0 ;;
|
||||||
|
*) args+=("$1") ;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
set -- "${args[@]}"
|
||||||
|
|
||||||
|
if [[ "$#" -eq 0 ]]; then
|
||||||
|
print_help
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
process_pdf() {
|
||||||
|
local pdf_fname
|
||||||
|
local metadata_body
|
||||||
|
local pdf_docname
|
||||||
|
local document_uuid
|
||||||
|
local content_body
|
||||||
|
|
||||||
pdf_fname="$1"
|
pdf_fname="$1"
|
||||||
pdf_docname="$(basename "$1" .pdf)"
|
pdf_docname="$(basename "$pdf_fname" .pdf)"
|
||||||
document_uuid="$(uuidgen)"
|
document_uuid="$(uuidgen)"
|
||||||
|
|
||||||
|
echo "Preparing '$pdf_fname'"
|
||||||
|
|
||||||
cat "$pdf_fname" > "${dir}/${document_uuid}.pdf"
|
cat "$pdf_fname" > "${dir}/${document_uuid}.pdf"
|
||||||
|
|
||||||
metadata_body="{
|
metadata_body="{
|
||||||
|
@ -51,7 +89,7 @@ content_body="{
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
|
|
||||||
pagedata_body=""
|
local pagedata_body=""
|
||||||
|
|
||||||
echo "$metadata_body" > "${dir}/${document_uuid}.metadata"
|
echo "$metadata_body" > "${dir}/${document_uuid}.metadata"
|
||||||
echo "$content_body" > "${dir}/${document_uuid}.content"
|
echo "$content_body" > "${dir}/${document_uuid}.content"
|
||||||
|
@ -61,5 +99,17 @@ for subdir in "" ".cache" ".highlight" ".textconversion" ".thumbnails"; do
|
||||||
mkdir "$dir/$document_uuid$subdir"
|
mkdir "$dir/$document_uuid$subdir"
|
||||||
done
|
done
|
||||||
|
|
||||||
scp -rp "$dir/$document_uuid".* $user@$host:/home/root/.local/share/remarkable/xochitl/
|
echo "Copying '$pdf_fname' as '$pdf_docname'"
|
||||||
|
scp -rq "$dir/$document_uuid".* "$user@$host:/home/root/.local/share/remarkable/xochitl/"
|
||||||
|
echo "Done transferring '$pdf_fname' as '$pdf_docname'"
|
||||||
|
}
|
||||||
|
|
||||||
|
dir="$(mktemp -d)"
|
||||||
|
|
||||||
|
for pdf_fname in "$@"; do
|
||||||
|
process_pdf "$pdf_fname"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Restarting xochitl"
|
||||||
ssh "$user@$host" systemctl restart xochitl
|
ssh "$user@$host" systemctl restart xochitl
|
||||||
|
echo "Done"
|
||||||
|
|
Loading…
Reference in a new issue