Difference between revisions of "Talk:FreeLinkomatix"

From NAS-Central Buffalo - The Linkstation Wiki
Jump to: navigation, search
m
m (FreeLinkomatix)
Line 71: Line 71:
 
###############################################################################
 
###############################################################################
  
ERROR="0"
+
ERROR="1"
uname -m | grep -q ppc || ERROR="1"
+
uname -m | grep -q ppc && ERROR="0"
 +
uname -m | grep -q arm && ERROR="0"
 
uname -m | grep -q mips && ERROR="0"
 
uname -m | grep -q mips && ERROR="0"
  
 
if [ "$ERROR" == "1" ] ; then
 
if [ "$ERROR" == "1" ] ; then
 
         echo ""
 
         echo ""
         echo "FATAL: Currently, only PPC-based and MIPSel based Linkstations are supported."
+
         echo "FATAL: Currently, only PPC, ARM and MIPSel based Linkstations are supported."
 
         echo "--> Cannot continue."
 
         echo "--> Cannot continue."
 
         echo ""
 
         echo ""
Line 85: Line 86:
 
# Recognize and set processor variable
 
# Recognize and set processor variable
 
uname -m | grep -q ppc && PROCESSOR="ppc"
 
uname -m | grep -q ppc && PROCESSOR="ppc"
 +
uname -m | grep -q arm && PROCESSOR="arm"
 
uname -m | grep -q mips && PROCESSOR="mips"
 
uname -m | grep -q mips && PROCESSOR="mips"
 
# Recognize Kernel 2.4 LinkStation Flavors  
 
# Recognize Kernel 2.4 LinkStation Flavors  
Line 95: Line 97:
 
uname -r | grep "2.6" | grep kurobox | grep -q -v HG && FLAVOR="ls1"
 
uname -r | grep "2.6" | grep kurobox | grep -q -v HG && FLAVOR="ls1"
 
uname -r | grep "2.6" | grep kurobox | grep -q HG && FLAVOR="hg"
 
uname -r | grep "2.6" | grep kurobox | grep -q HG && FLAVOR="hg"
 +
uname -r | grep "2.6" | grep arm | grep -q LS-GL && FLAVOR="gl"
  
 
###############################################################################
 
###############################################################################

Revision as of 20:11, 9 December 2006

Linkstation-debdux.gif 89px-Francesco_Torniello_da_Novara_Letter_F_1517.png 100px-Francesco_Torniello_da_Novara_Letter_X_1517.png

Contents

FreeLinkomatix

#! /bin/bash
###############################################################################
#  ___                _    _       _                       _    _             #
# | __>_ _  ___  ___ | |  <_>._ _ | |_   ___ ._ _ _  ___ _| |_ <_>__          #
# | _>|  _>/ ._>/ ._>| |_ | || | || / / / . \| | | |<_> | | |  | |\ \/        #
# |_| |_|  \___.\___.|___||_||_|_||_\_\ \___/|_|_|_|<___| |_|  |_|/\_\        #
#                                                                             #
# FreeLinkomatix is a tool for the Debian version of Linux used on the        #
# Buffalo LinkStation called FreeLink. This tool is designed to automate      #
# the addition of applications, libraries, and the upgrade to a v2.6 kernel   #
# which is not provided directly in the FreeLink distribution                 #
#                                                                             #
# The script is kept on the LinkStation wiki in the talk page:                #  
#                                                                             #  
#        http://linkstationwiki.net/index.php?title=Talk:FreeLinkomatix       #
#                                                                             #
# A full Description of the Project is at:                                    #
#                                                                             #
#        http://linkstationwiki.net/index.php?title=FreeLinkomatix            #
###############################################################################

wget http://downloads.linkstationwiki.net/freelinkomatix/freelinkomatix.sh -O newest
if ! diff freelinkomatix.sh newest >> /dev/null ; then
  rm newest
  clear
  echo "There is a newer version of FreeLinkomatix available"
  echo "****************************************************"
  echo " get it from:"
  echo " "
  echo " http://downloads.linkstationwiki.net/freelinkomatix/freelinkomatix.sh"
exit 1
else
  rm newest
fi

###############################################################################
#See if we are connected to the internet and DNS works                        #
###############################################################################
clear
echo 'Ping ns.internic.net to see if you are connected to the internet'
echo ' '
echo '**This may take a few moments so be patient**'
echo ' '
if ping -q -c 10 198.41.0.4 ; then
  echo ' use <host> on a.root-servers.net'
    if ! ping -q -c 1  a.root-servers.net | grep 198.41.0.4  ; then
      echo 'adding nameserver 217.115.138.24 to /etc/resolv.conf'
      echo 'nameserver 217.115.138.24'  >> /etc/resolv.conf
    else
      grep nameserver /etc/resolv.conf
      echo 'works fine'
    fi
else
  echo 'Are you connected to the internet?'
  exit 1
fi

###############################################################################
#First do a quick check to see that you are running a PPC or MIPS based       # 
#Linkstation.  Set some enviornment variables we can use later                #
###############################################################################

ERROR="1"
uname -m | grep -q ppc && ERROR="0"
uname -m | grep -q arm && ERROR="0"
uname -m | grep -q mips && ERROR="0"

if [ "$ERROR" == "1" ] ; then
        echo ""
        echo "FATAL: Currently, only PPC, ARM and MIPSel based Linkstations are supported."
        echo "--> Cannot continue."
        echo ""
        exit 1
fi

# Recognize and set processor variable
uname -m | grep -q ppc && PROCESSOR="ppc"
uname -m | grep -q arm && PROCESSOR="arm"
uname -m | grep -q mips && PROCESSOR="mips"
# Recognize Kernel 2.4 LinkStation Flavors 
uname -r | grep -q "2.4.17_mvl21-sandpoint" && FLAVOR="ls1"
uname -r | grep -q "2.4.20_mipsel_linkstation" && FLAVOR="ls2"
uname -r | grep -q "2.4.20_mvl31-ppc_linkstation" && FLAVOR="hg"
uname -r | grep -q "2.4.17_kuro-box" && FLAVOR="kb"
uname -r | grep -q "2.4.20_mvl21" && FLAVOR="hg"
# Recognize Kernel 2.6 LinkStation Flavors 
uname -r | grep "2.6" | grep kurobox | grep -q -v HG && FLAVOR="ls1"
uname -r | grep "2.6" | grep kurobox | grep -q HG && FLAVOR="hg"
uname -r | grep "2.6" | grep arm | grep -q LS-GL && FLAVOR="gl"

###############################################################################
#Then do a quick check to make sure you have apt-get this should weed out the #
#Openlink users too                                                           #
###############################################################################

apt-get -v | grep -q dpkg || ERROR="1"
if [ "$ERROR" == "1" ] ; then
        echo ""
        echo "FATAL: Do you have apt-get installed, is this Debian(FreeLink)?"
        echo "--> Cannot continue."
        echo ""
        exit 1
fi

###############################################################################
#Let's get started then.....                                                  #
###############################################################################
clear
echo "  ___                _    _       _                       _    _      "
echo " | __>_ _  ___  ___ | |  <_>._ _ | |_   ___ ._ _ _  ___ _| |_ <_>__   "
echo " | _>|  _>/ ._>/ ._>| |_ | || | || / / / . \| | | |<_> | | |  | |\ \/ "
echo " |_| |_|  \___.\___.|___||_||_|_||_\_\ \___/|_|_|_|<___| |_|  |_|/\_\ "
echo '  '
echo "FreeLinkomatix is a tool for the Debian version of Linux used on the"
echo "Buffalo LinkStation called FreeLink. This tool is designed to automate"
echo "the addition of applications, libraries, and the upgrade to a v2.6 kernel"
echo " "
echo "The following will automatically be installed:"
echo " 1. Update apt-repositories...."
echo " 2. Install DHCP-3 client if not present" 
echo " 3. Move /home /usr /var from hda1 to hda3 and create symlinks"
echo " 4. Install Samba"
echo " 5. Troubleshooting Windows shares (samba) - guest access"
echo " 6. Install Webmin 1.3 and StressFree Solutions Tiger Webmin Theme"
echo " 7. Allow all IPs for Webmin"
echo " 8. Install SSH SSHd and the associated Webmin module"
echo " 9. Install ProFTPd and Webmin module"
echo "10. Configure the time zone and use NTPdate"
echo "11. Install the Precompiled C development environment"
echo "12. Upgrade to Kernel 2.6 using Andre's web installer (PPC Only)"
echo " "
echo -n "Proceed? (y/n)"
read -e ANSWER
if [ "$ANSWER" == "n" ] ; then
 exit 1
fi
###############################################################################
#Update apt-repositories....                                                  #
###############################################################################
clear
echo "Update apt-repositories"
echo "-----------------------"
echo " In Debian new programs can easily be added by using the APT repository"
echo " You will have to update this repository first over the internet"
echo " "
echo " "
echo "***This will be done automatically in a few moments***"
 sleep 2 
  apt-get update
# apt-get upgrade
  apt-get dist-upgrade -y 

###############################################################################
#Install DHCP-3 client if not present                                         #
###############################################################################

dpkg --purge dhcpcd 
apt-get -y  install dhcp3-client 

###############################################################################
#Move /home /usr /var  from hda1 to hda3 and create symlinks                  #
###############################################################################

if ls -l / | grep /mnt > /dev/null ; then
  echo "you already moved root directories to /mnt"
else
  clear
  echo " "
  echo "Move /home /usr /var  from hda1 to hda3 and create symlinks"
  echo "-----------------------------------------------------------"
  echo " Eventually you will probably run out of hard drive space on hda1 "
  echo " (the location of the OS, and the default location of installed programs)," 
  echo " You can free up space by moving some of the files to hda3 "
  echo " (the large partition containing the network shares) by moving:" 
  echo " "
  if [ "$PROCESSOR" == "ppc" ] ; then
    echo " /home to  /mnt/home" 
    echo " /usr  to  /mnt/usr" 
    echo " /var  to  /mnt/var" 
  fi
  if [ "$PROCESSOR" == "mips" ] ; then
    echo " /home to /mnt/hda/home"
    echo " /usr  to /mnt/hda/usr"
    echo " /var  to /mnt/hda/var"
  fi
  echo " "
  echo " And creating symlinks. You will rapidly run out of space in debian" 
  echo " unless you do something to free up space on hda1"
  echo " "
  echo " "
  sleep 2 

  DIR="$(mount | grep hda3 | awk '{print $3}')"
  cp -Rdp /home ${DIR}
  rm -R   /home
  ln -s ${DIR}/home /home
  cp -Rdp /usr ${DIR}
  rm -R   /usr
  ln -s ${DIR}/usr /usr
  cp -Rdp /var ${DIR}
  rm -R   /var
  ln -s ${DIR}/var /var
fi

###############################################################################
#Enable the Debian unstable Branch                                            #
###############################################################################
#clear
#echo " "
#echo "Get access to packages from the Debian unstable branch"
#echo "------------------------------------------------------"
#echo " It is often useful to have access to the Debian unstable branch"
#echo " because it has some interesting packages like PHP5 and rTorrent"
#echo " Using the unstable packages saves you the time you would spend"
#echo " compiling, The good thing is you don't have to change your whole"
#echo " installation to unstable you can simply use your stable or testing"
#echo " repository and just use the packages not in there from the unstable"
#echo " repository."
#echo " "
#echo " "
#echo -n "Do you want to gain access to the Debian unstable branch? (y/n)"
#read -e ANSWER 
#if [ "$ANSWER" == "y" ] ; then
# echo 'APT::Default-Release' >> /etc/apt/apt.conf
# echo '"stable"; ' >> /etc/apt/apt.conf
# echo "deb http://http.us.debian.org/debian unstable main contrib non-free " >> /etc/apt/sources.list 
# echo "deb-src http://http.us.debian.org/debian unstable main contrib non-free" >> /etc/apt/sources.list 
# apt-get update
#fi

###############################################################################
#Install Samba                                                                #
###############################################################################
clear
echo " "
echo "Install Samba"
echo "------------------------"
echo " Samba is a free software implementation of Microsoft's networking"
echo " protocol released under the GNU General Public License. As of version 3"
echo " Samba not only provides file and print services for various Microsoft"
echo " Windows clients"
echo " "
echo " "
 sleep 2 
 apt-get install samba smbfs

###############################################################################
#Troubleshooting Windows shares (samba) - guest access                        #
###############################################################################
clear
echo " "
echo "Troubleshooting Windows shares (samba) - guest access"
echo "-----------------------------------------------------"
echo " This will pick a directory  /mnt/share and change the access" 
echo " permissions to make it readable and writable to everybody."
echo " "
echo " YOU MAY NOT WANT TO DO THIS AND INSTEAD WISH TO CONFIGURE"
echo " SAMBA WITH WEBMIN OR MANUALLY EDIT /etc/samba/smb.conf"
echo " YOUR smb.conf WILL BE MOVED TO smb.conf.backup"
echo " "
echo -n "Do you want to enable guest access for Samba? (y/n)"
read -e ANSWER 

if [ "$ANSWER" == "y" ] ; then
  echo " "
  echo -n "What is your windows workgroup name ie: MSHOME or WORKGROUP? (Default will be WORKGROUP)" 
  read -e WORKGROUP
  if [ "$WORKGROUP" == "" ] ; then
     $WORKGROUP = "WORKGROUP" 
  fi 
  echo " "
  echo -n "What do you want the name of your linkstation to be on the network (Default will be LinkStation)" 
  read -e LINKSTATION
  if [ "$LINKSTATION" == "" ] ; then
     $LINKSTATION = "LinkStation"
  fi 
  hostname $LINKSTATION
  if [ "$PROCESSOR" == "ppc" ] ; then
   mkdir /mnt/share
   chmod 777 /mnt/share
   mv -i /etc/samba/smb.conf /etc/samba/smb.conf.backup
   echo '' >> /etc/samba/smb.conf
   echo '[global] ' >> /etc/samba/smb.conf
   echo ' security = share ' >> /etc/samba/smb.conf
   echo ' workgroup =' $WORKGROUP >> /etc/samba/smb.conf
   echo ' create mode = 777 ' >> /etc/samba/smb.conf
   echo ' directory mode = 777 ' >> /etc/samba/smb.conf
   echo ' ' >> /etc/samba/smb.conf
   echo '[share] ' >> /etc/samba/smb.conf
   echo ' comment = LinkStation Share ' >> /etc/samba/smb.conf
   echo ' path = /mnt/share ' >> /etc/samba/smb.conf
   echo ' read only = no ' >> /etc/samba/smb.conf
   echo ' public = yes ' >> /etc/samba/smb.conf
   /etc/rc.d/init.d/samba restart
  fi
  if [ "$PROCESSOR" == "mips" ] ; then
   mkdir /mnt/hda/share
   chmod 777 /mnt/hda/share
   mv -i /etc/samba/smb.conf /etc/samba/smb.conf.backup
   echo '' >> /etc/samba/smb.conf
   echo '[global] ' >> /etc/samba/smb.conf
   echo ' security = share ' >> /etc/samba/smb.conf
   echo ' workgroup =' $WORKGROUP >> /etc/samba/smb.conf
   echo ' create mode = 777 ' >> /etc/samba/smb.conf
   echo ' directory mode = 777 ' >> /etc/samba/smb.conf
   echo ' ' >> /etc/samba/smb.conf
   echo '[share] ' >> /etc/samba/smb.conf
   echo ' comment = LinkStation Share ' >> /etc/samba/smb.conf
   echo ' path = /mnt/hda/share ' >> /etc/samba/smb.conf
   echo ' read only = no ' >> /etc/samba/smb.conf
   echo ' public = yes ' >> /etc/samba/smb.conf
   /etc/rc.d/init.d/samba restart
  fi
fi

###############################################################################
#Install Webmin 1.3 and StressFree Solutions Tiger Webmin Theme               #
###############################################################################
clear
echo " "
echo "Install Webmin 1.3 and StressFree Solutions Tiger Webmin Theme"
echo "------------------------------------------------"
echo " Webmin is a system configuration tool for Unix-like systems. It"
echo " has a web-based interface (GUI) desktop environment independent, for"
echo " configuring some of the internals of the operating system."
echo " Webmin is largely based on Perl, and is running as its own process"
echo " and webserver. It usually uses TCP port 10000 for communicating "
echo "  "
echo " The Tiger webmin theme features a completely new graphical look," 
echo " high colour icons, dropdown menus and an AJAX search tool for "
echo " locating Webmin modules quickly. It has been tested in Firefox," 
echo " Safari and Internet Explorer."
echo " "
echo "     Find out more here: http://www.stress-free.co.nz/webmin-theme"
echo " "
 sleep 2 

  apt-get install webmin webmin-core webmin-cpan webmin-inetd webmin-logrotate webmin-firewall 
  apt-get install webmin-samba 
  apt-get install perl  libnet-ssleay-perl  openssl libauthen-pam-perl libpam-runtime libio-pty-perl
  wget --tries=3 --dns-cache=off --dns-timeout=8 --connect-timeout=8 --random-wait -c  http://mesh.dl.sourceforge.net/sourceforge/webadmin/webmin_1.300_all.deb 
  wget --tries=3 --dns-cache=off --dns-timeout=8 --connect-timeout=8 --random-wait -c  http://downloads.linkstationwiki.net/freelinkomatix/webmin_1.300_all.deb 
  dpkg -i webmin_1.300_all.deb 
  wget --tries=3 --dns-cache=off --dns-timeout=8 --connect-timeout=8 --random-wait -c http://www.stress-free.co.nz/files/theme-stressfree.tar.gz
  wget --tries=3 --dns-cache=off --dns-timeout=8 --connect-timeout=8 --random-wait -c  http://downloads.linkstationwiki.net/freelinkomatix/theme-stressfree.tar.gz
  tar -C /usr/share/webmin -xvzf theme-stressfree.tar.gz 
  sed -e 's@^preroot.*$@preroot=theme-stressfree@ ; s@^allow.*$@@' < /etc/webmin/miniserv.conf > /tmp/file 
  cat /tmp/file > /etc/webmin/miniserv.conf 
  sed -e 's@^theme.*$@theme=theme-stressfree@' < /etc/webmin/config > /tmp/file 
  cat /tmp/file > /etc/webmin/config 
  /etc/webmin/restart

