-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathOpenEncryptedLibreOfficeDocument.sh
More file actions
executable file
·77 lines (51 loc) · 2.24 KB
/
Copy pathOpenEncryptedLibreOfficeDocument.sh
File metadata and controls
executable file
·77 lines (51 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
# This script is designed to be used with RDiezDocUtils.vbs ,
# see that file for more information.
# Copyright (c) 2025 R. Diez - Licensed under the GNU AGPLv3
set -o errexit
set -o nounset
set -o pipefail
declare -r SCRIPT_NAME="${BASH_SOURCE[0]##*/}" # This script's filename only, without any path components.
abort ()
{
echo >&2 && echo "Error in script \"$0\": $*" >&2
exit 1
}
# ------ Entry Point (only by convention) ------
if (( $# != 2 )); then
abort "Invalid command-line arguments. Please specify <document filename>, <password>."
fi
declare -r DOC_FILENAME="$1"
# It would be more secure to specify a file descriptor to read the password from.
# However, we will pass the password to LibreOffice in clear text on the command line anyway,
# so anybody who can list process arguments can snoop the password.
# Note that, on Linux, it is rather common that all user accounts can list all process arguments.
# Therefore, your password is probably not very safe.
# See also:
# Bug 42647 - command line option to specify password
# https://bugs.documentfoundation.org/show_bug.cgi?id=42647
declare -r PASSWORD="$2"
echo "Starting LibreOffice..."
CMD="soffice"
# If the filename or password have characters which collide with LibreOffice's BASIC syntax,
# like '(' or ',', this will break. The safest way would be to improve the code
# in this script, and in the LibreOffice side too, in order to hex-encode these strings.
MACRO_CMD="macro:///standard.RDiezDocUtils.OpenPasswordProtectedFile(\"${DOC_FILENAME}\", \"${PASSWORD}\")"
CMD+=" ${MACRO_CMD@Q}"
# Only print the command for troubleshooting purposes, as the password is visible in clear text.
if false; then
echo "$CMD"
fi
if true; then
# The '&' is in case LibreOffice is not already running. Without it, the script would wait for it to finish.
#
# The trouble is, '&' tends to break this script when called from Emacs, for example,
# see the alternative with StartDetached.sh below.
eval "$CMD" &
else
# Warning: If you choose this method, the password will land in syslog.
#
# Script StartDetached.sh is in the same Git repository as this script.
eval "StartDetached.sh --log-tag-name=${SCRIPT_NAME@Q} -- $CMD"
fi
echo "Finished starting LibreOffice."