Commit 964ce9e0 authored by bbguimaraes's avatar bbguimaraes
Browse files

scripts/sink: add host-based sink name mapping

Also rewrite in Perl =)
parent 8a5e992b
#!/usr/bin/env perl
use strict;
use warnings;
sub main {
my $sink = shift;
my @sinks = `pactl list short sinks`;
return print @sinks if !$sink;
my $id = find_sink(map_sink_name($sink, `hostname`), \@sinks);
die "sink $sink not found" if !$id;
system "pactl set-default-sink $id";
foreach(`pactl list short sink-inputs`) {
my @f = split;
system "pactl move-sink-input $f[0] $id";
}
}
sub find_sink {
my ($sink, $sinks) = @_;
return $sink if $sink =~ m/^[0-9]+$/;
foreach(@$sinks) {
my @f = split;
return $f[0] if $f[1] =~ $sink;
}
}
sub map_sink_name {
my ($sink, $host) = @_;
if($host =~ /^rh/) {
if($sink eq "analog-stereo") {
return "sofhdadsp__sink";
} elsif($sink eq "hdmi-stereo") {
return "sofhdadsp_4__sink";
}
}
}
main @ARGV;
#!/bin/bash
set -euo pipefail
sinks=$(pactl list short sinks)
[[ "$#" -eq 0 ]] && { echo "$sinks"; exit; }
sink=$1
if ! [[ "$sink" =~ [0-9]+ ]]; then
id=$(awk -v s="$sink" '$2 ~ s { print $1; exit }' <<< "$sinks")
fi
if [[ "$id" ]]; then
pactl set-default-sink "$id"
pactl list short sink-inputs | while read -r stream _; do
pactl move-sink-input "$stream" "$id"
done
fi
if [[ "$HOSTNAME" == wamozart ]]; then
card=; profile=
case "$sink" in
hdmi-stereo)
card=$(pactl list short cards | awk '{print $1; exit}')
profile=output:hdmi-stereo-extra1+input:analog-stereo;;
analog-stereo)
card=$(pactl list short cards | awk '{print $1; exit}')
profile=output:analog-stereo+input:analog-stereo;;
esac
[[ "$card" && "$profile" ]] \
&& pactl set-card-profile "$card" "$profile"
fi
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment