runme.sh 7.81 KB
Newer Older
1
2
3
#!/bin/bash
set -xe

4
5
6
# Future products supporting Flatpaks will set this accordingly
: PRODUCT                       "${PRODUCT:=firefox}"

7
8
9
10
11
12
# Required env variables

test "$VERSION"
test "$BUILD_NUMBER"
test "$CANDIDATES_DIR"
test "$L10N_CHANGESETS"
13
test "$FLATPAK_BRANCH"
14
15
16
17
18
19
20

# Optional env variables
: WORKSPACE                     "${WORKSPACE:=/home/worker/workspace}"
: ARTIFACTS_DIR                 "${ARTIFACTS_DIR:=/home/worker/artifacts}"

pwd

21
22
23
24
# XXX: this is used to populate the datetime in org.mozilla.firefox.appdata.xml
DATE=$(date +%Y-%m-%d)
export DATE

25
SCRIPT_DIRECTORY="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
26
TARGET_TAR_XZ_FULL_PATH="$ARTIFACTS_DIR/target.flatpak.tar.xz"
27
SOURCE_DEST="${WORKSPACE}/source"
28
29
FREEDESKTOP_VERSION="20.08"
FIREFOX_BASEAPP_CHANNEL="20.08"
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52


# XXX: these commands are temporarily, there's an upcoming fix in the upstream Docker image
# that we work on top of, from `freedesktopsdk`, that will make these two lines go away eventually
mkdir -p /root /tmp /var/tmp
mkdir -p "$ARTIFACTS_DIR"
rm -rf "$SOURCE_DEST" && mkdir -p "$SOURCE_DEST"

# XXX ensure we have a clean slate in the local flatpak repo
rm -rf ~/.local/share/flatpak/


CURL="curl --location --retry 10 --retry-delay 10"

# Download en-US linux64 binary
$CURL -o "${WORKSPACE}/firefox.tar.bz2" \
    "${CANDIDATES_DIR}/${VERSION}-candidates/build${BUILD_NUMBER}/linux-x86_64/en-US/firefox-${VERSION}.tar.bz2"

# Use list of locales to fetch L10N XPIs
$CURL -o "${WORKSPACE}/l10n_changesets.json" "$L10N_CHANGESETS"
locales=$(python3 "$SCRIPT_DIRECTORY/extract_locales_from_l10n_json.py" "${WORKSPACE}/l10n_changesets.json")

DISTRIBUTION_DIR="$SOURCE_DEST/distribution"
53
54
55
56
57
58
59
60
if [[ "$PRODUCT" == "firefox" ]]; then
    # Get Flatpak configuration
    PARTNER_CONFIG_DIR="$WORKSPACE/partner_config"
    git clone https://github.com/mozilla-partners/flatpak.git "$PARTNER_CONFIG_DIR"
    mv "$PARTNER_CONFIG_DIR/desktop/flatpak/distribution" "$DISTRIBUTION_DIR"
else
    mkdir -p "$DISTRIBUTION_DIR"
fi
61
62
63
64
65
66
67
68
69

mkdir -p "$DISTRIBUTION_DIR/extensions"
for locale in $locales; do
    $CURL -o "$DISTRIBUTION_DIR/extensions/langpack-${locale}@firefox.mozilla.org.xpi" \
        "$CANDIDATES_DIR/${VERSION}-candidates/build${BUILD_NUMBER}/linux-x86_64/xpi/${locale}.xpi"
done

envsubst < "$SCRIPT_DIRECTORY/org.mozilla.firefox.appdata.xml.in" > "${WORKSPACE}/org.mozilla.firefox.appdata.xml"
cp -v "$SCRIPT_DIRECTORY/org.mozilla.firefox.desktop" "$WORKSPACE"
70
71
# Add a group policy file to disable app updates, as those are handled by Flathub
cp -v "$SCRIPT_DIRECTORY/policies.json" "$WORKSPACE"
72
73
74
75
76
cp -v "$SCRIPT_DIRECTORY/default-preferences.js" "$WORKSPACE"
cp -v "$SCRIPT_DIRECTORY/launch-script.sh" "$WORKSPACE"
cd "${WORKSPACE}"

flatpak remote-add --user --if-not-exists --from flathub https://dl.flathub.org/repo/flathub.flatpakrepo
77
# XXX: added --user to `flatpak install` to avoid ambiguity
78
flatpak install --user -y flathub org.mozilla.firefox.BaseApp//${FIREFOX_BASEAPP_CHANNEL} --no-deps
79
80
81
82

# XXX: this command is temporarily, there's an upcoming fix in the upstream Docker image
# that we work on top of, from `freedesktopsdk`, that will make these two lines go away eventually
mkdir -p build
83
cp -r ~/.local/share/flatpak/app/org.mozilla.firefox.BaseApp/current/active/files build/files
84
85
86
87
88
89
90

ARCH=$(flatpak --default-arch)
cat <<EOF > build/metadata
[Application]
name=org.mozilla.firefox
runtime=org.freedesktop.Platform/${ARCH}/${FREEDESKTOP_VERSION}
sdk=org.freedesktop.Sdk/${ARCH}/${FREEDESKTOP_VERSION}
91
base=app/org.mozilla.firefox.BaseApp/${ARCH}/${FIREFOX_BASEAPP_CHANNEL}
92
93
94
95
[Extension org.mozilla.firefox.Locale]
directory=share/runtime/langpack
autodelete=true
locale-subset=true
96
97
98
99
100
101

