|
1 #!/bin/bash |
|
2 # This Source Code Form is subject to the terms of the Mozilla Public |
|
3 # License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
|
5 |
|
6 # |
|
7 # This tool generates full update packages for the update system. |
|
8 # Author: Darin Fisher |
|
9 # |
|
10 # In here to use the local common.sh to allow the full mars to have unfiltered files |
|
11 |
|
12 . $(dirname "$0")/common.sh |
|
13 |
|
14 # ----------------------------------------------------------------------------- |
|
15 |
|
16 print_usage() { |
|
17 notice "Usage: $(basename $0) [OPTIONS] ARCHIVE DIRECTORY" |
|
18 } |
|
19 |
|
20 if [ $# = 0 ]; then |
|
21 print_usage |
|
22 exit 1 |
|
23 fi |
|
24 |
|
25 if [ $1 = -h ]; then |
|
26 print_usage |
|
27 notice "" |
|
28 notice "The contents of DIRECTORY will be stored in ARCHIVE." |
|
29 notice "" |
|
30 notice "Options:" |
|
31 notice " -h show this help text" |
|
32 notice "" |
|
33 exit 1 |
|
34 fi |
|
35 |
|
36 # ----------------------------------------------------------------------------- |
|
37 |
|
38 archive="$1" |
|
39 targetdir="$2" |
|
40 # Prevent the workdir from being inside the targetdir so it isn't included in |
|
41 # the update mar. |
|
42 if [ $(echo "$targetdir" | grep -c '\/$') = 1 ]; then |
|
43 # Remove the / |
|
44 targetdir=$(echo "$targetdir" | sed -e 's:\/$::') |
|
45 fi |
|
46 workdir="$targetdir.work" |
|
47 updatemanifestv2="$workdir/updatev2.manifest" |
|
48 updatemanifestv3="$workdir/updatev3.manifest" |
|
49 targetfiles="updatev2.manifest updatev3.manifest" |
|
50 |
|
51 mkdir -p "$workdir" |
|
52 |
|
53 # On Mac, the precomplete file added by Bug 386760 will cause OS X to reload the |
|
54 # Info.plist so it launches the right architecture, bug 600098 |
|
55 |
|
56 # Generate a list of all files in the target directory. |
|
57 pushd "$targetdir" |
|
58 if test $? -ne 0 ; then |
|
59 exit 1 |
|
60 fi |
|
61 |
|
62 if [ ! -f "precomplete" ]; then |
|
63 notice "precomplete file is missing!" |
|
64 exit 1 |
|
65 fi |
|
66 |
|
67 list_files files |
|
68 |
|
69 popd |
|
70 |
|
71 # Add the type of update to the beginning of the update manifests. |
|
72 > $updatemanifestv2 |
|
73 > $updatemanifestv3 |
|
74 notice "" |
|
75 notice "Adding type instruction to update manifests" |
|
76 notice " type complete" |
|
77 echo "type \"complete\"" >> $updatemanifestv2 |
|
78 echo "type \"complete\"" >> $updatemanifestv3 |
|
79 |
|
80 notice "" |
|
81 notice "Adding file add instructions to update manifests" |
|
82 num_files=${#files[*]} |
|
83 |
|
84 for ((i=0; $i<$num_files; i=$i+1)); do |
|
85 f="${files[$i]}" |
|
86 |
|
87 if check_for_add_if_not_update "$f"; then |
|
88 make_add_if_not_instruction "$f" "$updatemanifestv3" |
|
89 if check_for_add_to_manifestv2 "$f"; then |
|
90 make_add_instruction "$f" "$updatemanifestv2" "" 1 |
|
91 fi |
|
92 else |
|
93 make_add_instruction "$f" "$updatemanifestv2" "$updatemanifestv3" |
|
94 fi |
|
95 |
|
96 dir=$(dirname "$f") |
|
97 mkdir -p "$workdir/$dir" |
|
98 $BZIP2 -cz9 "$targetdir/$f" > "$workdir/$f" |
|
99 copy_perm "$targetdir/$f" "$workdir/$f" |
|
100 |
|
101 targetfiles="$targetfiles \"$f\"" |
|
102 done |
|
103 |
|
104 # Append remove instructions for any dead files. |
|
105 notice "" |
|
106 notice "Adding file and directory remove instructions from file 'removed-files'" |
|
107 append_remove_instructions "$targetdir" "$updatemanifestv2" "$updatemanifestv3" |
|
108 |
|
109 $BZIP2 -z9 "$updatemanifestv2" && mv -f "$updatemanifestv2.bz2" "$updatemanifestv2" |
|
110 $BZIP2 -z9 "$updatemanifestv3" && mv -f "$updatemanifestv3.bz2" "$updatemanifestv3" |
|
111 |
|
112 eval "$MAR -C \"$workdir\" -c output.mar $targetfiles" |
|
113 mv -f "$workdir/output.mar" "$archive" |
|
114 |
|
115 # cleanup |
|
116 rm -fr "$workdir" |
|
117 |
|
118 notice "" |
|
119 notice "Finished" |
|
120 notice "" |