Skip to content

Commit

Permalink
Add compatibility with LibreOffice snap package
Browse files Browse the repository at this point in the history
  • Loading branch information
cfgnunes committed Apr 18, 2024
1 parent de8dfa5 commit 84f2d43
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 90 deletions.
19 changes: 8 additions & 11 deletions Document/Convert to 'docx'
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ _get_dependencies() {
command=$(_get_command "$input_file")

case $command in
"libreoffice_writer") dependencies+="package=libreoffice-writer" ;;
"libreoffice_writer")
if ! _command_exists "libreoffice.writer" && ! _command_exists "libreoffice-writer"; then
dependencies+="package=libreoffice-writer"
fi
;;
"pandoc") dependencies+="command=pandoc" ;;
esac
dependencies+=$'\n'
Expand Down Expand Up @@ -83,25 +87,18 @@ _run_command() {
# Run the main process.
case $command in
"libreoffice_writer")
local output_file_temp=""
local temp_file=""

output_file_temp=$(_get_output_filename "$input_file" "$TEMP_DIR_TASK" "par_extension_opt=replace; par_extension=$output_format")

# NOTE: Workaround to fix the bug 37531 in LibreOffice.
# See the: https://bugs.documentfoundation.org/show_bug.cgi?id=37531
local temp_file=""
temp_file=$(_get_temp_file_dry)

# NOTE: LibreOffice does not support ' -- ' in the command line.
# NOTE: LibreOffice does not support defining the output file manually.
std_output=$(libreoffice --headless --convert-to "$output_format" "-env:UserInstallation=file://$temp_file" --outdir "$TEMP_DIR_TASK" "$input_file" 2>&1)
_check_output "$?" "$std_output" "$input_file" "$output_file_temp"
std_output=$(libreoffice --headless --convert-to "$output_format" "-env:UserInstallation=file://$temp_file" --outdir "$output_dir" "$input_file" 2>&1)
_check_output "$?" "$std_output" "$input_file" ""

# Remove the temporary file.
rm -f -- "$temp_file"

std_output=$(_move_file "rename" "$output_file_temp" "$output_file" 2>&1)
_check_output "$?" "$std_output" "$input_file" ""
;;
"pandoc")
std_output=$(pandoc --standalone -o "$output_file" -- "$input_file" 2>&1)
Expand Down
19 changes: 8 additions & 11 deletions Document/Convert to 'odp'
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ _get_dependencies() {
command=$(_get_command "$input_file")

case $command in
"libreoffice_impress") dependencies+="package=libreoffice-impress" ;;
"libreoffice_impress")
if ! _command_exists "libreoffice.impress" && ! _command_exists "libreoffice-impress"; then
dependencies+="package=libreoffice-impress"
fi
;;
"pandoc") dependencies+="command=pandoc" ;;
esac
dependencies+=$'\n'
Expand Down Expand Up @@ -81,25 +85,18 @@ _run_command() {
# Run the main process.
case $command in
"libreoffice_impress")
local output_file_temp=""
local temp_file=""

output_file_temp=$(_get_output_filename "$input_file" "$TEMP_DIR_TASK" "par_extension_opt=replace; par_extension=$output_format")

# NOTE: Workaround to fix the bug 37531 in LibreOffice.
# See the: https://bugs.documentfoundation.org/show_bug.cgi?id=37531
local temp_file=""
temp_file=$(_get_temp_file_dry)

# NOTE: LibreOffice does not support ' -- ' in the command line.
# NOTE: LibreOffice does not support defining the output file manually.
std_output=$(libreoffice --headless --convert-to "$output_format" "-env:UserInstallation=file://$temp_file" --outdir "$TEMP_DIR_TASK" "$input_file" 2>&1)
_check_output "$?" "$std_output" "$input_file" "$output_file_temp"
std_output=$(libreoffice --headless --convert-to "$output_format" "-env:UserInstallation=file://$temp_file" --outdir "$output_dir" "$input_file" 2>&1)
_check_output "$?" "$std_output" "$input_file" ""

# Remove the temporary file.
rm -f -- "$temp_file"