###############################################################################
# Allow all IPs for Webmin                                                    #
###############################################################################
clear
echo " "
echo "Allow all IP addresses for Webmin"
echo "---------------------------------"
echo " By default Webmin will only allow 127.0.0.1 (localhost) to login."   
echo " You will have to change  /etc/webmin/miniserv.conf to allow at"  
echo " least one external computer access to log into webmin. "
echo " "
echo " This script will allow any external IP to login.  It's a big security" 
echo " hole though so after you login to webmin,  change the allowed IP"
echo " addresses by going to:"
echo " "
echo "            Webmin Configuration --> IP Access Control" 
echo " "
echo " OR you can just edit /etc/webmin/miniserv.conf and change the line:"
echo " "
echo "                       allow= 127.0.0.1"
echo " "
echo "    to what you need and answer no to the following prompt:"
echo " "
 sleep 2 

# cat /etc/webmin/miniserv.conf | grep -v allow=  > /tmp/file
# cat /tmp/file > /etc/webmin/miniserv.conf
# /etc/webmin/stop
# sleep 2 
# /etc/webmin/start

###############################################################################
#Install SSH SSHd and the associated Webmin module                            #
###############################################################################
clear
echo " "
echo "Install SSH SSHd and the associated Webmin module"
echo "-------------------------------------------------"
echo " SSH is a set of standards and an associated network protocol" 
echo " that allows establishing a secure channel between a local and"
echo " a remote computer. SSH is typically used to log into a remote"
echo " machine and execute commands, but it also supports tunneling,"
echo " forwarding arbitrary TCP ports and X11 connections; it can"
echo " transfer files using the associated SFTP or SCP protocols."
echo " An SSH server (SSHd), by default, listens on the standard" 
echo " TCP port 22."
echo " "
echo " By using SSHd on the LinkStation and a client such as PuTTY"
echo " you can create a secure replacement for Telnet, you can remove"
echo " Telnetd at a later time when you are sure that SSHd works with"
echo " the command:"
echo " "
echo "                rm /etc/rc2.d/S05utelnetd"
echo " "
 sleep 2 
  apt-get install ssh webmin-sshd



##############################################################################
#Install ProFTPd and Webmin module                                           #
##############################################################################
clear
echo " "
echo "Install ProFTPd"
echo "---------------"
echo " ProFTPd is an FTP server. It is stable and secure when configured"
echo " properly.  This will also install the Webmin module that you can"
echo " use to configure ProFTPd from within Webmin"
echo " "
 sleep 2 
 apt-get install webmin-proftpd proftpd proftpd-common  proftpd-doc



###############################################################################
#Configure the time zone and use NTPdate                                      #
###############################################################################
clear
echo " "
echo "Configure the time zone and use NTPdate"
echo "---------------------------------------"
echo " The ntpd (Network Time Protocol daemon) program is an operating"
echo " system daemon which sets and maintains the system time of day in"
echo " synchronism with time servers".
echo " First you will have to configure your time zone (tzconfig)" 
echo " This script with also make it a cron job to resynchronize"
echo " on an hourly basis"
echo " "
echo " "
 sleep 2 
 tzconfig
 apt-get install ntp ntp-simple ntp-server ntpdate
 /etc/init.d/ntpdate restart
 echo '17 *    * * *   root    /etc/init.d/ntpdate restart' >> /etc/crontab


###############################################################################
#Install the Precompiled C development environment                            #
###############################################################################
if  gcc --help | grep options  > /dev/null ; then
  echo "you already installed a C compiler"
else
  clear
  echo " "
  echo "Install Precompiled C development environment"
  echo "---------------------------------------------"
  echo " The LinkStation lacks virtually all necessary development tools" 
  echo " such as binutils or gcc, making it quite difficult to natively compile"
  echo " programs. This provides a complete package of precompiled development"
  echo " tools and related libraries." 
  echo " "
  echo " These tools come from http://www.linkstationwiki.net"
  echo " "
   sleep 2 
     if [ "$PROCESSOR" == "ppc" ] ; then
         mkdir tmpdevel
         cd tmpdevel
         wget http://downloads.linkstationwiki.net/development_tools/ppc-tools-2_1.tgz 
         mkdir devtools
         cd devtools
         tar xzvf ../ppc-tools-2_1.tgz
         ./install.sh
         if [ "$FLAVOR" == "hg" ] ; then
            wget http://downloads.linkstationwiki.net/kernel_headers/kernel-headers-2.4.20_hglan_htgl-2.0.tgz
            tar -C / -xvzf kernel-headers-2.4.20_hglan_htgl-2.0.tgz
         fi    
      fi
      if [ "$PROCESSOR" == "mips" ] ; then
         mkdir tmpdevel
         cd tmpdevel
         wget http://downloads.linkstationwiki.net/development_tools/mipsel-tools-2_1.tgz
         mkdir devtools
         cd devtools
         tar xzvf ../mipsel-tools-2_1.tgz
         ./install.sh
      fi
  cd ..
  cd ..
  rm -r tmpdevel
fi

###############################################################################
#        Upgrade to Kernel 2.6 using Andre's web installer                    #
#                       System will REBOOT after this                         #
#               This should always be the last action of this script          #
###############################################################################
if [ "$PROCESSOR" == "ppc" ] ; then
clear
echo " "
echo "Upgrade to Kernel 2.6 using Andre's web installer"
echo "-------------------------------------------------"
echo " Upgrade from Buffalo's outdated kernel 2.4, currently included"
echo " in the Debian (FreeLink) release, on LS1, HG, HS, KuroBox, and"
echo " KuroHG. The 2.6 Kernel addresses virtually all shortcomings of"
echo " the LS stock kernels: Very good USB support, NFS, routing, quotas"
echo " lots more."
echo " The 550+ modules are optional -- you could delete them if you're"
echo " short of disk space, as the "LS core functions", support for mass"
echo " storage devices and printing, have been compiled into the kernel"
echo " "
echo " Find out more at: http://hvkls.dyndns.org/downloads/documentation/"
echo " "
echo "       *****YOU WILL HAVE TO REBOOT AFTER THIS*****"
echo " "
 sleep 2 
  wget --tries=3 --dns-cache=off --dns-timeout=8 --connect-timeout=8 --random-wait -c http://downloads.linkstationwiki.net/mirrors/hvkls.dyndns.org/latest-webinstaller.tar.gz
  wget --tries=3 --dns-cache=off --dns-timeout=8 --connect-timeout=8 --random-wait -c http://hvkls.dyndns.org/downloads/latest-webinstaller.tar.gz
  tar -C / -xvzf latest-webinstaller.tar.gz
  /usr/local/sbin/webinstaller-kernelinst.sh
