|
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 |
|
11 . $(dirname "$0")/common.sh |
|
12 |
|
13 # TODO: it would be better to pass this as a command line option. |
|
14 directories_to_remove='TorBrowser/Data/Browser/profile.default/extensions/https-everywhere@eff.org' |
|
15 |
|
16 # ----------------------------------------------------------------------------- |
|
17 |
|
18 print_usage() { |
|
19 notice "Usage: $(basename $0) [OPTIONS] ARCHIVE DIRECTORY" |
|
20 } |
|
21 |
|
22 if [ $# = 0 ]; then |
|
23 print_usage |
|
24 exit 1 |
|
25 fi |
|
26 |
|
27 if [ $1 = -h ]; then |
|
28 print_usage |
|
29 notice "" |
|
30 notice "The contents of DIRECTORY will be stored in ARCHIVE." |
|
31 notice "" |
|
32 notice "Options:" |
|
33 notice " -h show this help text" |
|
34 notice " -q be less verbose" |
|
35 notice "" |
|
36 exit 1 |
|
37 fi |
|
38 |
|
39 if [ $1 = -q ]; then |
|
40 QUIET=1 |
|
41 shift |
|
42 fi |
|
43 |
|
44 # ----------------------------------------------------------------------------- |
|
45 |
|
46 archive="$1" |
|
47 targetdir="$2" |
|
48 # Prevent the workdir from being inside the targetdir so it isn't included in |
|
49 # the update mar. |
|
50 if [ $(echo "$targetdir" | grep -c '\/$') = 1 ]; then |
|
51 # Remove the / |
|
52 targetdir=$(echo "$targetdir" | sed -e 's:\/$::') |
|
53 fi |
|
54 workdir="$targetdir.work" |
|
55 updatemanifestv2="$workdir/updatev2.manifest" |
|
56 updatemanifestv3="$workdir/updatev3.manifest" |
|
57 targetfiles="updatev2.manifest updatev3.manifest" |
|
58 |
|
59 mkdir -p "$workdir" |
|
60 |
|
61 # On Mac, the precomplete file added by Bug 386760 will cause OS X to reload the |
|
62 # Info.plist so it launches the right architecture, bug 600098 |
|
63 |
|
64 # Generate a list of all files in the target directory. |
|
65 pushd "$targetdir" |
|
66 if test $? -ne 0 ; then |
|
67 exit 1 |
|
68 fi |
|
69 |
|
70 if [ ! -f "precomplete" ]; then |
|
71 notice "precomplete file is missing!" |
|
72 exit 1 |
|
73 fi |
|
74 |
|
75 list_files files |
|
76 list_symlinks symlinks symlink_targets |
|
77 |
|
78 popd |
|
79 |
|
80 # Add the type of update to the beginning of the update manifests. |
|
81 > "$updatemanifestv2" |
|
82 > "$updatemanifestv3" |
|
83 notice "" |
|
84 notice "Adding type instruction to update manifests" |
|
85 notice " type complete" |
|
86 echo "type \"complete\"" >> "$updatemanifestv2" |
|
87 echo "type \"complete\"" >> "$updatemanifestv3" |
|
88 |
|
89 # If removal of any old, existing directories is desired, emit the appropriate |
|
90 # rmrfdir commands. |
|
91 notice "" |
|
92 notice "Adding directory removal instructions to update manifests" |
|
93 for dir_to_remove in $directories_to_remove; do |
|
94 # rmrfdir requires a trailing slash; if slash is missing, add one. |
|
95 if ! [[ "$dir_to_remove" =~ /$ ]]; then |
|
96 dir_to_remove="${dir_to_remove}/" |
|
97 fi |
|
98 echo "rmrfdir \"$dir_to_remove\"" >> "$updatemanifestv2" |
|
99 echo "rmrfdir \"$dir_to_remove\"" >> "$updatemanifestv3" |
|
100 done |
|
101 |
|
102 notice "" |
|
103 notice "Adding file add instructions to update manifests" |
|
104 num_files=${#files[*]} |
|
105 |
|
106 for ((i=0; $i<$num_files; i=$i+1)); do |
|
107 f="${files[$i]}" |
|
108 |
|
109 if check_for_add_if_not_update "$f"; then |
|
110 make_add_if_not_instruction "$f" "$updatemanifestv3" |
|
111 if check_for_add_to_manifestv2 "$f"; then |
|
112 make_add_instruction "$f" "$updatemanifestv2" "" 1 |
|
113 fi |
|
114 else |
|
115 make_add_instruction "$f" "$updatemanifestv2" "$updatemanifestv3" |
|
116 fi |
|
117 |
|
118 dir=$(dirname "$f") |
|
119 mkdir -p "$workdir/$dir" |
|
120 $BZIP2 -cz9 "$targetdir/$f" > "$workdir/$f" |
|
121 copy_perm "$targetdir/$f" "$workdir/$f" |
|
122 |
|
123 targetfiles="$targetfiles \"$f\"" |
|
124 done |
|
125 |
|
126 notice "" |
|
127 notice "Adding symlink add instructions to update manifests" |
|
128 num_symlinks=${#symlinks[*]} |
|
129 for ((i=0; $i<$num_symlinks; i=$i+1)); do |
|
130 link="${symlinks[$i]}" |
|
131 target="${symlink_targets[$i]}" |
|
132 make_addsymlink_instruction "$link" "$target" "$updatemanifestv2" "$updatemanifestv3" |
|
133 done |
|
134 |
|
135 # Append remove instructions for any dead files. |
|
136 notice "" |
|
137 notice "Adding file and directory remove instructions from file 'removed-files'" |
|
138 append_remove_instructions "$targetdir" "$updatemanifestv2" "$updatemanifestv3" |
|
139 |
|
140 $BZIP2 -z9 "$updatemanifestv2" && mv -f "$updatemanifestv2.bz2" "$updatemanifestv2" |
|
141 $BZIP2 -z9 "$updatemanifestv3" && mv -f "$updatemanifestv3.bz2" "$updatemanifestv3" |
|
142 |
|
143 eval "$MAR -C \"$workdir\" -c output.mar $targetfiles" |
|
144 mv -f "$workdir/output.mar" "$archive" |
|
145 |
|
146 # cleanup |
|
147 rm -fr "$workdir" |
|
148 |
|
149 notice "" |
|
150 notice "Finished" |
|
151 notice "" |