std_output=$(_move_file "rename" "$output_file_temp" "$output_file" 2>&1)
_check_output "$?" "$std_output" "$input_file" ""
;;
"pandoc")
std_output=$(pandoc --standalone -o "$output_file" -- "$input_file" 2>&1)
Expand Down
19 changes: 8 additions & 11 deletions Document/Convert to 'ods'
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ _get_dependencies() {
command=$(_get_command "$input_file")

case $command in
"libreoffice_calc") dependencies+="package=libreoffice-calc" ;;
"libreoffice_calc")
if ! _command_exists "libreoffice.calc" && ! _command_exists "libreoffice-calc"; then
dependencies+="package=libreoffice-calc"
fi
;;
"pandoc") dependencies+="command=pandoc" ;;
esac
dependencies+=$'\n'
Expand Down Expand Up @@ -81,25 +85,18 @@ _run_command() {
# Run the main process.
case $command in
"libreoffice_calc")
local output_file_temp=""
local temp_file=""

output_file_temp=$(_get_output_filename "$input_file" "$TEMP_DIR_TASK" "par_extension_opt=replace; par_extension=$output_format")

# NOTE: Workaround to fix the bug 37531 in LibreOffice.
# See the: https://bugs.documentfoundation.org/show_bug.cgi?id=37531
local temp_file=""
temp_file=$(_get_temp_file_dry)

# NOTE: LibreOffice does not support ' -- ' in the command line.
# NOTE: LibreOffice does not support defining the output file manually.
std_output=$(libreoffice --headless --convert-to "$output_format" "-env:UserInstallation=file://$temp_file" --outdir "$TEMP_DIR_TASK" "$input_file" 2>&1)
_check_output "$?" "$std_output" "$input_file" "$output_file_temp"
std_output=$(libreoffice --headless --convert-to "$output_format" "-env:UserInstallation=file://$temp_file" --outdir "$output_dir" "$input_file" 2>&1)
_check_output "$?" "$std_output" "$input_file" ""

# Remove the temporary file.
rm -f -- "$temp_file"

std_output=$(_move_file "rename" "$output_file_temp" "$output_file" 2>&1)
_check_output "$?" "$std_output" "$input_file" ""
;;
"pandoc")
std_output=$(pandoc --standalone -o "$output_file" -- "$input_file" 2>&1)
Expand Down
19 changes: 8 additions & 11 deletions Document/Convert to 'odt'
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ _get_dependencies() {
command=$(_get_command "$input_file")

case $command in
"libreoffice_writer") dependencies+="package=libreoffice-writer" ;;
"libreoffice_writer")
if ! _command_exists "libreoffice.writer" && ! _command_exists "libreoffice-writer"; then
dependencies+="package=libreoffice-writer"
fi
;;
"pandoc") dependencies+="command=pandoc" ;;
esac
dependencies+=$'\n'
Expand Down Expand Up @@ -83,25 +87,18 @@ _run_command() {
# Run the main process.
case $command in
"libreoffice_writer")
local output_file_temp=""
local temp_file=""

output_file_temp=$(_get_output_filename "$input_file" "$TEMP_DIR_TASK" "par_extension_opt=replace; par_extension=$output_format")

# NOTE: Workaround to fix the bug 37531 in LibreOffice.
# See the: https://bugs.documentfoundation.org/show_bug.cgi?id=37531
local temp_file=""
temp_file=$(_get_temp_file_dry)

# NOTE: LibreOffice does not support ' -- ' in the command line.
# NOTE: LibreOffice does not support defining the output file manually.
std_output=$(libreoffice --headless --convert-to "$output_format" "-env:UserInstallation=file://$temp_file" --outdir "$TEMP_DIR_TASK" "$input_file" 2>&1)
_check_output "$?" "$std_output" "$input_file" "$output_file_temp"
std_output=$(libreoffice --headless --convert-to "$output_format" "-env:UserInstallation=file://$temp_file" --outdir "$output_dir" "$input_file" 2>&1)
_check_output "$?" "$std_output" "$input_file" ""

# Remove the temporary file.
rm -f -- "$temp_file"

