Skip to content

Instantly share code, notes, and snippets.

@ywarnier
Created October 5, 2017 03:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ywarnier/905747cfb21322267da733ff98a01cfc to your computer and use it in GitHub Desktop.
Save ywarnier/905747cfb21322267da733ff98a01cfc to your computer and use it in GitHub Desktop.
Rebuild Firefox's profiles.ini from the profile cache directories
<?php
/**
* This script provide a way to rebuild the profiles.ini file
* in your ~/.mozilla/firefox/ directory in case, like me, the
* update to Firefox 56 on Ubuntu wiped your profiles.ini out
* and placed a fresh "default" profile instead, but luckily
* left all the profiles directories in place.
* To use it, you need php-cli and you need to place this file
* inside the ~/.mozilla/firefox/ directory.
* Execute it with "php firefox-profiles-ini-rebuild.php" and
* it will generate a "profiles.ini.new" file that you can later
* (after a manual check) add at the bottom of your virgin
* profiles.ini with "cat profiles.ini.new >> profiles.ini".
* Make sure you delete the first block (default) if it's not
* the right default profile.
* @author Yannick Warnier <y at beeznest dot com>
* @license GNU/LGPLv2+
*/
$list = scandir(__DIR__);
$i = 1;
$string = '';
$block = "[ProfileX_X]\nName=Y_Y\nIsRelative=1\nPath=Z_Z\nDefault=0\n\n";
$file = 'profiles.ini.new';
foreach ($list as $entry) {
if (substr($entry, 0, 1) == '.') {
continue;
}
if (!preg_match('/\w+\.\w+/', $entry)) {
echo "$entry does not match pattern".PHP_EOL;
continue;
}
$split = preg_split('/\./', $entry);
print_r($split, 1);
$name = $split[1];
$find = ['X_X', 'Y_Y', 'Z_Z'];
$replace = [$i, $name, $entry];
$string .= str_replace($find, $replace, $block);
$i++;
}
file_put_contents(__DIR__.'/'.$file, $string);
echo "Done! Make sure you check $file before adding it to profiles.ini".PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment