← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad-layers:change-shell into launchpad-layers:main

 

Colin Watson has proposed merging ~cjwatson/launchpad-layers:change-shell into launchpad-layers:main.

Commit message:
Change the launchpad user's shell to /bin/bash

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad-layers/+git/launchpad-layers/+merge/439705

The `ols` layer creates this as a system user since it has no password, leaving its shell at the default of `/bin/sh`.  For a user that's never used interactively, that's fine.  However, at least some deployments based on this layer will end up being used interactively, especially `launchpad-admin`, so change the shell to `/bin/bash` so that it's more pleasant to do so.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad-layers:change-shell into launchpad-layers:main.
diff --git a/launchpad-base/lib/charms/launchpad/base.py b/launchpad-base/lib/charms/launchpad/base.py
index 1fb2815..fbdf2fd 100644
--- a/launchpad-base/lib/charms/launchpad/base.py
+++ b/launchpad-base/lib/charms/launchpad/base.py
@@ -32,6 +32,21 @@ def var_dir():
     return os.path.join(base.base_dir(), "var")
 
 
+def change_shell(user, shell):
+    if (
+        subprocess.run(
+            ["getent", "passwd", user],
+            capture_output=True,
+            check=True,
+            text=True,
+        )
+        .stdout.splitlines()[0]
+        .split(":")[6]
+        != shell
+    ):
+        subprocess.run(["chsh", "-s", shell, user], check=True)
+
+
 def ensure_lp_directories():
     for dirpath in oopses_dir(), var_dir():
         host.mkdir(dirpath, group=base.user(), perms=0o775)
diff --git a/launchpad-base/reactive/launchpad-base.py b/launchpad-base/reactive/launchpad-base.py
index a6c6fa9..4bec15d 100644
--- a/launchpad-base/reactive/launchpad-base.py
+++ b/launchpad-base/reactive/launchpad-base.py
@@ -5,6 +5,7 @@ import subprocess
 
 from charmhelpers.core import hookenv
 from charms.launchpad.base import (
+    change_shell,
     configure_lazr,
     configure_rsync,
     ensure_lp_directories,
@@ -76,6 +77,9 @@ def rabbitmq_unavailable():
 def configure():
     db = endpoint_from_flag("db.master.available")
     rabbitmq = endpoint_from_flag("rabbitmq.available")
+    # Interactive use shouldn't be frequent, but it's still needed
+    # sometimes, so make it less annoying.
+    change_shell(base.user(), "/bin/bash")
     ensure_lp_directories()
     config = get_service_config()
     db_primary, db_standby = postgres.get_db_uris(db)