std_output=$(_move_file "rename" "$output_file_temp" "$output_file" 2>&1)
_check_output "$?" "$std_output" "$input_file" ""
;;
"pandoc")
std_output=$(pandoc --standalone -o "$output_file" -- "$input_file" 2>&1)
Expand Down
31 changes: 18 additions & 13 deletions Document/Convert to 'pdf'
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,21 @@ _get_dependencies() {
pkg_manager=zypper; package=texlive-mathdesign |
pkg_manager=zypper; package=texlive-subeqnarray"
;;
"libreoffice_calc") dependencies+="package=libreoffice-calc" ;;
"libreoffice_impress") dependencies+="package=libreoffice-impress" ;;
"libreoffice_writer") dependencies+="package=libreoffice-writer" ;;
"libreoffice_calc")
if ! _command_exists "libreoffice.calc" && ! _command_exists "libreoffice-calc"; then
dependencies+="package=libreoffice-calc"
fi
;;
"libreoffice_impress")
if ! _command_exists "libreoffice.impress" && ! _command_exists "libreoffice-impress"; then
dependencies+="package=libreoffice-impress"
fi
;;
"libreoffice_writer")
if ! _command_exists "libreoffice.writer" && ! _command_exists "libreoffice-writer"; then
dependencies+="package=libreoffice-writer"
fi
;;
"pandoc_latex")
dependencies+="
command=pandoc |
Expand Down Expand Up @@ -185,25 +197,18 @@ _run_command() {
rm -rf -- "$temp_dir_output"
;;
"libreoffice_calc" | "libreoffice_impress" | "libreoffice_writer")
local output_file_temp=""
local temp_file=""

output_file_temp=$(_get_output_filename "$input_file" "$TEMP_DIR_TASK" "par_extension_opt=replace; par_extension=$output_format")

# NOTE: Workaround to fix the bug 37531 in LibreOffice.
# See the: https://bugs.documentfoundation.org/show_bug.cgi?id=37531
local temp_file=""
temp_file=$(_get_temp_file_dry)

# NOTE: LibreOffice does not support ' -- ' in the command line.
# NOTE: LibreOffice does not support defining the output file manually.
std_output=$(libreoffice --headless --convert-to "$output_format" "-env:UserInstallation=file://$temp_file" --outdir "$TEMP_DIR_TASK" "$input_file" 2>&1)
_check_output "$?" "$std_output" "$input_file" "$output_file_temp"
std_output=$(libreoffice --headless --convert-to "$output_format" "-env:UserInstallation=file://$temp_file" --outdir "$output_dir" "$input_file" 2>&1)
_check_output "$?" "$std_output" "$input_file" ""

# Remove the temporary file.
rm -f -- "$temp_file"

std_output=$(_move_file "rename" "$output_file_temp" "$output_file" 2>&1)
_check_output "$?" "$std_output" "$input_file" ""
;;
"pandoc_latex")
std_output=$(pandoc -V "geometry:margin=1.5cm" -V "geometry:a4paper" -V "fontfamily:charter" --standalone -o "$output_file" -- "$input_file" 2>&1)
Expand Down
19 changes: 8 additions & 11 deletions Document/Convert to 'pptx'
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ _get_dependencies() {
command=$(_get_command "$input_file")

case $command in
"libreoffice_impress") dependencies+="package=libreoffice-impress" ;;
"libreoffice_impress")
if ! _command_exists "libreoffice.impress" && ! _command_exists "libreoffice-impress"; then
dependencies+="package=libreoffice-impress"
fi
;;
"pandoc") dependencies+="command=pandoc" ;;
esac
dependencies+=$'\n'
Expand Down Expand Up @@ -81,25 +85,18 @@ _run_command() {
# Run the main process.
case $command in
"libreoffice_impress")
local output_file_temp=""
local temp_file=""

output_file_temp=$(_get_output_filename "$input_file" "$TEMP_DIR_TASK" "par_extension_opt=replace; par_extension=$output_format")

# NOTE: Workaround to fix the bug 37531 in LibreOffice.
# See the: https://bugs.documentfoundation.org/show_bug.cgi?id=37531
local temp_file=""
temp_file=$(_get_temp_file_dry)

# NOTE: LibreOffice does not support ' -- ' in the command line.
# NOTE: LibreOffice does not support defining the output file manually.
std_output=$(libreoffice --headless --convert-to "$output_format" "-env:UserInstallation=file://$temp_file" --outdir "$TEMP_DIR_TASK" "$input_file" 2>&1)
_check_output "$?" "$std_output" "$input_file" "$output_file_temp"
std_output=$(libreoffice --headless --convert-to "$output_format" "-env:UserInstallation=file://$temp_file" --outdir "$output_dir" "$input_file" 2>&1)
_check_output "$?" "$std_output" "$input_file" ""

# Remove the temporary file.
rm -f -- "$temp_file"

