#! /bin/bash
#script by huanix 11/8/2008
function install() {
clear
echo "You obviously don't owe me anything, but donations legitimize the time i spend on the computer to my wife. Even \$2 would go a long way toward positive marital relations -- You can paypal me at huanix@gmail.com -- as a matter of fact, you COULD do that while wine is compiling!! (hit enter)";
read q
uname -a
cat /etc/issue
echo "I'm going to begin by downloading the wine dependencies, then the wine source. After that I'll try to patch it and build it from source. All you have to do is be patient; on a modern system it should take slightly less than an hour to compile (add more time to download dependencies). In that time you can head to paypal and make a tiny contribution (paypal me: huanix@gmail.com)... i promise- my wife thinks i'm doing something worthwhile when people contribute!!! Hit Enter when you're ready - or Ctrl-C to get out of here."
read p

echo 'Are you installing on a 64bit machine? (y/n)' 
read k
if [ "$k" = "y" ]; then
sudo apt-get install libxcomposite-dev gcc-4.2-multilib
mkdir -p wine-1.1.6/lib32
ln -s /usr/lib32/libX11.so.6 wine-1.1.6/lib32/libX11.so
ln -s /usr/lib32/libXext.so.6 wine-1.1.6/lib32/libXext.so
ln -s /usr/lib32/libfreetype.so.6 wine-1.1.6/lib32/libfreetype.so
ln -s /usr/lib32/libfontconfig.so.1 wine-1.1.6/lib32/libfontconfig.so
ln -s /usr/lib32/libGL.so.1 wine-1.1.6/lib32/libGL.so
ln -s /usr/lib32/libGLU.so.1 wine-1.1.6/lib32/libGLU.so
ln -s /usr/lib32/libXrender.so.1 wine-1.1.6/lib32/libXrender.so
ln -s /usr/lib32/libXinerama.so.1 wine-1.1.6/lib32/libXinerama.so
ln -s /usr/lib32/libXxf86vm.so.1 wine-1.1.6/lib32/libXxf86vm.so
ln -s /usr/lib32/libXi.so.6 wine-1.1.6/lib32/libXi.so
ln -s /usr/lib32/libXrandr.so.2 wine-1.1.6/lib32/libXrandr.so
ln -s /usr/lib32/liblcms.so.1 wine-1.1.6/lib32/liblcms.so
ln -s /usr/lib32/libpng12.so.0 wine-1.1.6/lib32/libpng.so
ln -s /usr/lib32/libcrypto.so.0.9.8 wine-1.1.6/lib32/libcrypto.so
ln -s /usr/lib32/libssl.so.0.9.8 wine-1.1.6/lib32/libssl.so
ln -s /usr/lib32/libxml2.so.2 wine-1.1.6/lib32/libxml2.so
ln -s /usr/lib32/libjpeg.so.62 wine-1.1.6/lib32/libjpeg.so
ln -s /usr/lib32/libXcomposite.so.1 wine-1.1.6/lib32/libXcomposite.so
ln -s /usr/lib32/libcups.so.2 wine-1.1.6/lib32/libcups.so
ln -s /usr/lib32/libXcursor.so.1 wine-1.1.6/lib32/libXcursor.so
ln -s /usr/lib32/libdbus-1.so.3 wine-1.1.6/lib32/libdbus-1.so
ln -s /usr/lib32/libhal.so.1 wine-1.1.6/lib32/libhal.so
ln -s /usr/lib32/libsane.so.1 wine-1.1.6/lib32/libsane.so
ln -s /usr/lib32/libgphoto2.so.2 wine-1.1.6/lib32/libgphoto2.so
ln -s /usr/lib32/libgphoto2_port.so.0 wine-1.1.6/lib32/libgphoto2_port.so
ln -s /usr/lib32/libldap-2.4.so.2 wine-1.1.6/lib32/libldap.so
ln -s /usr/lib32/libldap_r-2.4.so.2 wine-1.1.6/lib32/libldap_r.so
ln -s /usr/lib32/liblber-2.4.so.2 wine-1.1.6/lib32/liblber.so
ln -s /usr/lib32/libxslt.so.1 wine-1.1.6/lib32/libxslt.so
ln -s /usr/lib32/libcapi20.so.3 wine-1.1.6/lib32/libcapi20.so
ln -s /usr/lib32/libjack.so.0 wine-1.1.6/lib32/libjack.so
ln -s /usr/lib32/libodbc.so.1 wine-1.1.6/lib32/libodbc.so
ln -s /usr/lib32/libgnutls.so.13 wine-1.1.6/lib32/libgnutls.so

fi
# building the environment for wine
sudo apt-get -y update
sudo apt-get -y build-dep wine

# getting wine from sf
wget voxel.dl.sourceforge.net/sourceforge/wine/wine-1.1.6.tar.bz2
tar -xvf wine-1.1.6.tar.bz2
cd wine-1.1.6/
#this is the EA Durbin Itunes hack; modified from git to patch so i don't have to install git.
#http://appdb.winehq.org/objectManager.php?sClass=version@ild=13739
patch --verbose dlls/msi/action.c << EOF
--- action.old	2008-11-08 19:30:58.000000000 -0500
+++ action.c	2008-11-08 19:37:04.000000000 -0500
@@ -867,7 +867,9 @@
 
     if (rc != ERROR_SUCCESS)
         ERR("Execution halted, action %s returned %i\n", debugstr_w(action), rc);
-
+/* ITUNES 8 INSTALL HACK */
+if( rc == 1603 )
+rc = ERROR_SUCCESS;
     return rc;
 }
 
@@ -4712,7 +4714,8 @@
     LPWSTR args;
     DWORD event, numargs;
     UINT r = ERROR_FUNCTION_FAILED;
-
+/* ITUNES 8 INSTALL HACK */
+return ERROR_SUCCESS;
     comp = get_loaded_component(package, MSI_RecordGetString(rec, 6));
     if (!comp || comp->Action == INSTALLSTATE_UNKNOWN || comp->Action == INSTALLSTATE_ABSENT)
         return ERROR_SUCCESS;
EOF

#still want to get the patches from Maarten Lankhorst to work!! They supposedly add device support. The patches ran on 1.0.1 w/ tunes 7.6 but still no device support on iTunes 8.
if [ "$k" = "y" ]; then
CC="gcc-4.2 -m32" LDFLAGS="-L/lib32 -L/usr/lib32 -L`pwd`/lib32 -Wl,-rpath,/lib32 -Wl,-rpath,/usr/lib32" ./configure -v --prefix=`pwd`
make
sudo make install
else 
./configure --prefix=`pwd` 
make depend
make install
#winecfg


fi 

echo 'Do you want me to try to download iTunes 8.01 for you? (y/n)'
read tunes 
if [ "$tunes" = "y" ]; then
cd ..
wget http://appldnld.apple.com.edgesuite.net/content.info.apple.com/iTunes8/061-5555.20081002.5Kij7/iTunes801Setup.exe
fi
echo 'You need to run winecfg before you do anything else. it will be in the "bin" folder of the install directory. After that, you can run [install directory]/bin/wine [path to]/iTunes801Setup.exe AFTER you run setup, you can run iTunes by running something like [install directory]/bin/wine ~/.wine/drive_c/Program\ Files/iTunes/iTunes.exe';
clear
ls -al
echo "
*********************************************
All done! (?)

Look for a folder called wine-1.1.6/bin/ inside there you'll find the wine binary (wine) and the wine configurator (winecfg). If I downloaded iTunes successfully, it should be in the present directory.

If you missed any of this, you can see EVERYTHING again in the file called wine-itunes-no-devices.log that should be in this directory!"



}
install | tee wine-itunes-no-devices.log