[Extension org.freedesktop.Platform.ffmpeg-full]
directory=lib/ffmpeg
add-ld-path=.
no-autodownload=true
version=${FREEDESKTOP_VERSION}
102
103
104
105
106
107
108
109
EOF

cat <<EOF > build/metadata.locale
[Runtime]
name=org.mozilla.firefox.Locale

[ExtensionOf]
ref=app/org.mozilla.firefox/${ARCH}/${FLATPAK_BRANCH}
110
111
112
113
114
115
116
117
118
119
EOF

appdir=build/files
install -d "${appdir}/lib/"
(cd "${appdir}/lib/" && tar jxf "${WORKSPACE}/firefox.tar.bz2")
install -D -m644 -t "${appdir}/share/appdata" org.mozilla.firefox.appdata.xml
install -D -m644 -t "${appdir}/share/applications" org.mozilla.firefox.desktop
for size in 16 32 48 64 128; do
    install -D -m644 "${appdir}/lib/firefox/browser/chrome/icons/default/default${size}.png" "${appdir}/share/icons/hicolor/${size}x${size}/apps/org.mozilla.firefox.png"
done
120
mkdir -p "${appdir}/lib/ffmpeg"
121
122

appstream-compose --prefix="${appdir}" --origin=flatpak --basename=org.mozilla.firefox org.mozilla.firefox
123
appstream-util mirror-screenshots "${appdir}"/share/app-info/xmls/org.mozilla.firefox.xml.gz "https://dl.flathub.org/repo/screenshots/org.mozilla.firefox-${FLATPAK_BRANCH}" build/screenshots "build/screenshots/org.mozilla.firefox-${FLATPAK_BRANCH}"
124

125
126
127
128
129
130
131
# XXX: we used to `install -D` before which automatically created the components
# of target, now we need to manually do this since we're symlinking
mkdir -p "${appdir}/lib/firefox/distribution/extensions"
# XXX: we put the langpacks in /app/share/locale/$LANG_CODE and symlink that
# directory to where Firefox looks them up; this way only subset configured
# on user system is downloaded vs all locales
for locale in $locales; do
132
    install -D -m644 -t "${appdir}/share/runtime/langpack/${locale:0:2}/" "${DISTRIBUTION_DIR}/extensions/langpack-${locale}@firefox.mozilla.org.xpi"
133
    ln -sf "/app/share/runtime/langpack/${locale:0:2}/langpack-${locale}@firefox.mozilla.org.xpi" "${appdir}/lib/firefox/distribution/extensions/langpack-${locale}@firefox.mozilla.org.xpi"
134
done
135
install -D -m644 -t "${appdir}/lib/firefox/distribution" "$DISTRIBUTION_DIR/distribution.ini"
136
install -D -m644 -t "${appdir}/lib/firefox/distribution" policies.json
137
138
139
140
install -D -m644 -t "${appdir}/lib/firefox/browser/defaults/preferences" default-preferences.js
install -D -m755 launch-script.sh "${appdir}/bin/firefox"

flatpak build-finish build                                      \
141
        --share=ipc                                             \
142
143
        --share=network                                         \
        --socket=pulseaudio                                     \
144
        --socket=x11                                            \
145
        --socket=pcsc                                           \
146
        --require-version=0.11.1                                \
147
148
        --persist=.mozilla                                      \
        --filesystem=xdg-download:rw                            \
149
        --device=all                                            \
150
151
152
153
154
155
        --talk-name=org.freedesktop.FileManager1                \
        --system-talk-name=org.freedesktop.NetworkManager       \
        --talk-name=org.a11y.Bus                                \
        --talk-name=org.gnome.SessionManager                    \
        --talk-name=org.freedesktop.ScreenSaver                 \
        --talk-name="org.gtk.vfs.*"                             \
156
        --talk-name=org.freedesktop.Notifications               \
157
        --own-name="org.mpris.MediaPlayer2.firefox.*"           \
158
159
        --command=firefox

160
161
flatpak build-export --disable-sandbox --no-update-summary --exclude='/share/runtime/langpack/*/*' repo build "$FLATPAK_BRANCH"
flatpak build-export --disable-sandbox --no-update-summary --metadata=metadata.locale --files=files/share/runtime/langpack repo build "$FLATPAK_BRANCH"
162
ostree commit --repo=repo --canonical-permissions --branch=screenshots/x86_64 build/screenshots
163
flatpak build-update-repo --generate-static-deltas repo
164
tar cvfJ flatpak.tar.xz repo
165

166
mv -- flatpak.tar.xz "$TARGET_TAR_XZ_FULL_PATH"
167
168
169
170
171

# XXX: if we ever wanted to go back to building flatpak bundles, we can revert this command; useful for testing individual artifacts, not publishable
# flatpak build-bundle "$WORKSPACE"/repo org.mozilla.firefox.flatpak org.mozilla.firefox
# TARGET_FULL_PATH="$ARTIFACTS_DIR/target.flatpak"
# mv -- *.flatpak "$TARGET_FULL_PATH"