You are not logged in.

#3401 2020-10-08 08:12:00

schard
Member
From: Hannover
Registered: 2016-05-06
Posts: 995
Website

Re: Post your handy self made command line utilities

Since we're using Arch Linux as the main driver for our digital signage systems in our company since ~2015 and are using it with different generations of configurations, especially bootloaders (GRUB, systemd-boot and Syslinux), I wrote a script to automagically detect the boot configuration and update the corresponding bootloaders.

#! /bin/bash

if test ${EUID} -ne 0; then
        echo "This script must be run as root." >&2
        exit 1
fi

DEV="/dev/sda"
LOADER="/boot/loader/loader.conf"

if test -d "/sys/firmware/efi"; then
        echo "System uses EFI boot."
        if test -f "${LOADER}"; then
                echo "EFI loader is systemd-boot."
                sed -ie 's/^default digital-signage$/default digital-signage\.conf/' "${LOADER}"
                bootctl update
        else
                echo "Unknown EFI loader." >&2
                exit 2
        fi
else
        echo "System uses BIOS/MBR boot."
        if test -b "${DEV}"; then
                BOOTLOADER="Syslinux"
                dd if="${DEV}" bs=512 count=1 2>/dev/null | grep -q GRUB && BOOTLOADER="GRUB"
                echo "Bootloader is ${BOOTLOADER}."

                if [ "${BOOTLOADER}" == "GRUB" ]; then
                        grub-install --target=i386-pc "${DEV}"
                        grub-mkconfig -o /boot/grub/grub.cfg
                else
                        syslinux-install_update -i -a -m
                fi
        else
                echo "Device ${DEV} does not exist." >&2
                exit 3
        fi
fi

Limitations
This script was written by me for our digital signage systems, of which I know, that
1) they either use systemd-boot in EFI mode with /boot as ESP or GRUB (legacy) resp. Syslinux (new) for BIOS/MBR boot
and
2) that the internal disk is guaranteed to be /dev/sda if present.

Last edited by schard (2020-10-08 08:22:01)

Offline

#3402 2020-10-08 20:37:20

Awebb
Member
Registered: 2010-05-06
Posts: 5,594

Re: Post your handy self made command line utilities

Here could be my awesome bash script that makes my default changes to makepkg.conf on a new machine by looping over an associative bash array and sed -i'ing the whole thing, but then I accidentally read the man page and realized that $HOME/.makepkg.conf is a thing, as well as an XDG_CONFIG_HOME.

Offline

#3403 2020-10-09 04:35:45

eschwartz
Trusted User/Bug Wrangler
Registered: 2014-08-08
Posts: 3,706

Re: Post your handy self made command line utilities

Awebb wrote:

but then I accidentally read the man page

For shame, you scoundrel!


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#3404 2020-10-09 15:30:17

Awebb
Member
Registered: 2010-05-06
Posts: 5,594

Re: Post your handy self made command line utilities

eschwartz wrote:
Awebb wrote:

but then I accidentally read the man page

For shame, you scoundrel!

I only read it, because I hoped there would be some sort of /etc/makepkg.conf.d where I could drop overrides.

Offline

#3405 2020-10-24 12:17:51

karabaja4
Member
From: Croatia
Registered: 2008-09-14
Posts: 886

Re: Post your handy self made command line utilities

Switch between headset and speakers using ALSA and not messing around with config files or PulseAudio (may require some modifying depending on your system):

#!/bin/bash
set -euo pipefail

usage() {
    echo "usage: switch.sh [speakers|headphones[headset]|maxvolume]"
    exit 1
}

[ ${#} -eq 0 ] && usage

execute_max_amixer() {
    amixer set Master unmute
    amixer set Master 100%
    amixer set Headphone unmute
    amixer set Headphone 100%
    amixer set Mic unmute
    amixer set Mic 100%
}

max_amixer() {
    execute_max_amixer &> /dev/null || true
    echo "Set volume to 100%"
}

write_asoundrc() {
    echo -e "defaults.ctl.card ${1}\ndefaults.pcm.card ${1}\ndefaults.pcm.device 0" > "${HOME}/.asoundrc"
}

switch_card() {
    declare -r number="$(awk -v pattern="${1}" '$0 ~ pattern {print $1; exit;}' /proc/asound/cards)"
    write_asoundrc "${number}"
    echo "Switched to card ${number} (${1})"
}

case "${1}" in
speakers)
    switch_card PCH
    ;;&
headphones|headset)
    switch_card Headset
    ;;&
speakers|headphones|headset|maxvolume)
    max_amixer
    ;;
*)
    usage
    ;;
esac

EDIT: v2, updated this a bit to not have duplicate code...

Last edited by karabaja4 (Yesterday 00:49:29)

Offline

#3406 2020-10-24 12:59:52

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 24,447
Website

Re: Post your handy self made command line utilities

cat /proc/asound/cards | grep PCH | head -n1 | cut -c2

1. useless use of cat
2. piping grep to head
3. piping head to cut
4. etc ...

I think you mean:

awk '/PCH/{print $1; exit;}' /proc/asound/cards

"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3407 2020-10-24 13:12:49

karabaja4
Member
From: Croatia
Registered: 2008-09-14
Posts: 886

Re: Post your handy self made command line utilities

Trilby wrote:
cat /proc/asound/cards | grep PCH | head -n1 | cut -c2

1. useless use of cat
2. piping grep to head
3. piping head to cut
4. etc ...

I think you mean:

awk '/PCH/{print $1; exit;}' /proc/asound/cards

Thanks, fixed.

Offline

#3408 2020-10-24 14:45:22

ondoho
Member
Registered: 2013-04-30
Posts: 677
Website

Re: Post your handy self made command line utilities

youtube-search

A python script that searches youtube for a given search term and extracts video URLs and metadata. Does not require youtube-dl. Torsocks wrapper included.
Get it here or here.

Last edited by ondoho (2020-10-25 18:49:18)


However studied and stilted your rant, it can never hide the base and primitve emotion that inspired it.
There's no objectivity.

Offline

Board footer

Powered by FluxBB