#!/bin/sh
if [ ! -f src/phones/p_lgvx8300.p ]
then
  echo "bogus bitpim source directory: exiting" >&2
  exit 1
fi
cd src/phones

if [ -f 5300-inited ]
then
  echo "__init__.py patch already applied" >&2
else
  patch -p0 <<'EOF' &&
Index: __init__.py
===================================================================
--- __init__.py	(revision 3531)
+++ __init__.py
@@ -61,6 +61,10 @@
                              'carrier': [c_vzw],
                              'brand': b_lg,
                              },
+              'LG-VX5300': { 'module': 'com_lgvx5300',
+                             'carrier': [c_vzw],
+                             'brand': b_lg,
+                             },
               'LG-LX5450': { 'module': 'com_lglx5450',
                              'carrier': [c_alltel],
                              'brand': b_lg,
EOF
  touch 5300-inited
fi

cp p_lgvx8300.p p_lgvx5300.p
patch -p0 <<'EOF'
--- p_lgvx5300.p.orig	2006-08-22 21:26:23.000000000 -0700
+++ p_lgvx5300.p	2006-08-22 21:52:40.000000000 -0700
@@ -10,7 +10,7 @@
 
 %{
 
-"""Various descriptions of data specific to LG VX8300"""
+"""Various descriptions of data specific to LG VX5300"""
 
 from common import PhoneBookBusyException
 
EOF

cp com_lgvx8300.py com_lgvx5300.py
patch -p0 <<'EOF'
--- com_lgvx5300.p.orig	2006-08-22 21:26:23.000000000 -0700
+++ com_lgvx5300.py	2006-08-22 21:55:14.000000000 -0700
@@ -6,11 +6,11 @@
 ### it under the terms of the BitPim license as detailed in the LICENSE file.
 ###
 
-"""Communicate with the LG VX8300 cell phone
+"""Communicate with the LG VX5300 cell phone
 
 
-The code in this file mainly inherits from VX8100 code and then extends where
-the 8300 has different functionality
+For now, this is just a copy of the LG VX8300 stuff with the
+names changed so that the phone will work.
 
 """
 
@@ -25,7 +25,7 @@
 import copy
 import com_lgvx4400
 import p_brew
-import p_lgvx8300
+import p_lgvx5300
 import com_lgvx8100
 import com_brew
 import com_phone
@@ -37,12 +37,12 @@
 import memo
 
 class Phone(com_lg.LGUncountedIndexedMedia, com_lgvx8100.Phone):
-    "Talk to the LG VX8300 cell phone"
+    "Talk to the LG VX5300 cell phone"
 
-    desc="LG-VX8300"
+    desc="LG-VX5300"
 
-    protocolclass=p_lgvx8300
-    serialsname='lgvx8300'
+    protocolclass=p_lgvx5300
+    serialsname='lgvx5300'
 
     external_storage_root='mmc1/'
 
@@ -85,7 +85,7 @@
         com_lgvx8100.Phone.get_detect_data(self, res)
         res[self.esn_file_key]=self.get_esn()
 
-    my_model='VX8300'
+    my_model='VX5300'
 
     def getfundamentals(self, results):
         """Gets information fundamental to interopating with the phone and UI.
@@ -127,7 +127,7 @@
 
     BP_Calendar_Version=3
     phone_manufacturer='LG Electronics Inc'
-    phone_model='VX8300'
+    phone_model='VX5300'
 
     WALLPAPER_WIDTH=275
     WALLPAPER_HEIGHT=175
@@ -135,7 +135,7 @@
     WALLPAPER_FILENAME_CHARS="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_() ."
     WALLPAPER_CONVERT_FORMAT="jpg"
 
-    # the 8300 uses "W" for wait in the dialstring, it does not support "T"
+    # the 5300 uses "W" for wait in the dialstring, it does not support "T"
     DIALSTRING_CHARS="[^0-9PW#*]"
 
     MAX_RINGTONE_BASENAME_LENGTH=32
EOF

cd ..
python protogen.py
