0

For Debian Linux, I have a post-installation script in which I would like to make a few local settings for a newly created user account in the file ~/.mozilla/firefox/<profile-directory>/user.js. However, before the user has launched Firefox there is no ~/.mozilla directory. Knowing that the default profile directory name ends with .default-esr I tried creating a new profile with the command

firefox -CreateProfile default-esr

but when Firefox is launched it creates another profile directory which ends with .default-esr-1. Is there a way to create a new profile which is actually used by Firefox? How can I create local settings from a script before Firefox has been launched?

I run Debian 12.1 and Mozilla Firefox 102.13.0esr (from the standard repository).

Edit:

If I run the command firefox -CreateProfile default-esr I get a ~/.mozilla/firefox/profiles.ini containing

[Profile0]
Name=default-esr
IsRelative=1
Path=1gbetm4q.default-esr

[General]
StartWithLastProfile=1
Version=2

On the other hand, if I launch Firefox with no .mozilla directory i get this profile.ini:

[Profile1]
Name=default
IsRelative=1
Path=gfro0v2o.default
Default=1

[Profile0]
Name=default-esr
IsRelative=1
Path=0715l0wk.default-esr

[General]
StartWithLastProfile=1
Version=2

[Install3B6073811A6ABF12]
Default=0715l0wk.default-esr
Locked=1

Apparently, Firefox creates two profiles the first time it's launched i.e when there is no .mozilla directory. Confusingly, the option Default refers to both profiles.

August Karlstrom
  • 1,736
  • 2
  • 27
  • 39
  • Your question is unclear, will you use only 1 profile or will you use more than 1 profile? – Z0OM Jul 25 '23 at 13:11
  • If you use only 1, the created 1 you can delete/overwrite and the profile.ini file – Z0OM Jul 25 '23 at 13:12
  • I'm only interested in defining one profile but the default behavior by Firefox is to create two profiles on the first launch: *default* and *default-esr* (see updated question). – August Karlstrom Jul 25 '23 at 16:08
  • 1
    Why don't you start a Firefox instance with your script once in the background and immediately terminate it to create your Mozilla folder with the profile.ini? After that, delete the default profiles, create the new one and overwrite the profile.ini file. You have everything you need in the answer and in the links; you just need to adjust your script. – Z0OM Jul 25 '23 at 16:18
  • And even if Firefox creates 2 or more profiles, you can still overwrite the .ini and leave the default folders as they are. – Z0OM Jul 25 '23 at 16:20
  • If you explain your steps very precisely, what you want to do and why, I'll write the script for you later once I'm finished with work :-) – Z0OM Jul 25 '23 at 16:22
  • That's very kind of you but I have found a solution now (see my reply). – August Karlstrom Jul 25 '23 at 16:43
  • 1
    You don't need 2 standard profiles; you don't even need a standard profile. You just need minimum, 1 profile to work with Firefox. If you believe you have found a solution, that's great; there are always multiple solutions and approaches in computer science. – Z0OM Jul 25 '23 at 17:19
  • There must be a reason why Firefox creates two profiles (*default* and *default-esr*) when launched for the first time. – August Karlstrom Jul 25 '23 at 18:08

2 Answers2

0

You can create a new profile with:

firefox -CreateProfile "PROFILENAME /PATH/PROFILEPATH"

The profile name and the profile path do not have to be identical.

Then copy your user.js with

cp -var user.js /PATH/PROFILEPATH/

And than start your firefox and select the profile

firefox -p

or to start with selected profile

firefox -P PROFILENAME &

Also take a look at this post where I describe something about profiles.

Firefox profiles with firefox -p

You can start your firefox with firefox -p

Now you get a new popup window where you can create, delete or rename profiles for firefox

Just unmark Use the selected profile without asking at startup and after that every time firefox start's you can select the profile you wanna work with

You can create different profiles for different use-cases

Or mark Use the selected profile without asking at startup, and after that firefox will start always with this profile

Update:

If you will use only the created profile, and you will not/can't execute firefox -p in your script, you can overwrite the profile.ini file with your script with this block.

This is the only block you need to start not more:

[Profile0]
Name=MYPROFILE
IsRelative=0
Path=/PATH/MYPROFILEPATH
Default=1
Z0OM
  • 1
  • 4
  • 24
  • 56
  • You can launch the profile without command line, just start your firefox – Z0OM Jul 25 '23 at 10:05
  • My script needs to run without user intervention so `firefox -p` is not an option. I suspect it should be possible to modify the `profiles.ini` file to set the default profile. There is both a `Default = 1` option and an `[Install]` section with `Default = ` in `profiles.ini`. – August Karlstrom Jul 25 '23 at 11:42
0

We can mimic Firefox's default behavior by creating the two standard profiles default-esr and default with the commands:

firefox -CreateProfile default-esr
firefox -CreateProfile default

This will create a ~/.mozilla/firefox/profiles.ini which looks like this:

[Profile1]
Name=default
IsRelative=1
Path=gfro0v2o.default

[Profile0]
Name=default-esr
IsRelative=1
Path=0715l0wk.default-esr

[General]
StartWithLastProfile=1
Version=2

Next, to make Firefox use default-esr (instead of it creating a new profile on launch) we need to add an Install section to profile.ini with the option Default:

profileDir="$(awk -F= '/^Path=.*\.default-esr/ { print $2 }' ~/.mozilla/firefox/profiles.ini)"
cat <<EOT >> ~/.mozilla/firefox/profiles.ini

[Install3B6073811A6ABF12]
Default=$profileDir
Locked=1
EOT

The hexadecimal suffix is calculated from the installation path and will not change. Finally we can copy the file user.js to the profile directory:

cp user.js "$HOME/.mozilla/firefox/$profileDir"
August Karlstrom
  • 1,736
  • 2
  • 27
  • 39