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

Proposed by Colin Watson
Status: Merged
Merged at revision: 1920a6f823d8d882a99662bdda55f67f37359850
Proposed branch: ~cjwatson/launchpad-layers:change-shell
Merge into: launchpad-layers:main
Diff against target: 48 lines (+19/-0)
2 files modified
launchpad-base/lib/charms/launchpad/base.py (+15/-0)
launchpad-base/reactive/launchpad-base.py (+4/-0)
Reviewer Review Type Date Requested Status
Guruprasad Approve
Review via email: mp+439705@code.launchpad.net

Commit message

Change the launchpad user's shell to /bin/bash

Description of the change

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.

To post a comment you must log in.
Revision history for this message
Guruprasad (lgp171188) wrote :

LGTM 👍🏼

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/launchpad-base/lib/charms/launchpad/base.py b/launchpad-base/lib/charms/launchpad/base.py
2index 1fb2815..fbdf2fd 100644
3--- a/launchpad-base/lib/charms/launchpad/base.py
4+++ b/launchpad-base/lib/charms/launchpad/base.py
5@@ -32,6 +32,21 @@ def var_dir():
6 return os.path.join(base.base_dir(), "var")
7
8
9+def change_shell(user, shell):
10+ if (
11+ subprocess.run(
12+ ["getent", "passwd", user],
13+ capture_output=True,
14+ check=True,
15+ text=True,
16+ )
17+ .stdout.splitlines()[0]
18+ .split(":")[6]
19+ != shell
20+ ):
21+ subprocess.run(["chsh", "-s", shell, user], check=True)
22+
23+
24 def ensure_lp_directories():
25 for dirpath in oopses_dir(), var_dir():
26 host.mkdir(dirpath, group=base.user(), perms=0o775)
27diff --git a/launchpad-base/reactive/launchpad-base.py b/launchpad-base/reactive/launchpad-base.py
28index a6c6fa9..4bec15d 100644
29--- a/launchpad-base/reactive/launchpad-base.py
30+++ b/launchpad-base/reactive/launchpad-base.py
31@@ -5,6 +5,7 @@ import subprocess
32
33 from charmhelpers.core import hookenv
34 from charms.launchpad.base import (
35+ change_shell,
36 configure_lazr,
37 configure_rsync,
38 ensure_lp_directories,
39@@ -76,6 +77,9 @@ def rabbitmq_unavailable():
40 def configure():
41 db = endpoint_from_flag("db.master.available")
42 rabbitmq = endpoint_from_flag("rabbitmq.available")
43+ # Interactive use shouldn't be frequent, but it's still needed
44+ # sometimes, so make it less annoying.
45+ change_shell(base.user(), "/bin/bash")
46 ensure_lp_directories()
47 config = get_service_config()
48 db_primary, db_standby = postgres.get_db_uris(db)

Subscribers

People subscribed via source and target branches