delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/09/04/18:00:45

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00
X-Spam-Check-By: sourceware.org
Message-ID: <4AA18DE9.50800@t-online.de>
Date: Sat, 05 Sep 2009 00:00:09 +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.8.1.21) Gecko/20090403 SeaMonkey/1.1.16
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Set root shell prompt in /etc/profile ?
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

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

When running as member of admin group a Cygwin process normally has 
root-like privileges. But this fact cannot be checked with 'geteuid() == 
0'. The shell never sets the default root prompt '#', except if the user 
is mapped to uid 0 in /etc/passwd.

Is there a generic way to set '#' via /etc/profile ?

The attached patch works for me on Cygwin 1.7., but it relies on a 
runtime file write check.
(It also requires ACL support in /tmp and would not work on 1.5).

Is there a better way to do this?

Christian


--------------090502020603000700030601
Content-Type: text/x-patch;
 name="set-root-prompt.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="set-root-prompt.patch"

--- /etc/profile.orig	2009-07-13 20:50:01.875000000 +0200
+++ /etc/profile	2009-09-04 23:57:16.578125000 +0200
@@ -84,6 +84,18 @@
 # CVSROOT=:pserver:anoncvs AT sources DOT redhat DOT com:/cvs/src
 # export CVSROOT
 
+# Set root prompt if shell can write to readonly file
+# (does only work if /tmp uses ACLs)
+f=/tmp/etc-profile-$$
+echo > "$f"
+chmod a=r "$f"
+if (echo > "$f") 2>/dev/null; then
+  PS1='# '
+else
+  PS1='$ '
+fi
+rm -f "$f"
+
 # Shell dependent settings
 case "`echo "_$0" | /usr/bin/tr '[:upper:]' '[:lower:]' | /usr/bin/sed -e 's/^_//'`" in
 bash     | -bash     | */bash | \
@@ -93,7 +105,7 @@
 	export HOSTNAME
 
 	# 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'"$PS1"
 	;;
 ksh*     | -ksh*     | */ksh* | \
 ksh*.exe | -ksh*.exe | */ksh*.exe )
@@ -103,12 +115,12 @@
 	# Set a default prompt of: user AT host and current_directory
 	PS1='^[]0;${PWD}^G
 ^[[32m${USER}@${HOSTNAME} ^[[33m${PWD}^[[0m
-$ '
+'"$PS1"
 	;;
 zsh*     | -zsh*     | */zsh* | \
 zsh*.exe | -zsh*.exe | */zsh*.exe )
 	# Set a default prompt of: user AT host, a command counter, and current_directory
-	PS1='(%n@%m)[%h] %~ %% '
+	PS1='(%n@%m)[%h] %~ '"${PS1/$/%%}"
 	
 	# Set SHELL if not set
 	if [ ! -z "${ZSH_NAME}" -a -z "${SHELL}" ]; then
@@ -118,8 +130,7 @@
 	;;
 sh     | -sh     | */sh | \
 sh.exe | -sh.exe | */sh.exe )
-	# Set a simple prompt
-	PS1='$ '
+	# Keep the simple prompt
 	;;
 * )
 	# Sorry, this shell has no defaults in /etc/profile,
@@ -131,7 +142,6 @@
 
 	# Thanks
 	
-	PS1='$ '
 	;;
 esac
 


--------------090502020603000700030601
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
--------------090502020603000700030601--

- Raw text -


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