fi

Post Install Script

#! /bin/bash
###############################################################################
#  ___                _    _       _                       _    _             #
# | __>_ _  ___  ___ | |  <_>._ _ | |_   ___ ._ _ _  ___ _| |_ <_>__          #
# | _>|  _>/ ._>/ ._>| |_ | || | || / / / . \| | | |<_> | | |  | |\ \/        #
# |_| |_|  \___.\___.|___||_||_|_||_\_\ \___/|_|_|_|<___| |_|  |_|/\_\        #
#                                                                             #
# FreeLinkomatix Post install script                                          #
#                                                                             #
# This script is ment to be run after the upgrade to a v2.6 kernel            #
# It will install additional apps some of which are dependant on kernel v2.6  #
###############################################################################


wget http://downloads.linkstationwiki.net/freelinkomatix/postinstall.sh -O newest
if ! diff postinstall.sh newest >> /dev/null ; then
  rm newest
  clear
  echo "There is a newer version of the Post Install Script available"
  echo "*************************************************************"
  echo " get it from:"
  echo " "
  echo " http://downloads.linkstationwiki.net/freelinkomatix/postinstall.sh"
exit 1
else
  rm newest
fi

clear
echo "FreeLinkomatix Post install script: "
echo " "
echo "This script is ment to be run after the upgrade to a v2.6 kernel"
echo "It will install additional apps some of which are dependant on kernel v2.6"
echo " "
echo "Operating System: " `uname -o`
echo "Kernel Release:   " `uname -r`
echo "Version:          " `uname -v`
echo "Processor:        " `uname -m`
echo " "
echo " 1. Add Kernel Network File System (NFS) and the Webmin Exports module"
echo " 2. Install Rsync and download Webmin module rsyncmin"
echo " 3. Add USB Automounting and CUPS Printer Support"
echo " 4. Macintosh Specific Netatalk and Howl Zeroconf DNS discovery service"
echo " 5. Add Firefly (mt-daapd) Media Server "
echo " 6. Install ccxstream XBMSP protocol for XBox Media Center "
echo " 7. KAID - XLink Kai online gaming for Xbox, 360, PS2 and PSP"
echo " 8. LAMP and Gallery2 Photo gallery "
echo " "
echo -n "Do you want to add additional apps to your Linkstation? (y/n)"
read -e ANSWER
if [ "$ANSWER" == "n" ] ; then
exit 1
fi

###############################################################################
#First do a quick check to see that you are running a kernel 2.6 on your      #
#Linkstation and set some variables                                           #
###############################################################################

ERROR="0"
kernelversion | grep -q "2.6" || ERROR="1"
uname -m | grep -q ppc || ERROR="1"

if [ "$ERROR" == "1" ] ; then
        echo ""
        echo "FATAL: At present only PPC-based Linkstations running kernel v2.6 are supported."
        echo "--> Cannot continue."
        echo ""
        exit 1
fi
# Recognize Kernel 2.6 LinkStation Flavors 
uname -r | grep "2.6" | grep kurobox | grep -q -v HG && FLAVOR="ls1"
uname -r | grep "2.6" | grep kurobox | grep -q HG && FLAVOR="hg"


###############################################################################
#Then do a quick check to make sure you have apt-get this should weed out the #
#Openlink users too                                                           #
###############################################################################

apt-get -v | grep -q dpkg || ERROR="1"
if [ "$ERROR" == "1" ] ; then
        echo ""
        echo "FATAL: Do you have apt-get installed, is this Debian(FreeLink)?"
        echo "--> Cannot continue."
        echo ""
        exit 1
fi

###############################################################################
#Install Rsync and download Webmin module rsyncmin                            #
###############################################################################
clear
echo " "
echo "Install Rsync and download Webmin module rsyncmin"
echo "-------------------------------------------------"
echo " rsync is a free software computer program for Unix systems which"
echo " synchronizes files and directories from one location to another" 
echo " while minimizing data transfer using delta encoding when" 
echo " appropriate. An important feature of rsync not found in most" 
echo " similar programs/protocols is that the mirroring takes place" 
echo " with only one transmission in each direction. rsync can copy" 
echo " or display directory contents and copy files, optionally using"
echo " compression and recursion."
echo " "
echo " This script will also download the webmin module Rsyncmin from"
echo " http://opensource.digisec.de/ which configures rsyncd.conf "
echo " "
echo "                        rsyncmin.wbm"
echo " "
echo " You will have to install the Rsyncmin module within Webmin yourself"
echo " "
echo " "
echo -n "Do you want to Install Rsync? (y/n)"
read -e ANSWER
if [ "$ANSWER" == "y" ] ; then
  if grep -F rsync /etc/freelinkomatix_installed ; then
    clear
    echo "You already installed this with the FreeLinkomatix Post-install Script"
    sleep 2 
  else
    echo "rsync" >> /etc/freelinkomatix_installed  
    apt-get install rsync
wget --tries=3 --dns-cache=off --dns-timeout=8 --connect-timeout=8 --random-wait -c  http://opensource.digisec.de/webmin/rsyncmin.wbm
wget --tries=3 --dns-cache=off --dns-timeout=8 --connect-timeout=8 --random-wait -c http://downloads.linkstationwiki.net/freelinkomatix/rsyncmin.wbm 
 fi
fi

###############################################################################
#Add USB Automounting and CUPS Printer Support                                #
###############################################################################
clear
echo " "
echo "Add USB Automounting and CUPS Printer Support"
echo "---------------------------------------------"
echo " This will add USB Drive automounting and mount USB"
echo " drives to /media/usb0,1,2,3 etc.  symbolic links"
echo " in /mnt/share will also be created usb0,usb1,usb2,usb3"
echo " so that they will be accessable via your samba share"
echo " Also CUPS (Common Unix Printing System) Support will"
echo " be added. You can configure this in Webmin"
echo " "
echo "  Webmin --> Hardware -->Printer Adminstration -->Module Config -->"
echo "  -->Printer Configuration Style -->[CUPS]"
echo " "
echo " "
echo -n "Do you want to add USB Automounting and CUPS Printer Support? (y/n)"
read -e ANSWER
if [ "$ANSWER" == "y" ] ; then
  if grep -F usbcups /etc/freelinkomatix_installed ; then
    clear
    echo "You already installed this with the FreeLinkomatix Post-install Script"
    sleep 2
  else
    echo "usbcups" >> /etc/freelinkomatix_installed  
    apt-get remove hotplug 
    apt-get install usbmount
    sed -e 's@^FILESYSTEMS.*$@FILESYSTEMS="ext3 ext2 vfat"@ ; s@^MOUNTOPTIONS.*$@MOUNTOPTIONS="noexec,nodev,noatime"@ ; s@^FS_MOUNTOPTIONS.*$@FS_MOUNTOPTIONS="-fstype=vfat,umask=000"@' < /etc/usbmount/usbmount.conf > /tmp/file
    cat /tmp/file > /etc/usbmount/usbmount.conf
    ln -s /media/usb0/ /mnt/share
    ln -s /media/usb1/ /mnt/share
    ln -s /media/usb2/ /mnt/share
    ln -s /media/usb3/ /mnt/share
    apt-get install cupsys cupsys-bsd
  fi
