You are not logged in.
I coded a CLI tool in C. With it you can manage all systemd units very comfortable with a TUI. You can select units with up / down, hit Enter to display all status information and use the F -keys to start, stop, restart, enable, disable, mask, unmask and reload the unit. After every operation, the daemon reloads and updates the display. The compiled executable is only some kilobytes, but the source code is 1561 lines long. I don't know if I can paste the source code here.
But if you like, you can get the source and also a compiled binary on my GitHub page.
My username:Lennart1978 the tool is called "servicemaster".
Today I updated to version 1.1 and it works very well.
All you need: systemd-libs and ncurses (Most likely this is already installed)
It's always great when someone else has use for it. It was a lot of work for me, I'm just a hobby programmer, not a professional.
Ich weiß, dass ich nichts weiß !
Offline
I coded a CLI tool in C. With it you can manage all systemd units very comfortable with a TUI. You can select units with up / down, hit Enter to display all status information and use the F -keys to start, stop, restart, enable, disable, mask, unmask and reload the unit. After every operation, the daemon reloads and updates the display. The compiled executable is only some kilobytes, but the source code is 1561 lines long. I don't know if I can paste the source code here.
But if you like, you can get the source and also a compiled binary on my GitHub page.My username:Lennart1978 the tool is called "servicemaster".
Today I updated to version 1.1 and it works very well.
All you need: systemd-libs and ncurses (Most likely this is already installed)It's always great when someone else has use for it. It was a lot of work for me, I'm just a hobby programmer, not a professional.
Offline
ServiceMaster release version 1.3:
- DBus event loop: Reacts immediately to external changes to units
- Fixed some small bugs
Ich weiß, dass ich nichts weiß !
Offline
This is a comically long one-liner I keep in my .profile for PDF merging.
pdfmerge() { if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then echo "Usage: pdfmerge MERGED PDF1 PDF2"; echo "Merge PDF1 and PDF2 into MERGED"; return 0; else if [ "$#" != 3 ]; then echo "pdfmerge: bad usage"; echo "Try 'pdfmerge --help' for more information"; return 1; fi; gs -qo -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -o $@; fi }
Some of my classes require PDF submissions with both computer-generated output and scans of handwritten solutions, so I use this to quickly merge the two. It doesn't have perfect error checking, but it's just enough for me to remember how to use it when I do use it once every one or two weeks or so.
I suspect it may be wise to un-one-liner it at some point.
Astrophysicist and programmer. I like simple things.
Offline
Here you go:
# original
pdfmerge() {
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "Usage: pdfmerge MERGED PDF1 PDF2"
echo "Merge PDF1 and PDF2 into MERGED"
return 0
else
if [ "$#" != 3 ]; then
echo "pdfmerge: bad usage"
echo "Try 'pdfmerge --help' for more information"
return 1
fi
gs -qo -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -o $@
fi
}
# simplified
pdfmerge() {
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "Usage: pdfmerge MERGED PDF1 PDF2"
echo "Merge PDF1 and PDF2 into MERGED"
return 0
fi
if [ "$#" != 3 ]; then
echo "pdfmerge: bad usage"
echo "Try 'pdfmerge --help' for more information"
return 1
fi
gs -qo -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -o $@
}
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
You're right! With the returns there I don't need the extra else. Thanks! More proof comically long one-liners are a bad idea.
Astrophysicist and programmer. I like simple things.
Offline
Lazy:
pdfmerge() {
[ "$#" = 3 ] && echo gs -qo -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -o "$@" && return 0
echo "Usage: pdfmerge MERGED PDF1 PDF2"; return 1
}
(though nb. the quoted "$@")
Online
I don't think quoting it would work as desired since it would treat the three items as a single argument to -o though, right? That might work anyhow but I haven't tested and I don't know if that would necessarily work.
Astrophysicist and programmer. I like simple things.
Offline
it would treat the three items as a single argument to -o
Source this:
foo(){
echo $#
}
bar(){
foo "$@"
}
then run
bar 1 2 3
bar "1 2" 3
Then test
Source this:
foo(){
echo $#
}
bar(){
foo $@
}
bar 1 2 3
bar "1 2" 3
Notice a difference?
Online
Yeah, as expected when it's quoted it treats the quoted object as one, but when it's unquoted it treats it as two space separated objects.
I guess my brain isn't seeing why that is desirable behavior here.
Astrophysicist and programmer. I like simple things.
Offline
"1 2" are one parameter, not two.
You want 'bar 1 2 3' to print "3" and 'bar "1 2" 3' to print '2'
Do you get that when not quoting $@ ?
The relevant condition is if the filenames you're passing contain spaces.
Online
Ah, that's why I didn't think of it, I tend not to use spaces in filenames. Thanks. O7
Astrophysicist and programmer. I like simple things.
Offline
Using QEMU/KVM a lot recently to test ISO images so I wrote these two functions for my shell RC file:
function vinst {
if [ $# != 2 ] ; then
echo 'Usage vinst $iso $disk'
else
qemu-system-x86_64 \
-enable-kvm \
-m 4G \
-device virtio-vga-gl \
-display sdl,gl=on \
-machine q35 \
-device intel-iommu \
-cpu host \
-audiodev alsa,id=snd0 \
-device ich9-intel-hda \
-device hda-output,audiodev=snd0 \
-drive if=virtio,format=raw,cache=none,file="$2" \
-nic user,model=virtio-net-pci \
-cdrom "$1" \
-boot d
fi
}
function vrun {
qemu-system-x86_64 \
-enable-kvm \
-m 4G \
-device virtio-vga-gl \
-display sdl,gl=on \
-machine q35 \
-device intel-iommu \
-cpu host \
-audiodev alsa,id=snd0 \
-device ich9-intel-hda \
-device hda-output,audiodev=snd0 \
-drive if=virtio,format=raw,cache=none,file="$1" \
-nic user,model=virtio-net-pci
}
`vinst` is for testing live ISO images and installing, it accepts the ISO image name and the target disk image as arguments, `vrun` is for running the installed system and accepts the disk image name.
Last edited by Head_on_a_Stick (2024-09-25 10:10:40)
"It's impossible for a white person to believe in capitalism and not believe in racism. You can't have capitalism without racism."
— Malcolm X
Offline
Just as a few posts before, that'd be cleaner without the else block (I also replaced the string comparison with numeric comparison:
vinst() {
if [ $# -ne 2 ]; then
echo 'Usage vinst <iso> <disk>'
return 1
fi
qemu-system-x86_64 \
# ...
}
Last edited by Trilby (2024-09-25 13:21:30)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
^ Thanks!
EDIT: these boards have an excellent linting service
Last edited by Head_on_a_Stick (2024-09-25 13:05:10)
"It's impossible for a white person to believe in capitalism and not believe in racism. You can't have capitalism without racism."
— Malcolm X
Offline
My pdf management script
#!/bin/bash
## read below file for details of qpdf usage
# /usr/share/doc/qpdf/qpdf-manual.pdf
#
#
# TRY PDFTRICKS for gui
echo -n "
choose option
m) merge pdf files
e) extract pages from pdf
p) image to pdf
l) libreoffice document to pdf
v) djvu to pdf
d) remove password (decrypt)
b) get and edit metadata ( including bookmarks )
r) rotate pages
s) optimize for size
x) exit
#? "
# d) delete pages from pdf (untested)
read ops
case $ops in
m) echo "which files to merge?"
read -a IN
echo -n "provide name for output file:"
read OUT
# pdfunite ${IN[@]} $OUT.pdf
pdftk ${IN[@]} cat output $OUT.pdf
;;
p) echo "which image files to convert? e.g., *.jpg"
read -a IN
echo -n "provide name for output file:"
read OUT
# convert "${IN[@]}" $OUT.pdf
img2pdf --output $OUT.pdf ${IN[@]}
;;
l) echo "which document files to convert? e.g., *.odt"
read -a IN
# echo -n "provide name for output file:"
# read OUT
libreoffice --headless --convert-to pdf "${IN[@]}"
;;
v) echo "which djvu file to convert?"
read -a IN
OUT="`basename $IN .djvu`"
OUT="$OUT".pdf
ddjvu -format=pdf -quality=85 -verbose $IN $OUT ;;
s)
echo "which pdf file to modify?"
read -a IN
echo -n "provide name for output file:"
read OUT
# ebook=150dpi, screen=72dpi, printer=300dpi, default=largesize
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile="$OUT" "$IN"
;;
e) echo -n "name the pdf file to extract images from:"
read IN
echo -n "first page to extract:"
read FIRST
echo -n "last page to extract:"
read LAST
echo -n "provide name for output file:"
read OUT
# pdfseparate -f $FIRST -l $LAST $IN $OUT%d
pdftk $IN cat $FIRST-$LAST output $OUT.pdf
# pdfunite $(echo $OUT*) $OUT.pdf
;;
r) echo -n "name the pdf file to rotate pages:"
read IN
echo -n "angle of rotation, +90 -90" # left,right,north,south etc with pdftk
read ANGLE
echo -n "first page to rotate:"
read FIRST
echo -n "last page to rotate:"
read LAST
echo -n "provide name for output file:"
read OUT
qpdf --rotate=$ANGLE:$FIRST-$LAST $IN $OUT.pdf
# pdftk $IN rotate $FIRST-$LAST$ANGLE output $OUT.pdf
;;
d) echo -n "Which pdf file to decrypt (without .pdf) ?"
read FILE
echo -n "Original password ?"
read PASS
qpdf --password="$PASS" --decrypt $FILE.pdf $FILE.decrypted.pdf
# pdftk $FILE.pdf input_pw "$PASS" output $FILE.decrypted.pdf
;;
b) echo -n "Which pdf file (without .pdf) ?"
read FILE
pdftk $FILE.pdf dump_data output $FILE.txt
echo "metadata dumped to $FILE.txt"
echo "kindly edit the metadata and enter y to proceed"
read reply
[[ $reply = y ]] && pdftk $FILE.pdf update_info $FILE.txt output $FILE.bookmarked.pdf
;;
# d) echo " example command to remove page 21
# pdftk $FILE.pdf cat 1-20 22-end $FILE_edited.pdf" ;;
x) exit
;;
esac
Arch is home!
https://github.com/Docbroke
Offline