Skip to content

Commit

Permalink
updated wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
shitwolfymakes committed Apr 26, 2022
1 parent 690eb5d commit df06158
Showing 1 changed file with 1 addition and 97 deletions.
98 changes: 1 addition & 97 deletions scripts/docker/docker_arm_wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,100 +62,4 @@ else

fi

# Change this to docker.com image
DOCKER_IMAGE="shitwolfymakes/automatic-ripping-machine:latest"

CONTAINER_NAME="arm-rippers"
CONTAINER_VOLUME="-v /home/arm:/home/arm -v /etc/arm/config:/etc/arm/config -v /home/arm/Music:/home/arm/Music -v /home/arm/logs:/home/arm/logs -v /home/arm/media:/home/arm/media"
CONTAINER_RESTART="on-failure:3"
ARM_UID="$(id -u arm)"
ARM_GID="$(id -g arm)"

function findGenericDevice {
echo "xxx4" | logger -t ARM -s

if command -v lsscsi > /dev/null ; then
SG_DEV="$(lsscsi -g | sed -ne '/\/dev\/sr[0-9]/ s#.*\(/dev/sg[0-9]*\) *#\1#p')"
echo "xxx5" | logger -t ARM -s

if [[ -n "${SG_DEV}" ]] ; then
echo "xxx6" | logger -t ARM -s
echo "Found generic device for ${DEVNAME}: ${SG_DEV}" | logger -t ARM
echo "${SG_DEV}"
fi
fi
}

function runArmContainer {
SG_DEV="$(findGenericDevice)"
if [[ -n "${SG_DEV}" ]] ; then
echo "xxx7" | logger -t ARM -s
SG_DEV_ARG="--device=${SG_DEV}:/dev/sg0"
fi
echo "Starting on ${DEVNAME} ${SG_DEV}" | logger -t ARM
echo "yeet ${SG_DEV_ARG}" | logger -t ARM
# mounting a device in a container requires:
# capability: SYS_ADMIN
# security option: apparmor:unconfined
docker run -d \
-e UID="${ARM_UID}" -e GID="${ARM_GID}" \
-v "${CONTAINER_VOLUME}" \
--privileged \
--restart "${CONTAINER_RESTART}" \
--name "${CONTAINER_NAME}" \
"${DOCKER_IMAGE}" \
| logger -t ARM
}

function startArmContainer {
echo "Starting stopped container ${CONTAINER_NAME}" | logger -t ARM
docker start "${CONTAINER_NAME}" | logger -t ARM
}

function startArmRip {
# get info from udev to pass into the Docker container
if [[ -z "${!ID_CDROM_MEDIA_*}" ]] ; then
eval "$(udevadm info --query=env --export "${DEVNAME}")"
fi
local disctype="$(echo "${!ID_CDROM_MEDIA_*}" \
| sed -nE '/.*(ID_CDROM_MEDIA_(BD|DVD|TRACK_COUNT_AUDIO)).*/ s//\1=1/p' )"
local label_flag="${ID_FS_LABEL:+-l ID_FS_LABEL=${ID_FS_LABEL}}"
if [[ -z "${disctype}" ]] ; then
disctype="unknown=1"
fi
# This lets us get all of udev perams
#echo "Starting udev in ${CONTAINER_NAME}" | logger -t ARM
#docker exec -i -w /home/arm \
#"${CONTAINER_NAME}" \
#/bin/bash /etc/init.d/udev start | logger -t ARM
echo "Starting rip" | logger -t ARM
echo "trying - docker exec -it \
-u ${ARM_UID} \
${CONTAINER_NAME} \
python3 /opt/arm/arm/ripper/main.py -d ${DEVNAME}" | logger -t ARM

sudo docker exec -it \
-u "${ARM_UID}" \
"${CONTAINER_NAME}" \
python3 /opt/arm/arm/ripper/main.py -d "${DEVNAME}" | logger -t ARM
}

# start ARM container, if not running, for WebUI
echo "Checking container status"
container_status="$(docker container ls -l -f name="${CONTAINER_NAME}" --format '{{json .Status}}')"
echo "container '${CONTAINER_NAME}' status: ${container_status}" | logger -t ARM
case "${container_status//\"}" in
Up*)
;;
Exited*)
startArmContainer
;;
*)
runArmContainer
;;
esac

# start the rip inside the same container

echo "xxx0" | logger -t ARM -s
startArmRip
/bin/bash "/usr/bin/python3 /opt/arm/arm/ripper/main.py -d ${DEVNAME}" | logger -t ARM -s

0 comments on commit df06158

Please sign in to comment.