bash: Enable system-wide .bashrc file, source /etc/shinit 11993/head
authorJeffery To <jeffery.to@gmail.com>
Tue, 28 Apr 2020 20:31:03 +0000 (04:31 +0800)
committerJeffery To <jeffery.to@gmail.com>
Tue, 28 Apr 2020 20:38:24 +0000 (04:38 +0800)
This enables a system-wide .bashrc file (/etc/bash.bashrc), as well as
some other options related to startup files, and sources /etc/shinit for
interactive shells.

Fixes https://bugs.openwrt.org/index.php?do=details&task_id=3019.

Signed-off-by: Jeffery To <jeffery.to@gmail.com>
utils/bash/Makefile
utils/bash/files/etc/bash.bashrc [new file with mode: 0644]
utils/bash/files/etc/profile.d/sys_bashrc.sh [new file with mode: 0644]
utils/bash/patches/901-startup-files.patch [new file with mode: 0644]

index ad1eab364da80f09dd3c1aadc52e1e4717fbc7a1..4bc4acf499c4991a479d65e24088ed65af125bc1 100644 (file)
@@ -39,6 +39,11 @@ define Package/bash/description
   incorporates useful features from the Korn and C shells (ksh and csh).
 endef
 
+define Package/bash/conffiles
+/etc/bash.bashrc
+/etc/bash.bash_logout
+endef
+
 # Bash detects and enables certain features by runtest simple piece of code
 # which is not viable when doing cross compilation and default to no in many
 # cases.  Grep for 'cross.compil' in aclocal.m4 and config-bot.h for details
@@ -89,6 +94,7 @@ define Package/bash/install
        $(INSTALL_DIR) $(1)/bin
        $(INSTALL_BIN) $(PKG_INSTALL_DIR)/bin/bash $(1)/bin/
        $(LN) bash $(1)/bin/rbash
+       $(CP) ./files/* $(1)/
 endef
 
 $(eval $(call BuildPackage,bash))
diff --git a/utils/bash/files/etc/bash.bashrc b/utils/bash/files/etc/bash.bashrc
new file mode 100644 (file)
index 0000000..158deaa
--- /dev/null
@@ -0,0 +1,6 @@
+# System-wide .bashrc file
+
+# Continue if running interactively
+[[ $- == *i* ]] || return 0
+
+[ \! -s /etc/shinit ] || . /etc/shinit
diff --git a/utils/bash/files/etc/profile.d/sys_bashrc.sh b/utils/bash/files/etc/profile.d/sys_bashrc.sh
new file mode 100644 (file)
index 0000000..5c06bb5
--- /dev/null
@@ -0,0 +1 @@
+[ -z "$BASH" ] || [ "$BASH" = /bin/sh ] || [ \! -s /etc/bash.bashrc ] || . /etc/bash.bashrc
diff --git a/utils/bash/patches/901-startup-files.patch b/utils/bash/patches/901-startup-files.patch
new file mode 100644 (file)
index 0000000..f15d923
--- /dev/null
@@ -0,0 +1,27 @@
+--- a/config-top.h
++++ b/config-top.h
+@@ -91,20 +91,20 @@
+ #define DEFAULT_BASHRC "~/.bashrc"
+ /* System-wide .bashrc file for interactive shells. */
+-/* #define SYS_BASHRC "/etc/bash.bashrc" */
++#define SYS_BASHRC "/etc/bash.bashrc"
+ /* System-wide .bash_logout for login shells. */
+-/* #define SYS_BASH_LOGOUT "/etc/bash.bash_logout" */
++#define SYS_BASH_LOGOUT "/etc/bash.bash_logout"
+ /* Define this to make non-interactive shells begun with argv[0][0] == '-'
+    run the startup files when not in posix mode. */
+-/* #define NON_INTERACTIVE_LOGIN_SHELLS */
++#define NON_INTERACTIVE_LOGIN_SHELLS
+ /* Define this if you want bash to try to check whether it's being run by
+    sshd and source the .bashrc if so (like the rshd behavior).  This checks
+    for the presence of SSH_CLIENT or SSH2_CLIENT in the initial environment,
+    which can be fooled under certain not-uncommon circumstances. */
+-/* #define SSH_SOURCE_BASHRC */
++#define SSH_SOURCE_BASHRC
+ /* Define if you want the case-capitalizing operators (~[~]) and the
+    `capcase' variable attribute (declare -c). */