mirror of
https://github.com/openwrt/openwrt.git
synced 2025-01-19 11:16:32 +00:00
base-files: Add /etc/shinit for non-login shell init
Because /etc/profile (and ~/.profile) are read by login shells only, aliases and functions defined there are not available to non-login shells, e.g. when using screen or tmux. If the ENV environment variable exists (exported by /etc/profile or ~/.profile) and references an existing file, then all interactive shells (login or non-login) will read that file as well. This sets the ENV environment variable in /etc/profile, pointing to /etc/shinit. This also adds /etc/shinit, which: * Contains alias and function definitions originally in /etc/profile * Sources /etc/mkshrc if the user is using mksh (also originally in /etc/profile), as /etc/mkshrc is meant for all interactive shells * Sources ~/.mkshrc if the user is using mksh, to compensate for the fact that mksh will not read ~/.mkshrc if ENV is set * Sources ~/.shinit if the user is not using mksh This also removes the shebang from /etc/profile, as the file is sourced, not executed. Signed-off-by: Jeffery To <jeffery.to@gmail.com>
This commit is contained in:
parent
2c3c83e40b
commit
12020f8a95
@ -72,6 +72,7 @@ define Package/base-files/conffiles
|
|||||||
/etc/services
|
/etc/services
|
||||||
/etc/shadow
|
/etc/shadow
|
||||||
/etc/shells
|
/etc/shells
|
||||||
|
/etc/shinit
|
||||||
/etc/sysctl.conf
|
/etc/sysctl.conf
|
||||||
/etc/sysupgrade.conf
|
/etc/sysupgrade.conf
|
||||||
$(call $(TARGET)/conffiles)
|
$(call $(TARGET)/conffiles)
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
#!/bin/sh
|
|
||||||
[ -e /tmp/.failsafe ] && export FAILSAFE=1
|
[ -e /tmp/.failsafe ] && export FAILSAFE=1
|
||||||
|
|
||||||
[ -f /etc/banner ] && cat /etc/banner
|
[ -f /etc/banner ] && cat /etc/banner
|
||||||
@ -13,6 +12,7 @@ export PATH="%PATH%"
|
|||||||
export HOME=$(grep -e "^${USER:-root}:" /etc/passwd | cut -d ":" -f 6)
|
export HOME=$(grep -e "^${USER:-root}:" /etc/passwd | cut -d ":" -f 6)
|
||||||
export HOME=${HOME:-/root}
|
export HOME=${HOME:-/root}
|
||||||
export PS1='\u@\h:\w\$ '
|
export PS1='\u@\h:\w\$ '
|
||||||
|
export ENV=/etc/shinit
|
||||||
|
|
||||||
case "$TERM" in
|
case "$TERM" in
|
||||||
xterm*|rxvt*)
|
xterm*|rxvt*)
|
||||||
@ -20,16 +20,6 @@ case "$TERM" in
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
[ -x /bin/more ] || alias more=less
|
|
||||||
[ -x /usr/bin/vim ] && alias vi=vim || alias vim=vi
|
|
||||||
|
|
||||||
alias ll='ls -alF --color=auto'
|
|
||||||
|
|
||||||
[ -z "$KSH_VERSION" -o \! -s /etc/mkshrc ] || . /etc/mkshrc
|
|
||||||
|
|
||||||
[ -x /usr/bin/arp -o -x /sbin/arp ] || arp() { cat /proc/net/arp; }
|
|
||||||
[ -x /usr/bin/ldd ] || ldd() { LD_TRACE_LOADED_OBJECTS=1 $*; }
|
|
||||||
|
|
||||||
[ -n "$FAILSAFE" ] || {
|
[ -n "$FAILSAFE" ] || {
|
||||||
for FILE in /etc/profile.d/*.sh; do
|
for FILE in /etc/profile.d/*.sh; do
|
||||||
[ -e "$FILE" ] && . "$FILE"
|
[ -e "$FILE" ] && . "$FILE"
|
||||||
@ -48,12 +38,3 @@ in order to prevent unauthorized SSH logins.
|
|||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
EOF
|
EOF
|
||||||
fi
|
fi
|
||||||
|
|
||||||
service() {
|
|
||||||
[ -f "/etc/init.d/$1" ] || {
|
|
||||||
echo "service "'"'"$1"'"'" not found, the following services are available:"
|
|
||||||
ls "/etc/init.d"
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
/etc/init.d/$@
|
|
||||||
}
|
|
||||||
|
21
package/base-files/files/etc/shinit
Normal file
21
package/base-files/files/etc/shinit
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
[ -x /bin/more ] || alias more=less
|
||||||
|
[ -x /usr/bin/vim ] && alias vi=vim || alias vim=vi
|
||||||
|
|
||||||
|
alias ll='ls -alF --color=auto'
|
||||||
|
|
||||||
|
[ -z "$KSH_VERSION" -o \! -s /etc/mkshrc ] || . /etc/mkshrc
|
||||||
|
|
||||||
|
[ -x /usr/bin/arp -o -x /sbin/arp ] || arp() { cat /proc/net/arp; }
|
||||||
|
[ -x /usr/bin/ldd ] || ldd() { LD_TRACE_LOADED_OBJECTS=1 $*; }
|
||||||
|
|
||||||
|
service() {
|
||||||
|
[ -f "/etc/init.d/$1" ] || {
|
||||||
|
echo "service "'"'"$1"'"'" not found, the following services are available:"
|
||||||
|
ls "/etc/init.d"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
/etc/init.d/$@
|
||||||
|
}
|
||||||
|
|
||||||
|
[ -n "$KSH_VERSION" -o \! -s "$HOME/.shinit" ] || . "$HOME/.shinit"
|
||||||
|
[ -z "$KSH_VERSION" -o \! -s "$HOME/.mkshrc" ] || . "$HOME/.mkshrc"
|
@ -6,5 +6,6 @@
|
|||||||
/etc/profile
|
/etc/profile
|
||||||
/etc/shadow
|
/etc/shadow
|
||||||
/etc/shells
|
/etc/shells
|
||||||
|
/etc/shinit
|
||||||
/etc/sysctl.conf
|
/etc/sysctl.conf
|
||||||
/etc/rc.local
|
/etc/rc.local
|
||||||
|
Loading…
Reference in New Issue
Block a user