#!/bin/sh
# Script for installing optware on a Western Digital Worldbook (White light Edition)
# Written by frater
#
export PATH=/opt/bin:/opt/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin
SCRIPTVER="Tue Mar 16 08:57:52 CET 2010"
os_date="`nvram get os_date`"
os_year=`echo $os_date | awk '{print $3}'`
os_month=`echo $os_date | awk '{print $1}'`
os_day=`echo $os_date | awk '{print $2}'`
KERNEL=`/bin/uname -r`
k26=0
/bin/uname -r | grep -q "^2\.6\." && k26=1
OLD_RC=1
[ $os_year -gt 2009 ] && OLD_RC=0
[ $os_year -eq 2009 ] && [ "$os_month" == "Dec" ] && OLD_RC=0
REBOOT_CORRECT=0
[ $os_year -gt 2009 ] && REBOOT_CORRECT=1
[ $os_year -eq 2009 ] && [ "$os_month" == "Dec" ] && [ $day -gt 2 ] && [ $day -lt 10 ] && REBOOT_CORRECT=1
echo -e "$0\nWritten on: ${SCRIPTVER}"
echo -e "If you're giving feedback, please post the version as well\n\n"
if ! grep -i -q "MIPS" /proc/cpuinfo ; then
echo "This device has no MIPS processor"
exit 1
fi
if [ ! "$USER" = root ]; then
echo -e "You're not root, you're ${USER}..\nI will not have enough permissions to do the things I want to do.\nExiting..."
exit 1
fi
cd /tmp
if ! /bin/mount 2>/dev/null | grep -q " on /opt " ; then
echo -e "You need to mount /opt\nExiting..."
exit 1
fi
echo -e "\n\nThis will take a while!\nIf you need to do some shopping.... do it now! ;-)\n"
sleep 1
mkdir -p /opt/etc/init.d 2>/dev/null
if [ ! -d /opt/etc/init.d ] ; then
echo -e "I'm unable to create the directory /opt/etc/init.d Check your config"
exit 1
fi
ipkg-opt print_installation_architecture >/dev/null 2>&1
if [ ${?} -eq 0 ] ; then
echo -e "You already installed optware, good show!\nI will execute an update"
ipkg-opt update
else
echo -e "Optware is not installed... Let's install it\n"
wget [url]http://wd.mirmana.com/optware-install-ddwrt.sh[/url] -O - | tr -d '\r' > /tmp/optware-install.sh
# wget [url]http://www.3iii.dk/linux/optware/optware-install-ddwrt.sh[/url] -O - | tr -d '\r' > /tmp/optware-install.sh
# wget [url]http://www.wlan-sat.com/boleo/optware/optware-install-ddwrt.sh[/url] -O - | tr -d '\r' > /tmp/optware-install.sh
sh /tmp/optware-install.sh
ipkg-opt update
if [ $? -ne 0 ] ; then
echo "Optware installation was not successfull... exit!"
exit 1
fi
fi
rc_startup=`nvram get rc_startup`
if [ ! $? -eq 0 ] ; then
echo "Error getting startup value... is this really DD-WRT?"
exit 1
fi
if [ $OLD_RC -ne 0 ] ; then
echo -en "nvram set rc_startup=\"" >/tmp/chng_startup
echo -n "${rc_startup}" | sed -e 's/[$`"\]/\\&/g' >> /tmp/chng_startup
if ! grep -q "/init.d/optS" /tmp/chng_startup ; then
echo -e "\nn=1\nwhile [ ! -d /opt/etc/init.d ] ; do\n sleep 3\n [ \\\$n -gt 30 ] && break\n let n+=1\ndone\n/opt/etc/init.d/optS\n\"" >>/tmp/chng_startup
chmod +x /tmp/chng_startup
/tmp/chng_startup
nvram commit
fi
rm /tmp/chng_startup
rc_shutdown=`nvram get rc_shutdown`
if ! nvram get rc_shutdown | grep -q "/init.d/optK" ; then
echo -en "nvram set rc_shutdown=\"" >/tmp/chng_shutdown
echo -e "/opt/etc/init.d/optK\n" >>/tmp/chng_shutdown
echo -n "${rc_shutdown}" | sed -e 's/[$`"\]/\\&/g' >>/tmp/chng_shutdown
echo -en "\"" >>/tmp/chng_shutdown
chmod +x /tmp/chng_shutdown
/tmp/chng_shutdown
rm /tmp/chng_shutdown
nvram commit
fi
fi
mkdir -p /opt/etc/init.d 2>/dev/null
mkdir -p /opt/usr/sbin 2>/dev/null
if [ ! -d /opt/etc/init.d ] ; then
echo "I was unable to create the directory /opt/etc/init.d, check if it is writable"
exit 1
fi
mkdir -p /opt/var/backups
mkdir -p /opt/tmp
cd /opt/etc/init.d
isVIRGIN=1
[ -f /opt/etc/init.d/S35automount ] && isVIRGIN=0
S45DISABLED=1
[ -f /opt/etc/init.d/S45pixelserv ] && grep -q "DISABLED=0" /opt/etc/init.d/S45pixelserv && S45DISABLED=0
secIP=
terIP=
if [ -f /opt/etc/init.d/S80vlighttpd ] ; then
secIP=`grep "^secIP=[0-9]" /opt/etc/init.d/S80vlighttpd | awk -F= '{print $2}'`
terIP=`grep "^terIP=[0-9]" /opt/etc/init.d/S80vlighttpd | awk -F= '{print $2}'`
fi
wget -qO optK [url]http://wd.mirmana.com/optK[/url]
wget -qO optS [url]http://wd.mirmana.com/optS[/url]
wget -qO S00optware [url]http://wd.mirmana.com/S00optware[/url]
# wget -qO S01modutils [url]http://wd.mirmana.com/S01modutils[/url]
wget -qO S01bashAsShell [url]http://wd.mirmana.com/S01bashAsShell[/url]
wget -qO S05chngProfile [url]http://wd.mirmana.com/S05chngProfile[/url]
wget -qO S10swap [url]http://wd.mirmana.com/S10swap[/url]
wget -qO S20wwwdata [url]http://wd.mirmana.com/S20wwwdata[/url]
[ $k26 == 0 ] && wget -qO S30usbmount [url]http://wd.mirmana.com/S30usbmount[/url]
wget -qO S35automount [url]http://wd.mirmana.com/S35automount[/url]
wget -qO S95watchprinter [url]http://wd.mirmana.com/S95watchprinter[/url]
wget -qO S95optremount [url]http://wd.mirmana.com/S95optremount[/url]
wget -qO K99optware [url]http://wd.mirmana.com/K99optware[/url]
if [ $REBOOT_CORRECT -ne 0 ] ; then
wget -qO S08reboot [url]http://wd.mirmana.com/S08reboot[/url]
fi
# kill the temporary fix for reboot if DD-WRT supports it natively
if grep -q "opt/etc" /etc/profile ; then
rm -f /opt/etc/init.d/S08reboot 2>/dev/null
fi
if [ $isVIRGIN = 1 ] ; then
wget -qO S60transmission_init [url]http://wd.mirmana.com/S60transmission_init[/url]
chmod +x K* 2>/dev/null
chmod +x S*
fi
chmod +x optS
chmod +x optK
# Disable usbmount in k26
[ $k26 == 0 ] || chmod -x S30usbmount 2>/dev/null
wget -qO S80pound [url]http://wd.mirmana.com/S80pound[/url]
wget -qO S45pixelserv [url]http://wd.mirmana.com/S45pixelserv[/url]
wget -qO S80vlighttpd [url]http://wd.mirmana.com/S80vlighttpd[/url]
wget -qO S90asterisk [url]http://wd.mirmana.com/S90asterisk[/url]
wget -qO S90transmission [url]http://wd.mirmana.com/S90transmission_as_user[/url]
wget -qO S90nzbget [url]http://wd.mirmana.com/S90nzbget[/url]
if [ $OLD_RC -eq 0 ] ; then
wget -qO S95asiablock [url]http://wd.mirmana.com/S95asiablock[/url]
else
wget -qO S95asiablock [url]http://wd.mirmana.com/S95asiablock_old[/url]
fi
[ ${S45DISABLED} = 0 ] && sed -i -e "s/^DISABLED=1/DISABLED=0/" /opt/etc/init.d/S45pixelserv
if [ ! -z "${secIP}" ] ; then
/opt/bin/sed -i -e "s/^secIP=$/secIP=${secIP}/" /opt/etc/init.d/S80vlighttpd
/opt/bin/sed -i -e "s/^terIP=$/terIP=${terIP}/" /opt/etc/init.d/S80vlighttpd
fi
sed -i -e 's/^prefix=\/usr/prefix=\/opt/' /opt/etc/init.d/S90asterisk
mkdir -p /opt/etc/asterisk
wget -qO /opt/etc/asterisk/asterisk.sh [url]http://wd.mirmana.com/asterisk.sh[/url]
chmod +x /opt/etc/asterisk/asterisk.sh
# Remove all symbolic links
rm K90swap 2>/dev/null
rm K70usbmount 2>/dev/null
rm K65automount 2>/dev/null
rm K20samba 2>/dev/null
rm K20pound 2>/dev/null
rm K10asterisk 2>/dev/null
rm K10transmission 2>/dev/null
rm K10nzbget 2>/dev/null
rm K05asiablock 2>/dev/null
ln -s S10swap K90swap 2>/dev/null
ln -s S30usbmount K70usbmount 2>/dev/null
ln -s S35automount K65automount 2>/dev/null
ln -s S80samba K20samba 2>/dev/null
ln -s S80vlighttpd K20vlighttpd 2>/dev/null
ln -s S80lighttpd K20lighttpd 2>/dev/null
ln -s S80pound K20pound 2>/dev/null
ln -s S90asterisk K10asterisk 2>/dev/null
ln -s S90transmission K10transmission 2>/dev/null
ln -s S90nzbget K10nzbget 2>/dev/null
# ln -s S95asiablock K05asiablock
# The services
ipkg-opt install xinetd
ipkg-opt install samba2
[ $? -eq 0 ] && chmod -x /opt/etc/init.d/S10xinetd
wget -qO /opt/etc/init.d/S80samba [url]http://wd.mirmana.com/S80samba[/url]
wget -qO /opt/etc/init.d/S10xinetd [url]http://wd.mirmana.com/S10xinetd[/url]
# widen subnet of swat
sed -i -e 's/192.168.1.0\/24/192.168.0.0\/16/' /opt/etc/xinetd.d/swat
wget -qO /opt/etc/xinetd.d/p910nd [url]http://wd.mirmana.com/xinetd_p910nd[/url]
#Only install busybox if it never been installed before
# as it will replace the proper gnu tools
# I only want it for its httpd I'm using for the asterisk interface
[ -e /opt/bin/busybox ] || ipkg-opt install busybox
ipkg-opt -force-reinstall -force-overwrite install util-linux-ng
ipkg-opt -force-reinstall -force-overwrite install inetutils
ipkg-opt install libidn
ipkg-opt install coreutils
ipkg-opt install diffutils
ipkg-opt install findutils
if [ $k26 = 1 ] ; then
ipkg-opt remove modutils 2>/dev/null
else
ipkg-opt install modutils
fi
ipkg-opt install psutils
ipkg-opt install psmisc
ipkg-opt install transmission
ipkg-opt install pound
ipkg-opt install asterisk14
ipkg-opt install bind
ipkg-opt install lighttpd
ipkg-opt install openldap-libs # needed for mod_auth
ipkg-opt install sqlite # needed for mod_webdav
ipkg-opt install zip
ipkg-opt install php-fcgi
ipkg-opt install libjpeg
ipkg-opt install libxslt
ipkg-opt install libxml2
ipkg-opt install nzbget
# Add NAME=named to the config, so it can be used by the script 'service'
if [ -f /opt/etc/init.d/S09named ] ; then
fdate="`date -r /opt/etc/init.d/S09named`"
if ! grep -q "^NAME=" /opt/etc/init.d/S09named ; then
sed -i -e 's/\/bin\/sh/\/bin\/sh\nNAME=named/' /opt/etc/init.d/S09named
touch -d "$fdate" /opt/etc/init.d/S09named
fi
chmod -x /opt/etc/init.d/S09named
fi
[ -f /opt/etc/init.d/S08samba ] && chmod -x /opt/etc/init.d/S08samba
if [ $isVIRGIN = 1 ] ; then
chmod +x /opt/etc/init.d/S80samba
[ -f /opt/etc/samba/smb.conf ] && cp -p /opt/etc/samba/smb.conf /opt/etc/samba/smb.conf.`date +%y-%b.%d...%H.%M -r /opt/etc/samba/smb.conf`
wget -O /opt/etc/samba/smb.conf [url]http://wd.mirmana.com/smb.conf[/url]
fi
# pixelserv
# wget -qO /opt/etc/init.d/S95pixelserv [url]http://wd.mirmana.com/S95pixelserv[/url]
wget -qO /opt/usr/sbin/pixelserv [url]http://wd.mirmana.com/pixelserv[/url]
chmod +x /opt/usr/sbin/pixelserv
wget -qO /opt/usr/sbin/pixelserv.pl [url]http://wd.mirmana.com/pixelserv.pl[/url]
chmod +x /opt/usr/sbin/pixelserv.pl
if [ $isVIRGIN = 1 ] ; then
mkdir -p /opt/etc/pixelserv
wget -qO /opt/etc/pixelserv/hosts.include [url]http://wd.mirmana.com/hosts.include[/url]
fi
cd /opt/usr/sbin
# backupessential
wget -q [url]http://wd.mirmana.com/backupessential[/url]
wget -q [url]http://wd.mirmana.com/vars_to_include[/url]
wget -q [url]http://wd.mirmana.com/vars_to_skip[/url]
wget -q [url]http://wd.mirmana.com/vars_preferred[/url]
chmod +x /opt/usr/sbin/backupessential
#
# handy program
wget -qO /opt/sbin/aggregate [url]http://wd.mirmana.com/aggregate[/url]
# Some handy scripts
wget -qO /opt/usr/sbin/watchprinter [url]http://wd.mirmana.com/watchprinter[/url]
wget -qO /opt/usr/sbin/optlog [url]http://wd.mirmana.com/optlog[/url]
wget -qO /opt/usr/sbin/service [url]http://wd.mirmana.com/service[/url]
# modify the header of these 2 perl-scripts
wget -qO /opt/usr/sbin/imdb [url]http://wd.mirmana.com/imdb[/url]
wget -qO /opt/usr/sbin/sendEmail [url]http://wd.mirmana.com/sendEmail[/url]
sed -i -e 's/\/usr\/bin\/perl/\/opt\/bin\/perl/' /opt/usr/sbin/imdb
sed -i -e 's/\/usr\/bin\/perl/\/opt\/bin\/perl/' /opt/usr/sbin/sendEmail
chmod +x /opt/sbin/aggregate
chmod +x /opt/usr/sbin/watchprinter
chmod +x /opt/usr/sbin/optlog
chmod +x /opt/usr/sbin/service
chmod +x /opt/usr/sbin/imdb
chmod +x /opt/usr/sbin/sendEmail
chmod -x /opt/etc/init.d/S80lighttpd
if [ -e /dev/usb ] ; then
wget -O /opt/etc/init.d/S95watchprinter [url]http://wd.mirmana.com/S95watchprinter[/url]
ipkg-opt install usbutils
ipkg-opt install p910nd
# Disable the p910nd script....
nvram get usb_printer | grep -q 0 || chmod +x /opt/etc/init.d/S95watchprinter 2>/dev/null
else
chmod -x /opt/etc/init.d/S95watchprinter 2>/dev/null
fi
chmod -x /opt/etc/init.d/S30usbmount 2>/dev/null
chmod -x S95p910nd 2>/dev/null
# Supporting scripts for transmission
wget -qO /opt/usr/sbin/mkdvd [url]http://wd.mirmana.com/mkdvd[/url]
wget -qO /opt/usr/sbin/mvmovie [url]http://wd.mirmana.com/mvmovie[/url]
wget -qO /opt/usr/sbin/trans_watchdog [url]http://wd.mirmana.com/trans_watchdog[/url]
sed -i -e "s/^# *BASEDIR=\/mnt/BASEDIR=\/mnt/" /opt/usr/sbin/mkdvd
sed -i -e "s/^#\!\/bin\/sh/#\!\/opt\/bin\/bash/" /opt/usr/sbin/mkdvd
sed -i -e "s/^# *BASEDIR=\/mnt/BASEDIR=\/mnt/" /opt/usr/sbin/mvmovie
sed -i -e "s/^#\!\/bin\/sh/#\!\/opt\/bin\/bash/" /opt/usr/sbin/mvmovie
sed -i -e "s/^#\!\/bin\/sh/#\!\/opt\/bin\/bash/" /opt/usr/sbin/trans_watchdog
chmod +x /opt/usr/sbin/mkdvd
chmod +x /opt/usr/sbin/mvmovie
chmod +x /opt/usr/sbin/trans_watchdog
echo -e "\nInstalling optware packages... (will take a while)\n"
# You really should have these packages
ipkg-opt install lsof
ipkg-opt install libcurl
ipkg-opt install sudo
ipkg-opt install bash
ipkg-opt install vim
ipkg-opt -force-reinstall -force-overwrite install net-tools
ipkg-opt install grep
ipkg-opt install procps
ipkg-opt install sed
ipkg-opt install wget
ipkg-opt install unzip
ipkg-opt install unrar
ipkg-opt install gawk
ipkg-opt install tar
ipkg-opt install gzip
ipkg-opt install bzip2
ipkg-opt install openssl
ipkg-opt install calc
ipkg-opt install par2cmdline
mkdir -p /opt/share/oversight
/opt/bin/wget -O /opt/share/oversight/oversight.tgz [url]http://wd.mirmana.com/oversight.tgz[/url]
/opt/bin/tar xvzf /opt/share/oversight/oversight.tgz -C /opt
if [ ! -e /opt/etc/nzbget.conf ] ; then
mkdir -p /mnt/usenet 2>/dev/null
cp -p /opt/oversight/conf/unpak.cfg.example /opt/oversight/conf/unpak.cfg
cp /opt/share/doc/nzbget/nzbget.conf.example /opt/etc/nzbget.conf
sed -i -e 's/\$MAINDIR=.*/\$MAINDIR=\/mnt\/usenet/' /opt/etc/nzbget.conf
sed -i -e 's/ServerIp=.*/ServerIp=0.0.0.0/' /opt/etc/nzbget.conf
sed -i -e 's/ParPauseQueue=.*/ParPauseQueue=yes/' /opt/etc/nzbget.conf
sed -i -e 's/PostPauseQueue=.*/PostPauseQueue=yes/' /opt/etc/nzbget.conf
sed -i -e 's/AllowReProcess=.*/AllowReProcess=yes/' /opt/etc/nzbget.conf
sed -i -e 's/PostProcess=.*/PostProcess=\/opt\/oversight\/unpak.sh/' /opt/etc/nzbget.conf
fi
# This one's for the utility 'host'
if [ $isVIRGIN = 1 ] ; then
ipkg-opt install bind
chmod -x /opt/etc/init.d/S09named
fi
# These are nice to have, too
ipkg-opt -force-reinstall -force-overwrite install e2fsprogs
ipkg-opt install htop
ipkg-opt install ncdu
ipkg-opt -force-reinstall install less
ipkg-opt install whois
ipkg-opt install tcpdump
ipkg-opt install netcat
ipkg-opt install cdrtools
ipkg-opt install mc
ipkg-opt install httping
ipkg-opt install m4
ipkg-opt install make
ipkg-opt install vsftpd
grep -q "^secure_chroot_dir" /opt/etc/vsftpd.conf || echo 'secure_chroot_dir=/opt/usr/share/empty' >>/opt/etc/vsftpd.conf
mkdir -p /opt/share/empty
xinfile=/opt/etc/xinetd.d/vsftpd
if [ ! -e $xinfile ] ; then
mkdir -p /opt/etc/xinetd.d
echo -e "service ftp\n{" >$xinfile
echo -e "\tsocket_type\t= stream" >>$xinfile
echo -e "\twait\t\t= no" >>$xinfile
echo -e "\tuser\t\t= root" >>$xinfile
echo -e "#\tonly_from\t= 192.168.0.0/16" >>$xinfile
echo -e "\tserver\t\t= /opt/sbin/vsftpd" >>$xinfile
echo -e "\tdisable\t\t= Yes" >>$xinfile
echo -e "}" >>$xinfile
fi
#if [ ! -e /opt/local/twonkymedia/twonkymedia.sh ] ; then
twonkver=5.0.68
support=unsupported
twonkver=5.1.2
support=downloads
if [ -f /opt/local/twonkymedia/twonky.${twonkver}.zip ] ; then
echo "Twonky already installed"
else
echo "Install Twonky version: $twonkver"
mkdir -p /opt/local/twonkymedia 2>/dev/null
if [ -e /opt/local/twonkymedia ] ; then
wget -q -O /opt/local/twonkymedia/twonky.${twonkver}.zip http://www.twonkyforum.com/${support}/${twonkver}/twonkymedia-mipsel-uclibc-0.9.28-${twonkver}.zip
cd /opt/local/twonkymedia
if [ -f twonky.${twonkver}.zip ] ; then
unzip -o twonky.${twonkver}.zip
# chmod +x twonkymedia.sh
wget -O /opt/etc/init.d/S95twonky [url]http://wd.mirmana.com/S95twonky[/url]
ln -s S95twonky /opt/etc/init.d/K05twonky
chmod +x /opt/etc/init.d/S95twonky
fi
else
echo "Unable to create /opt/local/twonkymedia"
fi
fi
optsize=`df | grep opt | grep -o "[0-9]*%" | tr -cd 0-9`
if [ -z "${optsize}" ] ; then
echo "I could not determine the size of /opt"
else
if [ ${optsize} -gt 85 ] && [ -z "`which perl`" ] ; then
echo "You don't have perl, but your /opt is already bigger than 85% (${optsize}%)"
echo "I will not install perl"
else
# colordiff will install perl
ipkg-opt install ipcalc
ipkg-opt install colordiff
ipkg-opt install perl-libwww
fi
fi
/opt/bin/ifconfig 2>&1 >/dev/null
if [ $? -ne 0 ] ; then
echo "Optware's ifconfig in net-tools is broken. I will remove it so the standard utility will be used!"
rm -f /opt/bin/ifconfig
fi
KEEPBASH=1
if [ $os_year -lt 2009 ] ; then
KEEPBASH=0
elif echo $os_date | grep -q "2009" ; then
echo $os_date | grep -q -e "^Oct" -e "^Nov" -e "^Dec" || KEEPBASH=0
if echo $os_date | grep -q -e "^Sep" ; then
DOM=`echo $os_date | awk '{print $2}'`
[ $DOM -lt 5 ] && KEEPBASH=0
fi
fi
if [ $KEEPBASH -eq 0 ] ; then
echo -e "\nI disable the shell replacement because your firmware is too old. ${os_date}\n"
chmod -x /opt/etc/init.d/S01bashAsShell
fi
if [ $k26 == 1 ] ; then
wget -O /opt/etc/init.d/S01fixparts [url]http://wd.mirmana.com/S01fixparts[/url]
chmod +x /opt/etc/init.d/S01fixparts
ipkg-opt install ntfs-3g
ipkg-opt install ntfsprogs
mkdir -p /opt/lib/modules/$KERNEL
wget -O /opt/lib/modules/$KERNEL/fuse.ko ftp://ftp.dd-wrt.com/others/eko/Public/modules/$KERNEL/fuse.ko
chmod +x /opt/lib/modules/$KERNEL/fuse.ko
fi
echo -e "\nOptware and basic packages are installed.\n"
if [ $isVIRGIN = 1 ] ; then
echo -e "\nI installed bind to get the handy utility 'host', but I don't think you want to run your WDWB as a DNS-server"
echo -e "\nI will delete the executable flag of /opt/etc/init.d/S09named.\n"
echo -e "\nJust make it executable again if you DO need it.\n"
chmod -x /opt/etc/init.d/S09named
fi
echo -e "Script finished!!\nYou can now fully use optware if you login again...\nI advice a reboot!\n"
echo -e "Do check if /opt will be mounted otherwise optware will not loaded!