rip-music-cd

#424
Raw
Author
winny
Created
Feb. 7, 2022, 4:30 a.m.
Expires
Never
Size
865 bytes
Hits
149
Syntax
Bash
Private
No
#!/usr/bin/env bash
# Trigger this via udev.  Put the following line in /etc/udev/rules.d/90-ripper.rules .
# SUBSYSTEM=="block", KERNEL=="sr*", ACTION=="change", RUN+="/usr/local/sbin/rip-music-cd"

set -eu -o pipefail

if [[ -f /root/dont-rip ]]; then
    msg='/root/dont-rip exists, exiting.'
    echo $msg
    sudo -u winston -i sh -c 'cat >> ~/ripper.log' <<<$msg
    exit 1
fi

sleep 5

# https://superuser.com/a/1367091/302931
python - <<EOF
"""detect_tray reads status of the CDROM_DRIVE.
Statuses:
1 = no disk in tray
2 = tray open
3 = reading tray
4 = disk in tray
"""

import fcntl
import os
import sys

CDROM_DRIVE = '/dev/sr0'

fd = os.open(CDROM_DRIVE, os.O_RDONLY | os.O_NONBLOCK)
rv = fcntl.ioctl(fd, 0x5326)
os.close(fd)
sys.exit(rv != 4)
EOF

sudo -u winston -i bash -c 'env INTERACTIVE=no abcde -B -G -x -d /dev/sr0 &>> ~/ripper.log'