Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warn users on debian if they are running with a non-default user #4051

Merged
merged 5 commits into from
Jul 27, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions bin/kalite
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ import subprocess
from distutils import spawn
import warnings


# Python 2+3 definition
try:
input = raw_input # @ReservedAssignment
except NameError:
pass

kalite_path = None

# Ensure that PATH is set because distutils.find_executable fails on
Expand Down Expand Up @@ -78,6 +85,30 @@ if not os.path.exists(kalite_path):
# Converts to normal string for Windows users, where it gets turned into a unicode string and errors out in subprocess
env['KALITE_DIR'] = str(kalite_path)

# TODO(benjaoming): Delegate responsibility to the .deb package
# This always evaluates to False on Windows, so no problem with the
# system-specific path
if os.name == "posix" and os.path.isfile("/etc/ka-lite/username"):
username = open("/etc/ka-lite/username", "r").read()
username = username.split("\n")[0] if username else None
if username and username != os.environ["USER"]:
default_home = os.environ.get("KALITE_HOME", os.path.expanduser("~/.kalite"))
if not os.path.exists(default_home) or not os.listdir(default_home):
sys.stderr.write((
"You are not running kalite as the default user {0}. "
"This is recommended unless you want to re-create the database "
"and start storing new videos/exercises etc. for a different "
"user account\n\n"
).format(username))
sys.stderr.write((
"To run the command as the default user, run this instead:\n\n"
" sudo su {user} -s /bin/sh -c {command}\n\n"
).format(user=username, command=" ".join(sys.argv)))
cont = input("Do you wish to continue? [y/N] ")
if not cont.lower() == "y":
sys.exit(0)


if 'KALITE_PYTHON' in os.environ:
python_executable = os.environ['KALITE_PYTHON']
if not spawn.find_executable(python_executable):
Expand Down