fi

###############################################################################
#Add Kernel Network File System (NFS) and the Webmin Exports module           #
###############################################################################
clear
echo " "
echo "Add Kernel Network File System (NFS) and the Webmin Exports module"
echo "-----------------------------------------------------------------"
echo " Network File System (NFS) is a protocol originally developed"
echo " by Sun Microsystems in 1984, as a distributed file system which"
echo " allows a computer to access files over a network as easily as if"
echo " they were on its local disks. NFS is one of many protocols built"
echo " on the Open Network Computing Remote Procedure Call system"
echo " This script will install Kernel NFS server support, it will" 
echo " require Kernel 2.6 to have been installed. Also the NFS exports"
echo " control module for webmin will be installed allowing webmin"
echo " to manage NFS exports."
echo "  " 
echo " After you set up NFS exports with webmin or manually, you "
echo " will have to either restart your system or restart the NFS"
echo " daemon with" 
echo " "
echo "               /etc/init.d/nfs-kernel-server start"
echo " "
echo " "
echo -n "Do you want to add Kernel NFS and Webmin Exports? (y/n)"
read -e ANSWER
if [ "$ANSWER" == "y" ] ; then
  if grep -F kernelnfs /etc/freelinkomatix_installed ; then
    clear
    echo "You already installed this with the FreeLinkomatix Post-install Script"
    sleep 2
  else
    echo "kernelnfs" >> /etc/freelinkomatix_installed  
    apt-get install nfs-kernel-server webmin-exports 
  fi
fi
###############################################################################
#Macintosh Specific Netatalk and Howl Zeroconf DNS discovery service          #
###############################################################################
clear
echo " "
echo "Macintosh Specific Netatalk and Howl Zeroconf DNS discovery service"
echo "-------------------------------------------------------------------"
echo " Protocols that provide Native Mac OS X compatibility"
echo " Netatalk is an open-source implementation of the AppleTalk suite"
echo " of protocols. It allows Unix-like operating systems to serve as "
echo " file, print and time servers for Macintosh computers."
echo " Howl -a multicast DNS service discovery is an open source"
echo " implementation of the Zeroconf specification a set of techniques"
echo " that automatically create a usable IP this allows unknowledgeable"
echo " users to connect computers, networked  printers, and other items"
echo " together and expect them to work. "
echo " Zeroconf was pioneered by Apple Computer in the company's move"
echo " from AppleTalk to IP."
echo " Binaries from: http://hvkls.dyndns.org/downloads/documentation/"
echo " "
echo " This will also get the third party webmin netatalk module"
echo " from Matthew Keller (kellermg@potsdam.edu) you will have to "
echo " install it yourself within webmin" 
echo " "
echo -n "Native Mac OS X compatibility with NetaTalk and Howl? (y/n)"
read -e ANSWER
if [ "$ANSWER" == "y" ] ; then
#########################
#INSTALL NETATALK FIRST #
######################### 
  if grep -F netatalkhowl /etc/freelinkomatix_installed ; then
    clear
    echo "You already installed this with the FreeLinkomatix Post-install Script"
    sleep 2
  else
    echo "netatalkhowl" >> /etc/freelinkomatix_installed  
    apt-get install cracklib-runtime libpam-cracklib netatalk 
    /etc/init.d/netatalk stop 
    wget --tries=3 --dns-cache=off --dns-timeout=8 --connect-timeout=8 --random-wait -c http://downloads.linkstationwiki.net/powerpc-hdhlan/binaries-that-need-kernel2.6/netatalk_2.0.3-4_powerpc.deb
    wget --tries=3 --dns-cache=off --dns-timeout=8 --connect-timeout=8 --random-wait -c http://hvkls.dyndns.org/downloads/netatalk_2.0.3-4_powerpc.deb

    dpkg -i netatalk_2.0.3-4_powerpc.deb 
    rm /etc/default/netatalk
    echo 'AFPD_MAX_CLIENTS=10 ' >> /etc/default/netatalk
    echo 'ATALK_NAME=`/bin/hostname` ' >> /etc/default/netatalk
    echo "ATALK_MAC_CHARSET='MAC_ROMAN' " >> /etc/default/netatalk
    echo "ATALK_UNIX_CHARSET='LOCALE' " >> /etc/default/netatalk
    echo 'AFPD_UAMLIST="-U uams_dhx.so" ' >> /etc/default/netatalk  
    echo 'AFPD_GUEST=nobody ' >> /etc/default/netatalk
    echo 'ATALKD_RUN=no ' >> /etc/default/netatalk
    echo 'PAPD_RUN=no ' >> /etc/default/netatalk
    echo 'CNID_METAD_RUN=yes ' >> /etc/default/netatalk
    echo 'AFPD_RUN=yes ' >> /etc/default/netatalk
    echo 'TIMELORD_RUN=no ' >> /etc/default/netatalk
    echo 'A2BOOT_RUN=no ' >> /etc/default/netatalk
    echo 'ATALK_BGROUND=yes ' >> /etc/default/netatalk
    echo 'export ATALK_MAC_CHARSET ' >> /etc/default/netatalk
    echo 'export ATALK_UNIX_CHARSET ' >> /etc/default/netatalk
    rm /etc/netatalk/afpd.conf
    echo '- -transall -uamlist uams_dhx.so -nosavepassword -noddp  ' >> /etc/netatalk/afpd.conf
    echo '/mnt/shared "shared" allow:linkstation ' >> /etc/netatalk/AppleVolumes.default

    wget --tries=3 --dns-cache=off --dns-timeout=8 --connect-timeout=8 --random-wait -c http://mattwork.potsdam.edu/projects/netatalk/webmin_module/netatalk.wbm
    wget --tries=3 --dns-cache=off --dns-timeout=8 --connect-timeout=8 --random-wait -c http://downloads.linkstationwiki.net/freelinkomatix/netatalk.wbm

    ####################
    #THEN INSTALL HOWL #
    ####################
    wget --tries=3 --dns-cache=off --dns-timeout=8 --connect-timeout=8 --random-wait -c http://downloads.linkstationwiki.net/powerpc-hdhlan/binaries-that-need-kernel2.6/howl_1.0.0-binaries-ppc.tar.gz
    wget --tries=3 --dns-cache=off --dns-timeout=8 --connect-timeout=8 --random-wait -c http://hvkls.dyndns.org/downloads/howl_1.0.0-binaries-ppc.tar.gz
    tar -C / -xvzf howl_1.0.0-binaries-ppc.tar.gz
    #will have to alter /etc/howl/mDNSResponder.conf file to fit what we make and wget it in the future....
    /etc/init.d/howl start
    fi
