From 49a8e9687ffdb779c611b378575370ee859893f9 Mon Sep 17 00:00:00 2001 From: Zdenek Behan Date: Wed, 7 Dec 2011 13:27:34 +0100 Subject: [PATCH] upgrade hook: move PS1 niceties from .bashrc to profile.d This solves two problems (and half): a) messing with user's preference file is a no-no, if we want a hardcoded behaviour like this, profile.d is the way to go b) .bashrc settings are overridden when doing env-update; source /etc/profile c) profile.d will also apply to root (although not with sudo su) BUG=none TEST=below 1) ./run_chroot_version_hooks --version 21 2) see all fixed, source /etc/profile, and still see my prompt unchanged Change-Id: I25b4602f4951b17815bcd312a8249320784c67e1 Reviewed-on: https://gerrit.chromium.org/gerrit/12539 Reviewed-by: Mike Frysinger Tested-by: Zdenek Behan Commit-Ready: Zdenek Behan --- chroot_version_hooks.d/22_trim_bashrc | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 chroot_version_hooks.d/22_trim_bashrc diff --git a/chroot_version_hooks.d/22_trim_bashrc b/chroot_version_hooks.d/22_trim_bashrc new file mode 100644 index 0000000000..68a01c6f71 --- /dev/null +++ b/chroot_version_hooks.d/22_trim_bashrc @@ -0,0 +1,24 @@ +# Copyright (c) 2011 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# We used to place bashrc niceties into the user's .bashrc. Use +# profile.d instead. + +sudo_clobber /etc/profile.d/chromiumos-niceties.sh << EOF +# Niceties for interactive logins. (cr) denotes this is a chroot, the +# __git_branch_ps1 prints current git branch in ./ . The $r behavior is to +# make sure we don't reset the previous $? value which later formats in +# $PS1 might rely on. +PS1='\$(r=\$?; __git_branch_ps1 "(%s) "; exit \$r)'"\${PS1}" +PS1="(cr) \${PS1}" +EOF + +# Also, get rid of the leftover stuff in the user's .bashrc. +# These are the two originally added lines: +STR1='export PS1='"'"'$(r=$?; __git_branch_ps1 "(%s) "; exit $r)'"'"'"${PS1}"' +STR2='export PS1="(cr) ${PS1}"' + +sed -e "/${STR1}/d" -e "/${STR2}/d" -i ~/.bashrc + +exit 0