std_output=$(_move_file "rename" "$output_file_temp" "$output_file" 2>&1)
_check_output "$?" "$std_output" "$input_file" ""
;;
"pandoc")
std_output=$(pandoc --standalone -o "$output_file" -- "$input_file" 2>&1)
Expand Down
19 changes: 8 additions & 11 deletions Document/Convert to 'txt'
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ _get_dependencies() {
command=$(_get_command "$input_file")

case $command in
"libreoffice_writer") dependencies+="package=libreoffice-writer" ;;
"libreoffice_writer")
if ! _command_exists "libreoffice.writer" && ! _command_exists "libreoffice-writer"; then
dependencies+="package=libreoffice-writer"
fi
;;
"pandoc") dependencies+="command=pandoc" ;;
"pdftotext")
dependencies+="
Expand Down Expand Up @@ -91,25 +95,18 @@ _run_command() {
# Run the main process.
case $command in
"libreoffice_writer")
local output_file_temp=""
local temp_file=""

output_file_temp=$(_get_output_filename "$input_file" "$TEMP_DIR_TASK" "par_extension_opt=replace; par_extension=$output_format")

# NOTE: Workaround to fix the bug 37531 in LibreOffice.
# See the: https://bugs.documentfoundation.org/show_bug.cgi?id=37531
local temp_file=""
temp_file=$(_get_temp_file_dry)

# NOTE: LibreOffice does not support ' -- ' in the command line.
# NOTE: LibreOffice does not support defining the output file manually.
std_output=$(libreoffice --headless --convert-to "$output_format" "-env:UserInstallation=file://$temp_file" --outdir "$TEMP_DIR_TASK" "$input_file" 2>&1)
_check_output "$?" "$std_output" "$input_file" "$output_file_temp"
std_output=$(libreoffice --headless --convert-to "$output_format" "-env:UserInstallation=file://$temp_file" --outdir "$output_dir" "$input_file" 2>&1)
_check_output "$?" "$std_output" "$input_file" ""

# Remove the temporary file.
rm -f -- "$temp_file"

std_output=$(_move_file "rename" "$output_file_temp" "$output_file" 2>&1)
_check_output "$?" "$std_output" "$input_file" ""
;;
"pandoc")
std_output=$(pandoc --standalone -o "$output_file" -- "$input_file" 2>&1)
Expand Down
19 changes: 8 additions & 11 deletions Document/Convert to 'xlsx'
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ _get_dependencies() {
command=$(_get_command "$input_file")

case $command in
"libreoffice_calc") dependencies+="package=libreoffice-calc" ;;
"libreoffice_calc")
if ! _command_exists "libreoffice.calc" && ! _command_exists "libreoffice-calc"; then
dependencies+="package=libreoffice-calc"
fi
;;
"pandoc") dependencies+="command=pandoc" ;;
esac
dependencies+=$'\n'
Expand Down Expand Up @@ -81,25 +85,18 @@ _run_command() {
# Run the main process.
case $command in
"libreoffice_calc")
local output_file_temp=""
local temp_file=""

output_file_temp=$(_get_output_filename "$input_file" "$TEMP_DIR_TASK" "par_extension_opt=replace; par_extension=$output_format")

# NOTE: Workaround to fix the bug 37531 in LibreOffice.
# See the: https://bugs.documentfoundation.org/show_bug.cgi?id=37531
local temp_file=""
temp_file=$(_get_temp_file_dry)

# NOTE: LibreOffice does not support ' -- ' in the command line.
# NOTE: LibreOffice does not support defining the output file manually.
std_output=$(libreoffice --headless --convert-to "$output_format" "-env:UserInstallation=file://$temp_file" --outdir "$TEMP_DIR_TASK" "$input_file" 2>&1)
_check_output "$?" "$std_output" "$input_file" "$output_file_temp"
std_output=$(libreoffice --headless --convert-to "$output_format" "-env:UserInstallation=file://$temp_file" --outdir "$output_dir" "$input_file" 2>&1)
_check_output "$?" "$std_output" "$input_file" ""

# Remove the temporary file.
rm -f -- "$temp_file"

std_output=$(_move_file "rename" "$output_file_temp" "$output_file" 2>&1)
_check_output "$?" "$std_output" "$input_file" ""
;;
"pandoc")
std_output=$(pandoc --standalone -o "$output_file" -- "$input_file" 2>&1)
Expand Down

0 comments on commit 84f2d43

Please sign in to comment.