Files
unraid-sound-driver/sound-driver.plg
ich777 afe698d425 added GitHub API check
- use GitHub API to detect latest version from selected package
- save md5 in packages directory
2022-07-21 07:21:13 +02:00

216 lines
7.3 KiB
XML

<?xml version="1.0" standalone="yes"?>
<!DOCTYPE PLUGIN [
<!ENTITY name "sound-driver">
<!ENTITY author "ich777">
<!ENTITY version "2022.07.21">
<!ENTITY launch "Settings/sound-driver">
<!ENTITY gitURL "https://github.com/&author;/unraid-&name;/raw/master">
<!ENTITY pluginURL "&gitURL;/&name;.plg">
<!ENTITY md5 "22fad02435056461129a8c831703e6dc">
<!ENTITY plugin "/boot/config/plugins/&name;">
<!ENTITY emhttp "/usr/local/emhttp/plugins/&name;">
<!ENTITY packages "/boot/config/plugins/&name;/packages">
]>
<PLUGIN name="&name;" author="&author;" version="&version;" launch="&launch;" pluginURL="&pluginURL;" min="6.9.2" support="https://forums.unraid.net/topic/92865-support-ich777-nvidiadvb-kernel-helperbuilder-docker/">
<CHANGES>
###2022.07.21
- Version detection from package via GitHub API
- Save md5 in packages directory
###2022.07.20
- Necessary changes for unRAID 6.11+
- Cleanup
###2022.04.11
- Added Plugin Update Helper when up-/downgrading unRAID version
###2021.06.23
- Changed package download repo
###2021.04.19
- Initial release
</CHANGES>
<FILE Run="/bin/bash">
<INLINE>
rm -f $(ls /boot/config/plugins/&name;/&name;*.txz 2&gt;/dev/null|grep -v '&version;')
</INLINE>
</FILE>
<FILE Name="/boot/config/plugins/&name;/&name;-&version;.txz" Run="upgradepkg --install-new">
<URL>&gitURL;/packages/&name;-&version;.txz</URL>
<MD5>&md5;</MD5>
</FILE>
<FILE Name="&emhttp;/README.md">
<INLINE>
**Sound Driver**
This package contains the Sound Drivers (and also a custom ALSA build) that enables you to make use of your Soundcard in Unraid.
</INLINE>
</FILE>
<FILE Run="/bin/bash">
<INLINE>
download() {
# Download Sound Driver
if wget -q -nc --show-progress --progress=bar:force:noscroll -O "&packages;/${KERNEL_V%%-*}/${LAT_PACKAGE}" "${DL_URL}/${LAT_PACKAGE}" ; then
wget -q -nc --show-progress --progress=bar:force:noscroll -O "&packages;/${KERNEL_V%%-*}/${LAT_PACKAGE}.md5" "${DL_URL}/${LAT_PACKAGE}.md5"
if [ "$(md5sum &packages;/${KERNEL_V%%-*}/${LAT_PACKAGE} | awk '{print $1}')" != "$(cat &packages;/${KERNEL_V%%-*}/${LAT_PACKAGE}.md5 | awk '{print $1}')" ]; then
echo
echo "---CHECKSUM ERROR!---"
rm -rf &plugin; &emhttp;
exit 1
fi
echo
echo "------------Sucessfully downloaded Sound Drivers, please wait...!------------"
else
echo
echo "------------------------Can't download Sound Drivers-------------------------"
rm -rf &plugin; &emhttp;
exit 1
fi
}
check() {
if ! ls -1 &packages;/${KERNEL_V%%-*}/ | grep -q "${PACKAGE}" ; then
LAT_PACKAGE="$(wget -qO- https://api.github.com/repos/ich777/unraid-sound-driver/releases/tags/${KERNEL_V} | jq -r '.assets[].name' | grep "${PACKAGE}" | grep -E -v '\.md5$' | sort -V | tail -1)"
echo
echo "--------------------------Downloading Sound Drivers--------------------------"
echo "---------This could take some time, please don't close this window!----------"
download
else
echo
echo "-------------------------Sound Drivers found locally-------------------------"
fi
}
install() {
# Install Sound Drivers
/sbin/installpkg "&packages;/${KERNEL_V%%-*}/${PACKAGE}*.txz"
depmod -a 2>/dev/null
sleep 1
udevadm control --reload 2>/dev/null &amp;&amp; udevadm trigger --action=add 2>/dev/null
sleep 3
}
activate() {
if [ ! -d &plugin;/conf ]; then
mkdir -p &plugin;/conf
fi
if [ "$(cat &plugin;/settings.cfg | grep "primary_audio_device" | cut -d '=' -f2)" != "empty" ]; then
echo -n "pcm."\!"default $(cat &plugin;/settings.cfg | cut -d '=' -f2 | cut -d ':' -f1):$(cat &plugin;/settings.cfg | cut -d '=' -f3 | cut -d ',' -f1)" > /etc/asound.conf
else
echo -n "# ALSA system-wide config file" > /etc/asound.conf
fi
sleep 1
if [ ! -f &plugin;/conf/asound.state ]; then
alsactl init -f &plugin;/conf/asound.state 2>/dev/null
sleep 1
alsactl store -f &plugin;/conf/asound.state 2>/dev/null
else
alsactl restore -f &plugin;/conf/asound.state 2>/dev/null
fi
echo -n "$(aplay -L | grep "CARD")" > /tmp/sound_outputs
}
# Define Variables
KERNEL_V="$(uname -r)"
PACKAGE="sound"
DL_URL="https://github.com/ich777/unraid-sound-driver/releases/download/$KERNEL_V"
if [ ! -d "&packages;/${KERNEL_V%%-*}" ]; then
mkdir -p "&packages;/${KERNEL_V%%-*}"
fi
#Create settings file if not found
if [ ! -f "&plugin;/settings.cfg" ]; then
echo 'primary_audio_device=empty' > "&plugin;/settings.cfg"
fi
#Check for old packages
rm -rf $(ls -d &packages;/* | grep -v "${KERNEL_V%%-*}")
#Check if Sound Drivers are already downloaded and installed
check
if [ ! -f /usr/sbin/alsactl ]; then
echo
echo "-------------------Installing Sound Drivers, please wait!--------------------"
install &gt; /dev/null
activate
echo
echo "------------------Installation of Sound Drivers successful-------------------"
echo
else
activate
echo
echo "------------------Installation of Sound Drivers successful-------------------"
echo
fi
#Check if Plugin Update Helper is downloaded and up-to-date
if [ ! -f &plugin;/plugin_update_helper ]; then
wget -q -T 5 -O &plugin;/plugin_update_helper "https://raw.githubusercontent.com/ich777/unraid-plugin_update_helper/master/plugin_update_helper"
else
CUR_V="$(grep -E "Plugin-Update-Helper version:" &plugin;/plugin_update_helper | awk '{print $4}')"
if [ ! -s /tmp/update-helper ]; then
echo "$(wget -T5 -qO- https://raw.githubusercontent.com/ich777/unraid-plugin_update_helper/master/plugin_update_helper | grep -E "Plugin-Update-Helper version:" | awk '{print $4}')" > /tmp/update-helper
AVAIL_V="$(cat /tmp/update-helper)"
else
AVAIL_V="$(cat /tmp/update-helper)"
fi
if [ ! -z "$AVAIL_V" ]; then
COMPARE="$(sort -V &lt;(echo -e "${AVAIL_V}\n$CUR_V") | tail -1)"
if [ "$CUR_V" != "$COMPARE" ]; then
wget -q -T 5 -O &plugin;/plugin_update_helper "https://raw.githubusercontent.com/ich777/unraid-plugin_update_helper/master/plugin_update_helper"
fi
fi
fi
#Check if Plugin Update Helper is installed and up to date
if [ ! -f /usr/bin/plugin_update_helper ]; then
cp &plugin;/plugin_update_helper /usr/bin/plugin_update_helper
chmod +x /usr/bin/plugin_update_helper
else
PLUGIN_V="$(grep -E "Plugin-Update-Helper version:" &plugin;/plugin_update_helper | awk '{print $4}')"
INST_V="$(grep -E "Plugin-Update-Helper version:" /usr/bin/plugin_update_helper | awk '{print $4}')"
COMPARE="$(sort -V &lt;(echo -e "${PLUGIN_V}\n$INST_V") | tail -1)"
if [ "$INST_V" != "$COMPARE" ]; then
kill $(ps aux | grep -E "inotifywait -q /boot/changes.txt -e move_self,delete_self" | grep -v "grep -E inotifywait" | awk '{print $2}') 2>/dev/null
sleep 1
cp &plugin;/plugin_update_helper /usr/bin/plugin_update_helper
chmod +x /usr/bin/plugin_update_helper
fi
fi
#Start Plugin Update Helper
if [ -z "$(ps aux | grep -E "inotifywait -q /boot/changes.txt -e move_self,delete_self" | grep -v "grep -E inotifywait" | awk '{print $2}')" ]; then
echo "/usr/bin/plugin_update_helper" | at now &gt; /dev/null 2&gt;&amp;1
fi
</INLINE>
</FILE>
<FILE Run="/bin/bash" Method="remove">
<INLINE>
echo "--------------------------------"
echo "---Uninstalling Sound Drivers---"
echo "--------------------------------"
# Remove plugin related files
removepkg &name;-&version;.txz
rm -rf &emhttp;
rm -rf &plugin;
echo
echo "------------------------------------------------------------------"
echo "------Sound Drivers uninstalled, please reboot your server!-------"
echo "------------------------------------------------------------------"
echo
</INLINE>
</FILE>
</PLUGIN>