Fixed to import after popping, not before!
[webos-internals:acydlords-webos.git] / install
1 #!/bin/sh
2 USER=`whoami`
3 HOSTNAME=castle
4 PATCH_NAME=$1
5 GIT_PATH=/opt/src/modifications
6
7 if [ "$USER" != "root" ]
8 then
9   echo "ERROR: Must be root, try sudo -i"
10   exit 1
11 fi
12
13 if [ "$HOSTNAME" != "castle" ]
14 then
15   echo "Script must be run on Pre"
16   exit 1
17 fi
18
19 if [ ! -e $GIT_PATH ]
20 then
21   echo "ERROR: Cannot find git tree at: $GIT_PATH"
22   echo "Please visit http://www.webos-internals.org/wiki/Applying_Patches"
23   exit 1
24 fi
25
26 if [ $# -gt 1 ]
27 then 
28   echo "ERROR: Too many arguments"
29   exit 1
30 fi
31
32 cd $GIT_PATH
33 if [ $? -ne 0 ]
34 then
35   echo "ERROR: Cannot find git path: $GIT_PATH"
36   echo "Please visit http://www.webos-internals.org/wiki/Applying_Patches"
37   exit 1
38 fi
39
40 if [ $# -eq 0 ]
41 then
42   echo ""
43   echo -n "Patch name to apply? [ALL] > "
44   read PATCH_NAME
45 fi
46
47 if [ "$PATCH_NAME" = "-l" ]
48 then
49   find . -name *.patch | awk -F/ '{print $NF}'
50   exit 0
51 fi
52
53 if [ "$PATCH_NAME" != "" ]
54 then
55   echo "Looking for patch $PATCH_NAME..."
56   find . -name $PATCH_NAME | grep $PATCH_NAME
57   if [ $? -ne 0 ]
58   then
59     echo "ERROR: Could not find patch: $PATCH_NAME"
60     exit 1
61   fi
62 fi
63
64 echo "Pulling latest git tree..."
65 git pull
66 if [ $? -ne 0 ]
67 then
68   echo "FAILED"
69   echo "Please visit http://www.webos-internals.org/wiki/Applying_Patches"
70   exit 1
71 fi
72
73 cd /
74 if [ $? -ne 0 ]
75 then
76   echo "Can't cd / ??? ----> RUN!"
77   exit 1
78 fi
79
80
81 echo "Remounting / rw..."
82 mount -o rw,remount /
83 if [ $? -ne 0 ]
84 then
85   echo "ERROR: Could not remount / in rw"
86   echo "Please visit http://www.webos-internals.org/wiki/Applying_Patches"
87   exit 1
88 fi
89
90 echo "Popping previous patches..."
91 quilt pop -a
92 if [ $? -ne 0 ]
93 then
94   echo "ERROR: Could not pop patch"
95   echo "Please visit http://www.webos-internals.org/wiki/Applying_Patches"
96   exit 1
97 fi
98
99 PATCH_PATH=`find ${GIT_PATH} -name ${PATCH_NAME}`
100 echo "Importing patch ${PATCH_PATH}..."
101 quilt import -f ${PATCH_PATH}
102
103 echo "Verifying patch is in quilt series..."
104 quilt series | grep $PATCH_NAME
105 if [ $? -ne 0 ]
106 then
107   echo "ERROR: Cannot find patch in series"
108   echo "Please visit http://www.webos-internals.org/wiki/Applying_Patches"
109   exit 1
110 fi
111
112 echo "Pushing new patches..."
113 quilt push -a
114 if [ $? -ne 0 ]
115 then
116   echo "ERROR: Could not push patch"
117   echo "Please visit http://www.webos-internals.org/wiki/Applying_Patches"
118   exit 1
119 fi
120
121 echo "SUCCESS"
122
123 echo "Remounting / to read-only"
124 mount -o ro,remount /