5 col_green_bold="${ESC}[1;32m"
7 col_yellow="${ESC}[1;33m"
8 #col_cyan="${ESC}[1;36m"
11 opt_destdir=/srv/musiikki
12 opt_adminpwfile=${opt_destdir}/htpasswd
22 # default name of Raspian
23 default_hostname=raspberrypi
27 echo "${col_green}$*${col_reset}"
32 echo "${col_green_bold}$*${col_reset}"
37 echo "${col_red}$*${col_reset}"
42 test $opt_verbose -eq 1 || return
47 echo_newline_verbose()
49 test $opt_verbose -eq 1 || return
54 # ------------------------------------------------------------
56 assert_system_uidgid()
58 test -z "$opt_uid" || return
60 if [ -d ${opt_destdir} ]
62 opt_uid=$(stat --format=%u ${opt_destdir})
63 opt_gid=$(stat --format=%g ${opt_destdir})
65 echo -n "${col_yellow}Set file owner to${col_reset}: "
68 echo -n "${col_yellow}Set file group to${col_reset}: "
73 assert_system_hostname()
75 test -z "$opt_hostname" || return
77 echo -n "${col_yellow}Set hostname to${col_reset}: "
83 test -z "$opt_essid" || return
85 if [ -f /etc/musiikki.conf ]
87 opt_essid=$(grep '^title=' /etc/musiikki.conf)
88 opt_essid=${opt_essid#title=}
90 if [ -f /etc/hostapd/hostapd.conf ]
92 opt_essid=$(grep '^ssid=' /etc/hostapd/hostapd.conf)
93 opt_essid=${opt_essid#ssid=}
95 echo -n "${col_yellow}Set Wireless ESSID to${col_reset}: "
101 assert_system_wpakey()
103 test -z "$opt_wpakey" || return
105 if [ -f /etc/hostapd/hostapd.conf ]
107 opt_wpakey=$(grep '^wpa_passphrase=' /etc/hostapd/hostapd.conf)
108 opt_wpakey=${opt_wpakey#wpa_passphrase=}
110 echo -n "${col_yellow}Set Wireless WPA key to${col_reset}: "
115 assert_system_subnet()
117 test -z "$opt_subnet" || return
120 if grep -q '^server\.bind' /etc/lighttpd/lighttpd.conf
122 opt_subnet=$(grep '^server\.bind\s' /etc/lighttpd/lighttpd.conf)
123 opt_subnet=${opt_subnet#*\"}
124 opt_subnet=${opt_subnet%.1\"*}
126 echo -n "${col_yellow}Set subnet (3 octets only) to${col_reset}: "
131 # ------------------------------------------------------------
136 echo_ok_bold "Installing Infodrom MediaServer"
142 if [ "$(/usr/bin/whoami)" != "root" ]
144 echo_error "The installation needs to be done as root"
153 if [ ! -x install-system ]
155 echo_error "Current directory lacks executable install-system"
161 echo_error "Current directory lacks bin directory"
165 if [ ! -d config-templates ]
167 echo_error "Current directory lacks config-templates directory"
171 if [ "$(pwd)" != "${opt_destdir}" -a -x /usr/bin/rsync ]
176 rsync -arH ./ ${opt_destdir}/
177 chown -R ${opt_uid}.${opt_gid} ${opt_destdir}
185 if [ "$(cat /etc/hostname)" = "$default_hostname" ]
187 echo_verbose "Default hostname found"; echo_newline_verbose
188 assert_system_hostname
189 echo $opt_hostname > /etc/hostname
190 printf "192.168.1.1\t%s\n" "$opt_hostname" >> /etc/hosts
197 echo_verbose "Looking for programs: "
199 echo_verbose "sed... "
203 echo_error "Program sed missing"
207 echo_verbose "dpkg... "
208 if [ ! -x /usr/bin/dpkg ]
211 echo_error "Program dpkg missing"
215 echo_verbose "apt-get... "
216 if [ -x /usr/bin/apt-get ]
218 opt_apt=/usr/bin/apt-get
220 echo_verbose "apt... "
221 if [ -x /usr/bin/apt ]
225 echo_verbose "aptitude... "
226 if [ -x /usr/bin/aptitude ]
228 opt_apt=/usr/bin/aptitude
231 echo_error "High-level package manager missing (apt-get/apt/aptitude)"
242 assert_no_recommends()
244 if ! grep -q 'APT::Install-Recommends False;' /etc/apt/apt.conf.d/*
246 echo_ok "Configure APT not to install recommended packages"
247 echo 'APT::Install-Recommends False;' > /etc/apt/apt.conf.d/40recommends
255 echo_error "No high-level package manager available"
261 $opt_apt install -y $*
271 echo_error "No high-level package manager available"
286 if [ -f "/var/lib/dpkg/info/${pkg}.list" ]
298 echo_verbose "Looking for installed packages: "
300 for pkg in sudo super rsync hostapd isc-dhcp-server minidlna lighttpd samba
302 echo_verbose "${pkg}... "
303 if ! package_exists ${pkg}
305 missing="$missing $pkg"
309 echo_verbose "php... "
310 php_cgi=$(apt-cache search php7*-cgi|cut -d' ' -f 1|grep php7.*-cgi|sort|tail -n 1)
313 for pkg in ${php}-cgi ${php}-json ${php}-sqlite3
315 echo_verbose "${pkg}... "
316 if ! package_exists ${pkg}
318 missing="$missing $pkg"
326 echo_ok "Installing$missing"
327 install_packages $missing || return 1
328 echo_ok "Successfully installed$missing"
333 echo_verbose "Looking for installed packages: "
335 for pkg in triggerhappy avahi-daemon
337 echo_verbose "${pkg}... "
338 if package_exists ${pkg}
340 toomuch="$toomuch $pkg"
348 echo_ok "Removing$toomuch"
349 remove_packages $toomuch || return 1
350 echo_ok "Successfully removed$toomuch"
356 if [ ! -f /etc/musiikki.conf ]
360 echo_ok "Installing main configuration"
361 sed "s/{essid}/${opt_essid}/g;s!{basedir}!${opt_destdir}!g;s!{htpasswd}!${opt_adminpwfile}!g" config-templates/musiikki.conf.template > /root/.template
362 install -o root -g root -m 644 /root/.template /etc/musiikki.conf
363 rm -f /root/.template
369 if [ ! -f /etc/hostapd/hostapd.conf ]
374 echo_ok "Create hostapd configuration"
375 sed "s/{essid}/${opt_essid}/g;s/{wpakey}/${opt_wpakey}/g" config-templates/hostapd.conf.template > /root/.template
376 install -o root -g root -m 644 /root/.template /etc/hostapd/hostapd.conf
377 rm -f /root/.template
380 if grep -q '#DAEMON_CONF=""' /etc/default/hostapd
382 echo_ok "Activate hostapd"
383 sed -i 's!#DAEMON_CONF=""!DAEMON_CONF="/etc/hostapd/hostapd.conf"!' /etc/default/hostapd
389 if ! grep -q '^source /etc/network/interfaces.d/wlan1.conf' /etc/network/interfaces
391 echo >> /etc/network/interfaces
392 echo 'source /etc/network/interfaces.d/wlan1.conf' >> /etc/network/interfaces
393 echo >> /etc/network/interfaces
396 sed -i 's!#net.ipv4.ip_forward=1!net.ipv4.ip_forward=1!' /etc/sysctl.conf
397 if ! grep -q '^net.ipv4.ip_forward=1' /etc/sysctl.conf
399 echo >> /etc/sysctl.conf
400 echo 'net.ipv4.ip_forward=1' >> /etc/sysctl.conf
403 # iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
404 # iptables -A FORWARD -i wlan0 -o wlan1 -m state --state RELATED,ESTABLISHED -j ACCEPT
405 # iptables -A FORWARD -i wlan1 -o wlan0 -j ACCEPT
406 # iptables-save > /srv/musiikki/iptables_nat.conf
413 if [ ! -f /etc/network/interfaces.d/wlan0.conf ]
415 cat <<EOT > /etc/network/interfaces.d/wlan0.conf
417 iface wlan0 inet static
418 address ${opt_subnet}.1
419 netmask 255.255.255.0
420 broadcast ${opt_subnet}.255
421 network ${opt_subnet}.0
422 #gateway ${opt_subnet}.1
424 echo "source /etc/network/interfaces.d/wlan0.conf" >> /etc/network/interfaces
427 if ! grep -q "^subnet ${opt_subnet}.0 " /etc/dhcp/dhcpd.conf
429 echo_ok "Add DHCP configuration"
430 sed "s/{subnet}/${opt_subnet}/g" config-templates/dhcpd.conf.template >> /etc/dhcp/dhcpd.conf
433 if grep -q 'INTERFACESv4=""' /etc/default/isc-dhcp-server
435 echo_ok "Add WLAN interface to DCHP config"
436 sed -i 's/INTERFACESv4=".*"/INTERFACESv4="wlan0"/' /etc/default/isc-dhcp-server
442 echo_verbose "Asserting permissions "
443 for prg in $(cd bin && echo *)
445 test $prg != musiikki-rescan || continue
447 echo_verbose "${prg}... "
448 if ! grep -q "^${prg}" /etc/super.tab
450 printf "%s\t%s/bin/%s www-data u+g=root password=n\n" ${prg} ${opt_destdir} ${prg} >> /etc/super.tab
462 if ! grep -q "^friendly_name=${opt_essid}" /etc/minidlna.conf
464 sed -i "s!#friendly_name=!friendly_name=${opt_essid}!;s!^media_dir=.*!!" /etc/minidlna.conf
465 sed -i "s!#listening_ip=!listening_ip=${opt_subnet}.1!" /etc/minidlna.conf
466 sed -i "s!#db_dir=.*!db_dir=/media/music/cache!" /etc/minidlna.conf
468 echo "" >> /etc/minidlna.conf
469 echo "model_name=${opt_essid}" >> /etc/minidlna.conf
470 echo "media_dir=A,/media/music/music" >> /etc/minidlna.conf
471 echo "media_dir=P,/media/music/pictures" >> /etc/minidlna.conf
472 echo "media_dir=V,/media/music/video" >> /etc/minidlna.conf
475 test -d /media/music/cache || install -d -m 755 /media/music/cache
476 chown -R minidlna:minidlna /media/music/cache
478 test -d /media/music/music/playlists || install -d -m 755 /media/music/music/playlists
479 chown -R www-data:www-data /media/music/music/playlists
484 echo_verbose "Asserting lighttpd modules "
487 echo_verbose "05-auth... "
488 if [ ! -f /etc/lighttpd/conf-enabled/05-auth.conf ]
492 cat <<EOT > /etc/lighttpd/conf-enabled/05-auth.conf
493 # /usr/share/doc/lighttpd/authentication.txt.gz
495 server.modules += ( "mod_auth" )
497 auth.backend = "plain"
498 auth.backend.plain.userfile = "${opt_adminpwfile}"
499 # auth.backend.plain.groupfile = "lighttpd.group"
501 auth.require = ( "/admin/" =>
504 "realm" => "${opt_essid}",
505 "require" => "user=admin",
511 for name in 10-fastcgi 15-fastcgi-php
513 echo_verbose "${name}... "
514 if [ ! -f /etc/lighttpd/conf-enabled/${name}.conf ]
516 ln -s ../conf-available/${name}.conf /etc/lighttpd/conf-enabled/${name}.conf
522 if [ ! -f ${opt_adminpwfile} ]
524 echo -n "${col_yellow}Set web admin password to${col_reset}: "
527 echo "admin:${admin_pw}" > ${opt_adminpwfile}
530 chown www-data.www-data ${opt_adminpwfile}
532 if ! grep -q '^server.tag' /etc/lighttpd/lighttpd.conf
537 sed -i "s!^server.document-root\\s*=\\s*\".*\"!server.document-root = \"${opt_destdir}/html\"!" /etc/lighttpd/lighttpd.conf
538 echo "server.tag = \"${opt_essid}\"" >> /etc/lighttpd/lighttpd.conf
539 echo "server.bind = \"${opt_subnet}.1\"" >> /etc/lighttpd/lighttpd.conf
545 if ! grep -q '^\[musicread\]$' /etc/samba/smb.conf
547 echo_ok "Add shares to Samba"
548 sed "s/{essid}/${opt_essid}/g" config-templates/smb.conf.template >> /etc/samba/smb.conf
551 if ! grep -q '^musicread:' /etc/passwd
555 echo_ok "Create read/only Samba account"
556 adduser --quiet --disabled-password --system --group --no-create-home --home /var/lib/misc --gecos "${opt_essid} read/only account" musicread
559 if ! grep -q '^musicwrite:' /etc/passwd
563 echo_ok "Create read/write Samba account"
564 adduser --quiet --disabled-password --system --group --no-create-home --home /var/lib/misc --gecos "${opt_essid} read/write account" musicwrite
570 if [ ! -f /etc/cron.d/musiikki ]
572 echo_ok "Install crontab"
573 cp config-templates/cron.d.template /etc/cron.d/musiikki
576 if [ ! -d /var/local/musiikki ]
578 install -d -o minidlna -g minidlna -m 755 /var/local/musiikki
581 if [ ! -d /var/local/musiikki/rescan ]
583 install -d -o minidlna -g minidlna -m 777 /var/local/musiikki/rescan
590 assert_root || exit 2
591 assert_directory || exit 2
592 assert_hostname || exit 2
593 assert_programs || exit 2
594 assert_no_recommends || exit 2
595 assert_packages || exit 2