Commit d4d5d8a5 authored by m3hm00d's avatar m3hm00d
Browse files

Better separation of output, logic, and library functions

1. 51-update-bash.bashrc:
- Add comment to '/etc/bashrc' ('The following code is added by XYZ
script').
- Removal of OPTS_FILE variable.

2. replace-su-with-sudo.sh:
- Updated comment to better describe the role of this script.
- Moved output stuff to '/usr/local/bin/replace-su-with-sudo'.
- Moved translation stuff to '/usr/local/bin/replace-su-with-sudo'.
- 'su' function will now simply call the 'replace-su-with-sudo' script.

3. replace-su-with-sudo:
- Created new script
- It handles the logic and output (with translation) of 'Please use sudo
instead' message.

4. tails_is_password_set.py
- Moved from /usr/local/bin/ to /usr/local/lib/python3/dist-packages/
- Removed main() function. This file is now just a library; not meant to
be executed as a standalone script.

5. 'POTFILES.in' and 'refresh-translations':
- Modified to accommodate the changes made in 'replace-su-with-sudo.sh'
and 'replace-su-with-sudo'.
parent 78735b9d
......@@ -7,9 +7,8 @@ set -u
echo "Updating /etc/bash.bashrc"
OPTS_FILE='/etc/bash.bashrc'
cat <<EOF>> "${OPTS_FILE}"
cat <<EOF>> /etc/bash.bashrc
# The following code snippet is added by 'config/chroot_local-hooks/51-update-bash.bashrc'
for file in /etc/bash.bashrc.d/*;
do
......
......@@ -6,28 +6,16 @@
# users in particular may be puzzled by the authentication failures
# while trying to 'su' using administration password.
#
# This script introduces 'su' function for non-root users which asks
# This script introduces 'su' function for non-root users. The 'su'
# function executes '/usr/local/bin/replace-su-with-sudo', which asks
# them to use 'sudo' instead of 'su'.
#
# https://redmine.tails.boum.org/code/issues/15583
# Get LANG
. /etc/default/locale
export LANG
# Initialize gettext support
. gettext.sh
TEXTDOMAIN="tails"
export TEXTDOMAIN
# Since we don't want to add 'su' function for root user, we will stop
# execution of this script if $USER is root.
[ "$USER" == root ] && return
su (){
if tails_is_password_set.py; then
echo "`gettext \"su is disabled. Please use sudo instead.\"`"
else
cat /usr/share/tails-greeter/no-password-lecture.txt
fi
/usr/local/bin/replace-su-with-sudo
}
#!/usr/bin/env python3
import gettext
from tails_is_password_set import is_password_set
def main() -> None:
if is_password_set():
print(_('"su is disabled. Please use sudo instead."'))
exit(0)
else:
print(open("/usr/share/tails-greeter/no-password-lecture.txt").read())
exit(1)
if __name__ == "__main__":
# Initialize translations
translation = gettext.translation("tails", fallback=True)
_ = translation.gettext
main()
......@@ -5,12 +5,3 @@ import subprocess
def is_password_set():
output = subprocess.check_output(["passwd", "--status"])
return output.split()[1] == b"P"
def main():
if is_password_set():
exit(0)
else:
exit(1)
if __name__ == "__main__":
main()
......@@ -20,7 +20,7 @@ tmp/pot/unsafe-browser.pot
tmp/pot/unlock-veracrypt-volumes-volume.py.pot
tmp/pot/unlock-veracrypt-volumes-volume_list.py.pot
tmp/pot/unlock-veracrypt-volumes-volume_manager.py.pot
tmp/pot/replace-su-with-sudo.sh.pot
tmp/pot/replace-su-with-sudo.pot
# Files updated by intltool-update --desktop-style
config/chroot_local-includes/etc/skel/Desktop/Report_an_error.desktop.in
......
......@@ -17,13 +17,13 @@ PYTHON_PROGS="/etc/whisperback/config.py \
/usr/local/lib/python3/dist-packages/unlock_veracrypt_volumes/volume_list.py \
/usr/local/lib/python3/dist-packages/unlock_veracrypt_volumes/volume_manager.py
/usr/local/lib/tails-additional-software-notify \
/usr/local/sbin/tails-additional-software"
/usr/local/sbin/tails-additional-software \
/usr/local/bin/replace-su-with-sudo"
SHELL_PROGS="/etc/NetworkManager/dispatcher.d/60-tor-ready.sh \
/usr/local/bin/keepassx \
/usr/local/lib/tails-spoof-mac \
/usr/local/bin/tor-browser \
/usr/local/sbin/unsafe-browser \
/etc/bash.bashrc.d/replace-su-with-sudo.sh"
/usr/local/sbin/unsafe-browser"
JAVASCRIPT_PROGS=" \
/usr/share/gnome-shell/extensions/status-menu-helper@tails.boum.org/extension.js \
/usr/share/gnome-shell/extensions/torstatus@tails.boum.org/extension.js \
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment