~freed00m/librewolf-comment-out-cfg-hook

dfbc35964ee7db271b008778db57c512b10d7163 — Antonin Dach 3 years ago
Librewolf comment out hooks
A  => .SRCINFO +12 -0
@@ 1,12 @@
pkgbase = librewolf-comment-out-cfg-hook
	pkgdesc = Comment out custom cfg values via pacman hook
	pkgver = 1
	pkgrel = 1
	url = https://git.sr.ht/~freed00m/librewolf-comment-out-cfg-hook
	arch = x86_64
	arch = aarch64
	license = MIT
	depends = librewolf

pkgname = librewolf-comment-out-cfg-hook


A  => .gitignore +4 -0
@@ 1,4 @@
*.tar*
/pkg



A  => LICENSE +21 -0
@@ 1,21 @@
MIT License

Copyright (c) 2021 AntonĂ­n Dach

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

A  => PKGBUILD +32 -0
@@ 1,32 @@
# Maintainer: AntonĂ­n Dach <dach@protonmail.com>

pkgname=librewolf-comment-out-cfg-hook
pkgver=1
pkgrel=1
pkgdesc='Comment out custom cfg values via pacman hook'
arch=(x86_64 aarch64)
url='https://git.sr.ht/~freed00m/librewolf-comment-out-cfg-hook'
license=('MIT')
depends=(librewolf)

package() {
  # -m  will set the mode
  # -D  will just create the non-existing directories to the target.
  #cd "$srcdir" && find usr/ -type f -exec install -Dm 644 "{}" "$pkgdir/{}" \;

  mkdir -p "$pkgdir/usr/share/libalpm/scripts/"
  mkdir -p "$pkgdir/usr/share/libalpm/hooks/"

  cd "$srcdir"

  cp ../librewolf-cfg-comment-out-values.hook "$pkgdir/usr/share/libalpm/hooks/librewolf-cfg-comment-out-values.hook"
  cp ../librewolf-cfg-uncomment-out-values.hook "$pkgdir/usr/share/libalpm/hooks/librewolf-cfg-uncomment-out-values.hook"
  cp ../librewolf-cfg-comment-out-values.sh "$pkgdir/usr/share/libalpm/scripts/librewolf-cfg-comment-out-values.sh"
  cp ../librewolf-cfg-uncomment-out-values.sh "$pkgdir/usr/share/libalpm/scripts/librewolf-cfg-uncomment-out-values.sh"

  # Set executable afterwards
  chmod +x "$pkgdir/usr/share/libalpm/scripts/librewolf-cfg-uncomment-out-values.sh"
  chmod +x "$pkgdir/usr/share/libalpm/scripts/librewolf-cfg-comment-out-values.sh"
}

# vim: ts=2 sw=2 et:

A  => README.md +91 -0
@@ 1,91 @@
# Librewolf 

When librewolf's defaults are way to strict and your custom values are lost during update.

Disable cfg values and polies by making sure they are commented out :)

Very simple design, feed a list of values and the hooks will sed it out.

## Why would you want this?

The browser [librewolf](https://librewolf-community.gitlab.io/) 
comes with very opinionated defaults. 
The defaults are fine tuned for maximum privacy and security but you might find 
few settings and policies that goes against your usecase.

For example, you might want
 * to enable DRM
 * to enable Firefox Sync for bookmarks only
 * to enable WebGL
 * to disable titlebar paint for dark GTK themes

This hook package will allow you to set your custom defaults are blocked
by checking `librewolf.cfg` and `policies.json` post install.

If there is a entry blocking you in any way, 
this package will allow you to undo the hardoced values. 

** But keep in mind ** 
It's not for setting up your values. 
You should do create a new files with your custom prefs your self.

Put your created files here
```
$ ls /usr/lib/librewolf/browser/defaults/preferences 
ctrl-q-disable.js          urlbar-suggestions.js  wayland.js
disable-drawInTiltebar.js 
```

## How it works

Any values blocked by `librewolf.cfg` and `policies.json` can be *unblocked* 
by commenting out the said value.

Many setting from `librewolf.cfg` and `policies.json` cannot bet set via `*.js` 
file at $HOME or at `/usr/lib/librewolf`

Basically this package will put 2 pacman hooks into the ALPM directories.

The first hook `/usr/share/libalpm/hooks/librewolf-apply-cfg-mod.hook` 
will be applied post install of this package and post upgrade of Librewolf itself.

The second hook `/usr/share/libalpm/hooks/librewolf-undo-cfg-mod.hook` will
undo every modification from first hook prior the Librewolf update. 

It's there to basically return the `librewolf.cfg` and `policies.json` 
back to stock to prevent any `*.pacnew` files from being created by deault.

Note - currently there is no backup() in the PKGBUILD of librewolf so undo-hook
is redundant, however that might change in future.

## Caveats and what to take pay more attention

`librewolf.cfg` states 

```
// "pref"           : Sets the preference as if a user had set it, every time you start the browser. So users can make changes,
//                    but they will be erased on restart. If you set a particular preference this way,
//                    it shows up in about:config as "user set".
```

however, any function call `pref();` from a `/usr/lib/librewolf/browser/defaults/preferences/*.js`
does behave more or less like "defaultPref" instead, so user changes done via GUI will be kept on restart.

Also `lockPref, lock_pref, defaultPref, default_pref` are not working function calls in `/usr/lib/librewolf/browser/defaults/preferences/*.js` so they have no effect but does work at `$HOME/.librewolf/user-profile/user.js`.


## TODOs for future? 

I am mostly responsive on mail `dach@protonmail.com` don't hesitate to ask, send PR or issue to me.

### Implementing some sort value changer for policies

Currently the `policies.json` can only comment out keys, not change a value.

The only scenario I can imagine that there is policy being set by librewolf 
	and is the same as the firefox default. 
You might want to set a different value.

Not implemented due to high complexity. Validating json + multiline parsing.



A  => librewolf-cfg-comment-out-values.hook +12 -0
@@ 1,12 @@
[Trigger]
Type = Package
Operation = Install
Operation = Upgrade
Target = personal-privacy-and-security
Target = librewolf

[Action]
Description = Commenting out values from librewolf.cfg and policy.json...
When = PostTransaction
Exec = /usr/share/libalpm/scripts/librewolf-cfg-comment-out-values.sh
Depends = librewolf

A  => librewolf-cfg-comment-out-values.sh +23 -0
@@ 1,23 @@
#!/bin/sh

POLICY_FILE=/usr/lib/librewolf/distribution/policies.json
CFG_FILE=/usr/lib/librewolf/librewolf.cfg

POLICY_MOD_FILE=/usr/lib/librewolf/distribution/policies.json-comment-out-list
CFG_MOD_FILE=/usr/lib/librewolf/librewolf.cfg-comment-out-list

touch $CFG_MOD_FILE
touch $POLICY_MOD_FILE

while IFS= read -r line
do
  sed -i "s/^lockPref(\"$line\"/\/\/lockPref(\"$line\"/g" $CFG_FILE
done < $CFG_MOD_FILE


while IFS= read -r line
do
	sed -i "s/\"$line\":/\"__COMMENT__ $line\":/g" $POLICY_FILE
done < $POLICY_MOD_FILE

# vim:fileencoding=utf-8:ts=2:shiftwidth=2

A  => librewolf-cfg-uncomment-out-values.hook +10 -0
@@ 1,10 @@
[Trigger]
Type = Package
Operation = Upgrade
Target = librewolf

[Action]
Description = Reverting comments to cfg and policy before librewolf upgrades... 
When = PreTransaction
Exec = /usr/share/libalpm/scripts/librewolf-cfg-uncomment-out-value.sh
Depends = librewolf

A  => librewolf-cfg-uncomment-out-values.sh +19 -0
@@ 1,19 @@
#!/bin/sh

POLICY_FILE=/usr/lib/librewolf/distribution/policies.json
CFG_FILE=/usr/lib/librewolf/librewolf.cfg

POLICY_MOD_FILE=/usr/lib/librewolf/distribution/policies.json-comment-out-list
CFG_MOD_FILE=/usr/lib/librewolf/librewolf.cfg-comment-out-list

while IFS= read -r line
do
  sed -i "s/\/\/lockPref(\"$line\"/lockPref(\"$line\"/g" $CFG_FILE
done < $CFG_MOD_FILE

while IFS= read -r line
do
	sed -i "s/\"__COMMENT__ $line\":/\"$line\":/g" $POLICY_FILE
done < $POLICY_MOD_FILE

# vim:fileencoding=utf-8:ts=2:shiftwidth=2