fi
###############################################################################
#Add Firefly (mt-daapd) Media Server                                          #
###############################################################################
clear
echo " "
echo "Add Firefly (mt-daapd) Media Server"
echo "-----------------------------------"
echo " Firefly Media Server (formerly mt-daapd) is an open-source media"
echo " server (or daemon) for the Roku SoundBridge and iTunes. It serves"
echo " media files using Roku Server Protocol (RSP) and Digital Audio"
echo " Access Protocol (DAAP).Netatalk is an open-source implementation"
echo " of the AppleTalk suite"
echo " "
echo " Point your web browser to http://linkstation:3689 and login with: "
echo "                user:mt-daapd"
echo "                password:mt-daapd "
echo " "
echo " and set up the configuration in the web interface "
echo " "
echo " "
echo " Binaries from: http://hvkls.dyndns.org/downloads/documentation/"
echo " "
echo -n "Add Firefly (mt-daapd) Media Server? (y/n)"
read -e ANSWER
if [ "$ANSWER" == "y" ] ; then
  if grep -F firefly /etc/freelinkomatix_installed ; then
    clear
    echo "You already installed this with the FreeLinkomatix Post-install Script"
    sleep 2
  else
    echo "firefly" >> /etc/freelinkomatix_installed  
    apt-get install libid3tag0 
    wget --tries=3 --dns-cache=off --dns-timeout=8 --connect-timeout=8 --random-wait -c http://downloads.linkstationwiki.net/powerpc-hdhlan/binaries-that-need-kernel2.6/mtdaapd_0.2.4-binaries-ppc.tar.gz
    wget --tries=3 --dns-cache=off --dns-timeout=8 --connect-timeout=8 --random-wait -c http://hvkls.dyndns.org/downloads/mtdaapd_0.2.4-binaries-ppc.tar.gz
    tar -C / -xvzf mtdaapd_0.2.4-binaries-ppc.tar.gz 
    #wget http://puzzle.dl.sourceforge.net/sourceforge/mt-daapd/mt-daapd-0.2.4.tar.gz
    #tar -xvzf mt-daapd-0.2.4.tar.gz
    #cd mt-daapd-0.2.4
    #./configure --prefix=/usr/local --enable-browse --enable-query --enable-mdns --with-id3tag=/usr/local --sysconfdir=/etc 
    #make
    #make install
    #mkdir /etc/mt-daapd
    #cp contrib/mt-daapd.* /etc/mt-daapd/
    mv /etc/mt-daapd.SAMPLE /etc/mt-daapd 
    /etc/init.d/mt-daapd start
  fi
fi


###############################################################################
#Install ccxstream XBMSP protocol for XBox Media Center                       #
###############################################################################
clear
echo " "
echo "Install ccxstream XBMSP protocol for XBox Media Center"
echo "------------------------------------------------------"
echo " XBMSP (XBox Media Stream Protocol) or XBMS for short is another way"
echo " of sharing media, supposedy it is faster than Samba. It is capable"
echo " of streaming all types of media and gives the option of sharing"
echo " individual folders or entire drives. XBMS is very bandwith efficient."
echo " Once you install ccXStream on your LinkStation all you have to do"
echo " is configure your XMBC to use the media share."
echo " ccxstream is a part of the XBox Media Center Project"
echo "http://www.xboxmediacenter.com/"
echo " "
echo " It will share /mnt/share by default"
echo " "
echo -n "Do you want to install ccxstream - XBMSP? (y/n)"
read -e ANSWER 
if [ "$ANSWER" == "y" ] ; then
  if grep -F ccxstream /etc/freelinkomatix_installed ; then
    clear
    echo "You already installed this with the FreeLinkomatix Post-install Script"
    sleep 2
  else
    echo "ccxstream" >> /etc/freelinkomatix_installed  
    wget --tries=3 --dns-cache=off --dns-timeout=8 --connect-timeout=8 --random-wait -c  http://osdn.dl.sourceforge.net/sourceforge/xbplayer/ccxstream-1.0.15.tar.gz
    wget --tries=3 --dns-cache=off --dns-timeout=8 --connect-timeout=8 --random-wait -c http://downloads.linkstationwiki.net/freelinkomatix/ccxstream-1.0.15.tar.gz
    tar -xvzf ccxstream-1.0.15.tar.gz
    cd ccxstream-1.0.15
    make
    cp ccxstream /usr/local/bin
    cp ccxtest /usr/local/bin
    mkdir /usr/doc/ccxstream
    cp  COPYRIGHT /usr/doc/ccxstream/
    cp  ChangeLog /usr/doc/ccxstream/
    cp  PORTING /usr/doc/ccxstream/
    cp  README /usr/doc/ccxstream/
    cp  TODO /usr/doc/ccxstream/
    cp  xbmsp-xml.txt /usr/doc/ccxstream/
    cp  xbmsp.txt /usr/doc/ccxstream/
    echo '#! /bin/sh' >> /etc/init.d/ccxstream
    echo '#' >> /etc/init.d/ccxstream
    echo '# CCXSTREAM - see /usr/doc/ccxstream/README for options' >> /etc/init.d/ccxstream
    echo '#' >> /etc/init.d/ccxstream
    echo '# Set SHAREDIR to directory you want to share' >> /etc/init.d/ccxstream
    echo '# Set OPTIONS to other command line options you want' >> /etc/init.d/ccxstream
    echo 'SHAREDIR=/mnt/share' >> /etc/init.d/ccxstream
    echo 'OPTIONS="-f -F /var/run/ccxstream.pid"' >> /etc/init.d/ccxstream
    echo '#' >> /etc/init.d/ccxstream
    echo '  if [ -n "`pidof ccxstream`" ] ; then' >> /etc/init.d/ccxstream
    echo '     killall ccxstream 2>/dev/null' >> /etc/init.d/ccxstream
    echo '  fi' >> /etc/init.d/ccxstream
    echo '  sleep 2' >> /etc/init.d/ccxstream
    echo '  /usr/local/bin/ccxstream -r $SHAREDIR  $OPTIONS' >> /etc/init.d/ccxstream
    chmod a+x /etc/init.d/ccxstream
    # cd /etc/rc.d/rc2.d
    # ln -s ../init.d/ccxstream S75ccxstream
    # cd ../rc0.d
    # ln -s ../init.d/ccxstream K02ccxstream
    # cd ../rc6.d
    # ln -s ../init.d/ccxstream K02ccxstream
    # /etc/init.d/ccxstream
  fi
