delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2011/04/01/17:29:11

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-1.3 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY
X-Spam-Check-By: sourceware.org
Message-ID: <4D964392.6080809@t-online.de>
Date: Fri, 01 Apr 2011 23:28:50 +0200
From: Christian Franke <Christian DOT Franke AT t-online DOT de>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.17) Gecko/20110123 SeaMonkey/2.0.12
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: [PATCH] base-files-4.0.6: Change prompt if running with admin rights
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

--------------080206040800050506080705
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

The attached patch for /etc/profile and /etc/bash.bashrc sets a root 
prompt ('#' instead of '$' or '%') if the shell runs with admin rights 
(local or domain admin group).

Does not rely on a specific admin SID -> gid mapping in /etc/group.

Tested with bash, zsh, mksh, posh, dash.

Christian


--------------080206040800050506080705
Content-Type: text/x-diff;
 name="base-files-4.0-6-rootprompt.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="base-files-4.0-6-rootprompt.patch"

diff -rup base-files-4.0-6.orig/etc/defaults/etc/bash.bashrc base-files-4.0-6/etc/defaults/etc/bash.bashrc
--- base-files-4.0-6.orig/etc/defaults/etc/bash.bashrc	2011-03-17 21:30:38.000000000 +0100
+++ base-files-4.0-6/etc/defaults/etc/bash.bashrc	2011-03-31 15:38:12.000000000 +0200
@@ -16,7 +16,7 @@
 [[ "$-" != *i* ]] && return
 
 # Set a default prompt of: user AT host and current_directory
-PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$ '
+PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n'"${PS1a:-\\\$ }"
 
 # Uncomment to use the terminal colours set in DIR_COLORS
 # eval "$(dircolors -b /etc/DIR_COLORS)"
diff -rup base-files-4.0-6.orig/etc/defaults/etc/profile base-files-4.0-6/etc/defaults/etc/profile
--- base-files-4.0-6.orig/etc/defaults/etc/profile	2011-03-18 17:59:18.000000000 +0100
+++ base-files-4.0-6/etc/defaults/etc/profile	2011-03-31 23:06:38.953125000 +0200
@@ -85,6 +85,16 @@ else
   cd "${HOME}" || echo "WARNING: Failed attempt to cd into ${HOME}!"
 fi
 
+# Set PS1a if user is in local or domain admin group
+unset PS1a
+grps="$(id -G 2>/dev/null)"
+for g in $(sed -n 's,^[^:]*:S-1-5\(-32-544\|-21-[^:]*-512\):\([0-9]*\):.*$,\2,p' /etc/group 2>/dev/null); do
+  case " $grps " in
+    *\ $g\ *) PS1a="# "; break;;
+  esac
+done
+unset g grps
+
 # Shell dependent settings
 profile_d ()
 {
@@ -104,19 +114,20 @@ if [ ! "x${BASH_VERSION}" = "x"  ]; then
 elif [ ! "x${KSH_VERSION}" = "x" ]; then
   typeset -l HOSTNAME=$(/usr/bin/hostname)
   profile_d sh
-  PS1=$(print '\033]0;${PWD}\n\033[32m${USER}@${HOSTNAME} \033[33m${PWD/${HOME}/~}\033[0m\n$ ')
+  PS1=$(print '\033]0;${PWD}\n\033[32m${USER}@${HOSTNAME} \033[33m${PWD/${HOME}/~}\033[0m\n'"${PS1a:-\$ }")
 elif [ ! "x${ZSH_VERSION}" = "x" ]; then
   HOSTNAME=$(/usr/bin/hostname)
   profile_d zsh
-  PS1='(%n@%m)[%h] %~ %% '
+  PS1='(%n@%m)[%h] %~ '"${PS1a:-%% }"
 elif [ ! "x${POSH_VERSION}" = "x" ]; then
   HOSTNAME=$(/usr/bin/hostname)
-  PS1="$ "
+  PS1="${PS1a:-\$ }"
 else 
   HOSTNAME=$(/usr/bin/hostname) 
   profile_d sh
-  PS1="$ "
+  PS1="${PS1a:-\$ }"
 fi
+unset PS1a
 
 export PATH MANPATH INFOPATH USER TMP TEMP PRINTER HOSTNAME PS1 
 


--------------080206040800050506080705
Content-Type: text/plain; charset=us-ascii

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
--------------080206040800050506080705--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019