Skip to content

Commit

Permalink
Merge pull request #21 from OS2borgerPC/20-princh-scripts
Browse files Browse the repository at this point in the history
Use princh-setup to add the printer instead of lpadmin
  • Loading branch information
NeutraChikara authored Feb 6, 2025
2 parents ff6f414 + 9ec1b7d commit 6a96d19
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
4 changes: 2 additions & 2 deletions printer_princh_add.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
title: "Tilføj Princh Cloud Printer"
version: 1
version: 2
parent: "Printer"
source: scripts/printer_options_set.sh
source: scripts/printer_princh_add.sh
parameters:
- name: "Navn (OBS: INGEN ÆØÅ, mellemrum eller apostrofer)"
type: "string"
Expand Down
2 changes: 1 addition & 1 deletion printer_princh_install.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "Installer Princh Cloud Printer"
version: 1
version: 2
parent: "Printer"
source: scripts/printer_princh_install.sh
parameters:
Expand Down
22 changes: 13 additions & 9 deletions scripts/printer_princh_add.sh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
#! /usr/bin/env sh
#!/usr/bin/env sh

set -ex

if get_os2borgerpc_config os2_product | grep --quiet kiosk; then
echo "Dette script er ikke designet til at blive anvendt på en kiosk-maskine."
exit 1
fi
# lpadmin doesn't like spaces

# CUPS/lpadmin doesn't like spaces
NAME="$(echo "$1" | tr ' ' '_')"
PRINCH_ID="$2"
DESCRIPTION="$3"
SET_STANDARD="$4"
SET_DEFAULT="$4"

if [ "$SET_DEFAULT" = "True" ]; then
DEFAULT_MAYBE="--default"
fi

# Delete the printer if a printer already exists by that NAME
lpadmin -x "$NAME" || true

# No princh-cloud-printer binary in path, so checking for princh-setup
if which princh-setup > /dev/null; then
lpadmin -p "$NAME" -v "princh:$PRINCH_ID" -D "$DESCRIPTION" -E -P /usr/share/ppd/princh/princheu.ppd -L "$DESCRIPTION"
# The two driver options are ISO and US, determining the paper sizes it uses, and specifically whether princheu.ppd (ISO) or princhus.ppd (US) is being used
# shellcheck disable=SC2086 # With quotes around princh_setup gets an explicitly empty argument and fails because of it
princh-setup add --name "$NAME" --device-id "$PRINCH_ID" --driver iso --description "$DESCRIPTION" $DEFAULT_MAYBE
# Finally additionally set the location on the newly added printer
lpadmin -p "$NAME" -L "$DESCRIPTION"
else
echo "Princh is not installed. Please run the script that installs Princh before this one."
exit 1
fi

if [ "$SET_STANDARD" = "True" ]; then
# Set the printer as standard printer
lpadmin -d "$NAME" && lpstat -d
fi
10 changes: 5 additions & 5 deletions scripts/printer_princh_install.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/env sh
#!/usr/bin/env sh

set -ex

Expand Down Expand Up @@ -29,15 +29,15 @@ if [ "$PRINCH_VERSION_AVAILABLE" != "$PRINCH_VERSION_INSTALLED" ]; then
# predictable for the command to install it below
curl $URL --output $FILE
dpkg --install $FILE

rm $FILE
else
printf '%s\n' "Princh is already installed and in the most recent version."
fi

# Create Princh autostart
princh_autostart_dir=/home/.skjult/.config/autostart
PRINCH_AUTOSTART_DIR=/home/.skjult/.config/autostart

mkdir --parents $princh_autostart_dir
mkdir --parents $PRINCH_AUTOSTART_DIR

# This will fail if the symlink already exists, but the exit status is still 0 so no problem
ln -sf /usr/share/applications/com-princh-print-daemon.desktop $princh_autostart_dir
ln -sf /usr/share/applications/com-princh-print-daemon.desktop $PRINCH_AUTOSTART_DIR

0 comments on commit 6a96d19

Please sign in to comment.