fi
###############################################################################
#KAID - XLink Kai online gaming for Xbox, 360, PS2 and PSP                    #
###############################################################################
clear
echo " "
echo "KAID - XLink Kai online gaming for Xbox, 360, PS2 and PSP"
echo "---------------------------------------------------------"
echo " Xlink Kai: Evolution VII lets you connect with other console users"
echo " around the world, and play online games for free. XLink Kai: Evo VII"
echo " tricks your console into thinking that the other users it is connecting"
echo " to over the Internet, are actually part of a Local Area Network. This"
echo " is the basis of system-link gaming, where friends would gather around"
echo " in the same house and play over 2 or more consoles. With XLink Kai: Evo VII"
echo " you now have the option to test your skills out with anybody in the world."
echo " you will need a XTAG (username) and Password for this service."
echo " Xlink Kai is developed by Team Xlink - http://www.teamxlink.co.uk/"
echo " "
echo -n "Do you want to install X-link KAID? (y/n)"
read -e ANSWER 
if [ "$ANSWER" == "y" ] ; then
  if grep -F xlinkkai /etc/freelinkomatix_installed ; then
    clear
    echo "You already installed this with the FreeLinkomatix Post-install Script"
    sleep 2
  else
    echo "xlinkkai" >> /etc/freelinkomatix_installed  
    echo -n "Enter your Xlink username:"
    read -e USERNAME
    echo -n "Enter your password:"
    read -e PASSWORD
    wget --tries=3 --dns-cache=off --dns-timeout=8 --connect-timeout=8 --random-wait -c http://www.teamxlink.co.uk/binary/kaid-ppc-static-libc-2.3.zip
    wget --tries=3 --dns-cache=off --dns-timeout=8 --connect-timeout=8 --random-wait -c http://downloads.linkstationwiki.net/freelinkomatix/kaid-ppc-static-libc-2.3.zip
    apt-get install unzip
    unzip kaid-*
    mv kaid-static* kaid
    mv kaid /usr/local/sbin
    chmod 755 /usr/local/sbin/kaid
    wget http://downloads.linkstationwiki.net/freelinkomatix/kaid
    mv kaid /etc/init.d/kaid
    chmod 755 /etc/init.d/kaid  
    # ln -s /etc/init.d/kaid /etc/rc.d/rc0.d/K99kaid
    # ln -s /etc/init.d/kaid /etc/rc.d/rc2.d/S99kaid
    # ln -s /etc/init.d/kaid /etc/rc.d/rc6.d/K99kaid
    wget http://downloads.linkstationwiki.net/freelinkomatix/kaid.conf
    echo 'Username = ' $USERNAME  >> kaid.conf
    echo 'Password = ' $PASSWORD  >> kaid.conf
    mv kaid.conf /etc/kaid.conf
  fi
fi




###############################################################################
#LAMP and Gallery2 Photo gallery                                              #
###############################################################################
clear
echo "LAMP and Gallery2 Photo gallery"
echo "-------------------------------"
echo " LAMP (or L.A.M.P.) refers to a set of free software programs commonly"
echo " used together to run dynamic Web sites or servers:"
echo "  * Linux, the operating system"
echo "  * Apache, the Web server"
echo "  * MySQL, the database management system (or database server)"
echo "  * PHP scripting/programming language" 
echo " "
echo " Gallery2"
echo " The Gallery Project is an open source PHP project enabling simple"
echo " management and publication of photographs and other digital media"
echo " through a PHP-enabled Apache, IIS or Zeus web server. Photo management"
echo " includes automatic thumbnails, resizing, rotation, and flipping, among"
echo " other things. Albums can be organized hierarchically and individually"
echo " controlled by administrators or privileged users. "
echo " "
echo -n "Do you want to install LAMP? (y/n)"
read -e ANSWER 
if [ "$ANSWER" == "y" ] ; then
  if grep -F lamp /etc/freelinkomatix_installed ; then
    clear
    echo "You already installed this with the FreeLinkomatix Post-install Script"
    sleep 2
  else
    echo "lamp" >> /etc/freelinkomatix_installed  
    apt-get install apache apache-common 
    apt-get install mysql-server php4-mysql libapache-mod-auth-mysql
  fi
fi
echo -n "Do you want to install Gallery2? (y/n)"
read -e ANSWER 
if [ "$ANSWER" == "y" ] ; then
  if grep -F gallery /etc/freelinkomatix_installed ; then
    clear
    echo "You already installed this with the FreeLinkomatix Post-install Script"
    sleep 2
  else
    echo "gallery" >> /etc/freelinkomatix_installed  
    apt-get install apache debconf  mysql-client  netpbm  php4  php4-mysql  wwwconfig-common 
    wget http://ftp.debian.org/debian/pool/main/g/gallery2/gallery2_2.1.2-1_all.deb
    dpkg -i gallery2_2.1.2-1_all.deb 
  fi
fi