forked from canonical/firefox-snap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirefox.launcher
executable file
·55 lines (52 loc) · 2.41 KB
/
firefox.launcher
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/sh
# Copyright (C) 2021 Canonical Ltd.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3, as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# When running the snap for the first time, try and locate an existing
# firefox config in $SNAP_REAL_HOME/.mozilla/firefox, and import it.
# This requires the personal-files plug to be connected.
# This is a stopgap measure until proper profile migration is implemented
# in firefox (see https://bugzilla.mozilla.org/1730530).
DOTMOZILLA="$SNAP_USER_COMMON/.mozilla"
if [ ! -d "$DOTMOZILLA" ]; then
FIREFOX_CONFIG="$SNAP_REAL_HOME/.mozilla/firefox"
cat "$FIREFOX_CONFIG/profiles.ini" >/dev/null 2>&1
if [ "$?" -eq "0" ]; then
SIZE=$(du -sb $FIREFOX_CONFIG | cut -f 1)
AVAILABLE_BLOCKS=$(stat -f -c %a $SNAP_USER_COMMON)
BLOCK_SIZE=$(stat -f -c %s $SNAP_USER_COMMON)
AVAILABLE_SIZE=$(($AVAILABLE_BLOCKS*$BLOCK_SIZE))
if [ $AVAILABLE_SIZE -gt $SIZE ]; then
printf "Importing existing firefox profiles from $FIREFOX_CONFIG\n"
TS1=$(date +%s.%3N)
mkdir -p "$DOTMOZILLA"
cp -R "$FIREFOX_CONFIG" "$DOTMOZILLA/"
# Search and replace absolute file paths in plain-text config files.
for FILENAME in "pkcs11.txt" "extensions.json"; do
find "$DOTMOZILLA/firefox" -name "$FILENAME" \
-exec sed -i "s#$FIREFOX_CONFIG#$DOTMOZILLA/firefox#g" {} \;
done
# Patch the imported profiles to set the default one for use by the snap
# (legacy mode, no dedicated profiles).
$SNAP/patch-default-profile.py "$DOTMOZILLA/firefox/profiles.ini"
TS2=$(date +%s.%3N)
T=$(printf "$TS1 $TS2" | awk '{printf "%.3f",$2-$1}')
printf "Import done in $T s\n"
else
printf "Not importing existing firefox profiles from $FIREFOX_CONFIG "
printf "because there is not enough available space in $SNAP_USER_COMMON "
printf "(required: $SIZE bytes / available: $AVAILABLE_SIZE bytes)\n"
fi
fi
fi
exec "$SNAP/usr/lib/firefox/firefox" "$@"