Skip to content

Commit

Permalink
initialize repo
Browse files Browse the repository at this point in the history
  • Loading branch information
ochurlaud committed Nov 8, 2020
0 parents commit 3061931
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Olivier CHURLAUD

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# mpd_cdrom

Does everything so that whenever a cd is inserted, its music is added to the mpd main playlist. When the cd is removed, it all corresponding songs are removed from the playlist.
25 changes: 25 additions & 0 deletions packaging/archlinux/PKGBUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

pkgbase="mpd_cdrom"
pkgname="mpd_cdrom"
pkgver="1.0.0"
pkgrel=1

pkg_desc="Add songs to mpd when a CD-ROM is inserted, remove them when ejected"
license=('MIT')
arch=('any')
depends=('mpd' 'mpc' 'cdparanoia')

source=("${pkgname}-${pkgver}::git+https://github.com/ochurlaud/mpd_cdrom.git")
md5sums=('SKIP')

install=${pkgname}.install

package() {
cd "${srcdir}/${pkgname}-${pkgver}"
mkdir -p "${pkgdir}/usr/bin/"
mkdir -p "${pkgdir}/etc/udev/rules.d/"
mkdir -p "${pkgdir}/etc/systemd/system/"
cp src/bin/* "${pkgdir}/usr/bin/"
cp src/systemd/* "${pkgdir}/etc/systemd/system/"
cp src/udev-rules/* "${pkgdir}/etc/udev/rules.d/"
}
4 changes: 4 additions & 0 deletions packaging/archlinux/mpd_cdrom.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
post_install() {
echo "INFO: adding user 'mpd' to the 'optical' group"
usermod -aG optical mpd
}
46 changes: 46 additions & 0 deletions src/bin/mpd_cdrom
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

usage() {
echo "Usage: $0 [load|unload]"
exit $1
}

mpd_load() {
nbtracks=$(cdparanoia -sQ |& grep -P "^\s+\d+\." | wc -l)

for ((i=1; i<=${nbtracks};i++)) ; do
mpc add cdda:///${i}
done
}

mpd_unload() {
positions=$(mpc playlist | grep -n "cdda:///" | cut -d':' -f1)
if [[ "${positions}" != "" ]] ; then
mpc del ${positions}
fi
}

control_dependencies() {
which $1 > /dev/null
if [[ "$?" -ne "0" ]]; then
echo "[ERROR] $1 is not installed"
exit 2
fi
}

for dependency in "mpc" "cdparanoia"; do
control_dependencies ${dependency}
done

if [[ "$#" -ne "1" ]] ; then
usage 1
fi

if [[ "$1" = "load" ]] ; then
mpd_load
elif [[ "$1" = "unload" ]] ; then
mpd_unload
else
usage 1
fi

3 changes: 3 additions & 0 deletions src/systemd/mpd-load-cdrom.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Service]
Type=oneshot
ExecStart=/usr/bin/mpd_cdrom load
3 changes: 3 additions & 0 deletions src/systemd/mpd-unload-cdrom.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Service]
Type=oneshot
ExecStart=/usr/bin/mpd_cdrom unload
2 changes: 2 additions & 0 deletions src/udev-rules/90-raspi3-cdrom.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ACTION=="change", SUBSYSTEM=="block", KERNEL=="sr*", ENV{DISK_EJECT_REQUEST}=="", TAG+="systemd", ENV{SYSTEMD_WANTS}="mpd-load-cdrom.service"
ACTION=="change", SUBSYSTEM=="block", KERNEL=="sr*", ENV{DISK_EJECT_REQUEST}=="1", TAG+="systemd", ENV{SYSTEMD_WANTS}="mpd-unload-cdrom.service"

0 comments on commit 3061931

Please sign in to comment.