Skip to content

Commit

Permalink
Merge pull request #4389 from rusty-snake/profcleaner.sh
Browse files Browse the repository at this point in the history
Create profcleaner.sh
  • Loading branch information
netblue30 committed Jul 8, 2021
2 parents 665023e + 1bb3f61 commit 00cb8b6
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/tools/profcleaner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

# Copyright (C) 2021 Firejail Authors
#
# This file is part of firejail project
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# 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, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

if [[ $1 == --help ]]; then
cat <<-EOM
USAGE:
profcleaner.sh --help Show this help message and exit
profcleaner.sh --system Clean all profiles in /etc/firejail
profcleaner.sh --user Clean all profiles in ~/.config/firejail
profcleaner.sh /path/to/profile1 /path/to/profile2 ...
EOM
exit 0
fi

if [[ $1 == --system ]]; then
profiles=(/etc/firejail/*.{inc,local,profile})
elif [[ $1 == --user ]]; then
profiles=("$HOME"/.config/firejail/*.{inc,local,profile})
else
profiles=("$@")
fi

sed -i \
-e "s/^blacklist/deny/" \
-e "s/^noblacklist/nodeny/" \
-e "s/^whitelist/allow/" \
-e "s/^nowhitelist/noallow/" \
"${profiles[@]}"

7 comments on commit 00cb8b6

@curiosityseeker
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, wouldn't it be better to remove the caret in the sed lines? Right now commented lines with blacklist/noblacklist/whitelist/nowhitelist instructions will not be handled by this script. Example: lines 29 + 30 in firefox.profile

@rusty-snake
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, think of include whitelist-common.inc for example. However we can extend it to also change #whitelist and # whitelist (and so on).

@curiosityseeker
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right - I missed that. And yes, extending the script to include those other cases would make sense, indeed.

@rusty-snake
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"s/^(# |#)?whitelist/\1allow/" what do you think (requires -E)?

@curiosityseeker
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should work.

One question: Is there a reason why the whitelist-*.inc files have not been renamed?

@rusty-snake
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rusty-snake
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: 0b31c41

Please sign in to comment.