Skip to content

Instantly share code, notes, and snippets.

@gaikokujinch
Last active January 29, 2017 12:39
Show Gist options
  • Save gaikokujinch/f9d39a773ec0d108ab70d43c4b6269d2 to your computer and use it in GitHub Desktop.
Save gaikokujinch/f9d39a773ec0d108ab70d43c4b6269d2 to your computer and use it in GitHub Desktop.
Madsonic
#!/bin/sh
#
# PROVIDE: madsonic
# REQUIRE: LOGIN DAEMON NETWORKING
# KEYWORD: shutdown
#
# To enable madsonic, add this line to your /etc/rc.conf:
#
# madsonic_enable="YES"
#
# And optionally these line:
#
# madsonic_user="username" # Default is "root"
# madsonic_bin="/path/to/madsonic.sh" # Default is "/usr/local/sbin/madsonic.sh"
. /etc/rc.subr
name="madsonic"
rcvar="${name}_enable"
load_rc_config $name
required_files=$madsonic_bin
: ${madsonic_enable="NO"}
: ${madsonic_user="root"}
: ${madsonic_port="4040"}
: ${madsonic_home="/usr/local/madsonic"}
: ${madsonic_bin="${madsonic_home}/madsonic.sh"}
: ${madsonic_music_folder="/mnt/media/music"}
: ${madsonic_podcast_folder="${madsonic_music_folder}/podcasts"}
: ${madsonic_playlist_folder="${madsonic_music_folder}/playlists"}
: ${madsonic_playlist_import_folder="${madsonic_playlist_folder}/import"}
: ${madsonic_playlist_export_folder="${madsonic_playlist_folder}/export"}
: ${madsonic_playlist_backup_folder="${madsonic_playlist_folder}/backup"}
: ${madsonic_pidfile="${madsonic_home}/madsonic.pid"}
status_cmd="${name}_status"
stop_cmd="${name}_stop"
command=$madsonic_bin
command_args="--pidfile=${madsonic_pidfile} --home=${madsonic_home} --port=${madsonic_port} --default-music-folder=${madsonic_music_folder} --default-podcast-folder=${madsonic_podcast_folder} --default-playlist-import-folder=${madsonic_playlist_import_folder} --default-playlist-export-folder=${madsonic_playlist_export_folder} --default-playlist-backup-folder=${madsonic_playlist_backup_folder}"
verify_pid() {
pid=`cat ${madsonic_pidfile} 2>/dev/null`
ps -p ${pid} | grep -q "madsonic"
return $?
}
madsonic_stop() {
echo "Stopping ${name}"
verify_pid
if [ -n "${pid}" ]; then
kill ${sig_stop} ${pid}
wait_for_pids ${pid}
echo "Stopped"
fi
rm -f ${madsonic_pidfile}
}
madsonic_status() {
verify_pid && echo "${name} is running as ${pid}" || echo "${name} is not running"
}
run_rc_command "$1"

Madsonic

ToC

Notes

jls
jexec 18 tcsh

Inside the jail

Optional: give root a password

passwd

Add user subsonic

adduser

Username: subsonic Full name: Subsonic Uid: (1011) Login group: (default) Login group is urbackup. Invite urbackup into other groups: wheel Login class: (default) Shell: tcsh Home directory: (default) Home directory permissions: (default) Use password-based authentication: no Lock out the account after creation: (default) OK?: yes Add another user?: no

mkdir /music
chown -R subsonic:subsonic /music
su - subsonic
mkdir /home/subsonic/install

Add storage

Add storage to /music in the NAS gui

Install Madsonic

exit
pkg update
pkg upgrade
pkg install madsonic-standalone
echo 'madsonic_enable="YES"' >> /etc/rc.conf
service madsonic start

Now open a web browser and go to http://10.0.0.26:4040

Alternate install


mkdir -p /usr/local/madsonic && cd /usr/local/madsonic
wget -Omadsonic.tar.gz http://madsonic.org/download/6.0/20160122_madsonic-6.0.7960-standalone.zip
tar -zxvf madsonic.tar.gz
rm madsonic.tar.gz
chown -R media:media /usr/local/madsonic

vi /usr/local/etc/rc.d/madsonic
# Use the file "madsonic" attached below
chmod a+x /usr/local/etc/rc.d/madsonic

sysrc madsonic_enable=YES
sysrc madsonic_user=media
sysrc madsonic_group=media
sysrc madsonic_bin=/usr/local/madsonic/madsonic.sh
sysrc madsonic_podcast_folder=/mnt/media/music/podcasts
sysrc madsonic_playlist_folder=/mnt/media/music/playlists

Here is the madsonic launch script to use.

Install SSL

Source: https://project.altservice.com/issues/761 Install openssl and zip:

pkg install openssl zip

Generate a strong SSL key and a CSR to send for signing by a CA:

cd /usr/local/etc
openssl req -sha512 -out madsonic.example.com.csr -new -newkey rsa:4096 -nodes -keyout madsonic.example.com.key

Combine the SSL key, certificate, and CA intermediate certificate files together into a madsonic-bundle.crt file:

cat madsonic.example.com.key madsonic.example.com.crt startcom.class1.bundle > madsonic-bundle.crt

Next convert it to a format madsonic understands:

openssl pkcs12 -in madsonic-bundle.crt -export -out madsonic-bundle.pkcs12

When prompted enter madsonic as export password. Now you should have a madsonic-bundle.pkcs12 file, we need to import this into a keystore for Madsonic to use:

keytool -importkeystore -srckeystore madsonic-bundle.pkcs12 -destkeystore madsonic.keystore -srcstoretype PKCS12 -srcstorepass madsonic -srcalias 1 -destalias madsonic

When prompted enter madsonic as the password. Finally we need to put the keystore into the file Madsonic uses to boot:

zip /usr/local/madsonic-standalone/madsonic-booter-jar-with-dependencies.jar madsonic.keystore

Now set the madsonic_https_port in the rc.conf file and restart madsonic:

echo 'madsonic_https_port="4443"' >> /etc/rc.conf
service madsonic restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment