flasher: use nanddump to avoid dep on mtdblock
[pandora-misc.git] / hotfix_updater / get_packages.sh
1 #!/bin/bash
2 #
3 # Script to gather the ipks that were changed in a new firmware compared to an
4 # older firmware. Update the variables at the top to match your files and then
5 # just run the script. It should generate 4 output txt files as well as fetch
6 # the ipks that are to be installed.
7
8
9 WORKING_DIR=`pwd`
10
11 # where shall the packages end?
12 PACKAGES_FOLDER=$WORKING_DIR/hotfix/packages
13
14 # old and new list of packages seperated by newlines
15 OLD_PACKAGES=$WORKING_DIR/installed-packages_fw1.txt
16 NEW_PACKAGES=$WORKING_DIR/installed-packages_hf6r.txt
17
18 # names of the output files
19 TO_BE_REMOVED=$WORKING_DIR/to_be_removed.txt
20 TO_BE_ADDED=$WORKING_DIR/to_be_added.txt
21 REALLY_REMOVED=$WORKING_DIR/really_removed.txt
22 REALLY_ADDED=$WORKING_DIR/really_added.txt
23 ERRORS=$WORKING_DIR/errors.txt
24
25
26 # some temp files
27 TMP1=$WORKING_DIR/tmp1.txt
28 TMP2=$WORKING_DIR/tmp2.txt
29
30
31 #
32 # gather list of new and removed packages based on the input files
33 #
34
35 if [ ! -f $OLD_PACKAGES ]
36 then
37         echo "could not find the new package list at $OLD_PACKAGES; aborting"
38         exit 1;
39 fi
40 if [ ! -f $NEW_PACKAGES ]
41 then
42         echo "could not find the new package list at $NEW_PACKAGES; aborting"
43         exit 1;
44 fi
45
46 # list of removed packages since "OLD_PACKAGES" (means also packages that were replaced in a new version!)
47 diff $OLD_PACKAGES $NEW_PACKAGES | grep "<" | cut -f 2 -d " " | sort > $TO_BE_REMOVED
48
49 # list of added packages in "NEW_PACKAGES" compared to "OLD_PACKAGES" (also updated versions!)
50 diff $OLD_PACKAGES $NEW_PACKAGES | grep ">" | cut -f 2 -d " " | sort  > $TO_BE_ADDED
51
52 cat $TO_BE_REMOVED | cut -f 1 -d "_" | sort  > $TMP1
53 cat $TO_BE_ADDED | cut -f 1 -d "_" | sort  > $TMP2
54
55 diff $TMP1 $TMP2 | grep "<" | cut -f 2 -d " " | sort > $REALLY_REMOVED
56 diff $TMP1 $TMP2 | grep ">" | cut -f 2 -d " " | sort > $REALLY_ADDED
57
58 #cleanup temp files from "gathering package list"
59 rm -f $TMP1 $TMP2
60
61
62 #
63 # find out filenames for "new" packages and download the files
64 #
65
66 # remove existing old stamp files
67 rm -f $WORKING_DIR/Packages.stamps.all $WORKING_DIR/Packages.stamps.armv7a $WORKING_DIR/Packages.stamps.omap3-pandora
68
69 # get recent stamp files from the feed
70 wget --output-document=$WORKING_DIR/Packages.stamps.all http://www.openpandora.org/feeds/unstable/all/Packages.stamps
71 wget --output-document=$WORKING_DIR/Packages.stamps.armv7a http://www.openpandora.org/feeds/unstable/armv7a/Packages.stamps
72 wget --output-document=$WORKING_DIR/Packages.stamps.omap3-pandora http://www.openpandora.org/feeds/unstable/omap3-pandora/Packages.stamps
73
74 # convert package entries in stamp files into the correct "full" urls
75 cat $WORKING_DIR/Packages.stamps.all | cut -f 2 -d " " | sed -e 's;^;http://www.openpandora.org/feeds/unstable/all/;g' > $TMP1
76 cat $WORKING_DIR/Packages.stamps.armv7a | cut -f 2 -d " " | sed -e 's;^;http://www.openpandora.org/feeds/unstable/armv7a/;g' >> $TMP1
77 cat $WORKING_DIR/Packages.stamps.omap3-pandora | cut -f 2 -d " " | sed -e 's;^;http://www.openpandora.org/feeds/unstable/omap3-pandora/;g' >> $TMP1
78
79 # cleanup temp files
80 rm -f $WORKING_DIR/Packages.stamps.all $WORKING_DIR/Packages.stamps.armv7a $WORKING_DIR/Packages.stamps.omap3-pandora
81
82 rm -f $ERRORS
83 # get the list of the relevant (aka 'new) package URLs
84 for i in `cat $TO_BE_ADDED`;
85 do
86         grep "$i" $TMP1 >> $TMP2;
87         if [ "$?" -ne "0" ]
88         then
89                 echo "Could not find package '$i' in download list" >> $ERRORS
90         fi
91 done
92
93 # seperate into 'kernel' and 'other' (every packagename that starts with 'kernel' is only relevant for the kernel space
94 cat $TMP2 | grep  "\/kernel" > $TMP2.kernel
95 cat $TMP2 | grep -v "\/kernel" > $TMP2.other
96
97
98 #create folders for the new packages
99 if [ ! -d $PACKAGES_FOLDER/kernel ]
100 then
101         mkdir -p $PACKAGES_FOLDER/kernel
102 fi
103 if [ ! -d $PACKAGES_FOLDER/other ]
104 then
105         mkdir -p $PACKAGES_FOLDER/other
106 fi
107
108 # download kernel ipks
109 cd $PACKAGES_FOLDER/kernel
110 wget --no-clobber -i $TMP2.kernel
111
112 # download other ipks
113 cd $PACKAGES_FOLDER/other
114 wget --no-clobber -i $TMP2.other
115
116 # move packages that are supposed to be openpandora specific into an extra folder which is installed last!
117 mkdir $PACKAGES_FOLDER/pandora
118 mv $PACKAGES_FOLDER/other/pandora*ipk $PACKAGES_FOLDER/pandora/
119
120 # cleanup all the remaining temp files
121 rm -f $TMP1 $TMP2 $TMP2.kernel $TMP2.other
122
123
124 #
125 # explain the results in some nice words
126 #
127
128 echo -e
129 echo -e
130 echo -e
131 echo "Explaination of created folders and files"
132 echo -e
133 echo "Created text files:"
134 echo " $TO_BE_REMOVED: files that are no longer included (at least not as this exact package version)"
135 echo " $TO_BE_ADDED: files that are to be installed (complete package name incl version number"
136 echo " $REALLY_REMOVED: package names of those packages that are no longer installed (and should be removed using opkg!)"
137 echo " $REALLY_ADDED: package names of packages that were added since the old version"
138 echo " $ERRORS: a list of packages that were not found on the given download server(s)"
139 echo -e
140 echo "Saved all ("`ls $PACKAGES_FOLDER/kernel/*ipk | wc -l`") kernel related ipks to:"
141 echo " $PACKAGES_FOLDER/kernel"
142 echo "Saved all ("`ls $PACKAGES_FOLDER/other/*ipk | wc -l`") 'other' ipks to:"
143 echo " $PACKAGES_FOLDER/other"
144 echo -e
145 echo "You can now copy the folder $PACKAGES_FOLDER into the place where you create the pnd file."
146 if [ -s $ERRORS ]
147 then
148         echo -e
149         echo "Some packages were not found. Please have a look at $ERRORS and make sure that things actually work!"
150 fi
151