base-files: split /etc/profile
authorKonstantin Demin <[email protected]>
Thu, 4 Sep 2025 12:36:56 +0000 (15:36 +0300)
committerRobert Marko <[email protected]>
Thu, 20 Nov 2025 16:48:18 +0000 (17:48 +0100)
- move extra parts to /etc/profile.d/*
- improve syntax and messages

Signed-off-by: Konstantin Demin <[email protected]>
Link: https://github.com/openwrt/openwrt/pull/19953
Signed-off-by: Robert Marko <[email protected]>
package/base-files/files/etc/profile
package/base-files/files/etc/profile.d/00-passwordless-root.sh [new file with mode: 0644]
package/base-files/files/etc/profile.d/apk-cheatsheet.sh [new file with mode: 0644]

index f9acdb439fa63026fdc0c22cb2df991777ab1797..9ce59c87e917176c3d09b67adf91b0c90a63f7a3 100644 (file)
@@ -1,61 +1,38 @@
+unset FAILSAFE
 [ -e /tmp/.failsafe ] && export FAILSAFE=1
 
 [ -f /etc/banner ] && cat /etc/banner
-[ -n "$FAILSAFE" ] && cat /etc/banner.failsafe
+[ -n "$FAILSAFE" ] && [ -f /etc/banner.failsafe ] && cat /etc/banner.failsafe
 
-grep -Fsq '/ overlay ro,' /proc/mounts && {
-       echo 'Your JFFS2-partition seems full and overlayfs is mounted read-only.'
-       echo 'Please try to remove files from /overlay/upper/... and reboot!'
-}
+if grep -Fsq '/ overlay ro,' /proc/mounts ; then
+cat << EOF
+
+ === WARNING! ======================================
+ Your JFFS2-partition seems full and overlayfs is
+ mounted as READ-ONLY!
+ Please try to remove files from /overlay/upper/...
+ and reboot!
+ ---------------------------------------------------
+
+EOF
+fi
 
 export PATH="%PATH%"
-export HOME=$(grep -e "^${USER:-root}:" /etc/passwd | cut -d ":" -f 6)
-export HOME=${HOME:-/root}
+HOME=$(grep -E "^${USER:-root}:" /etc/passwd | cut -d ":" -f 6)
+HOME=${HOME:-/root}
+export HOME
 export PS1='\u@\h:\w\$ '
 export ENV=/etc/shinit
 
 case "$TERM" in
        xterm*|rxvt*)
-               export PS1='\[\e]0;\u@\h: \w\a\]'$PS1
-               ;;
+               export PS1='\[\e]0;\u@\h: \w\a\]'"$PS1"
+       ;;
 esac
 
-[ -n "$FAILSAFE" ] || {
-       for FILE in /etc/profile.d/*.sh; do
-               [ -e "$FILE" ] && . "$FILE"
+if [ -z "$FAILSAFE" ] ; then
+       for FILE in /etc/profile.d/*.sh ; do
+               [ -f "$FILE" ] && . "$FILE"
        done
        unset FILE
-}
-
-if ( grep -qs '^root::' /etc/shadow && \
-     [ -z "$FAILSAFE" ] )
-then
-cat << EOF
-=== WARNING! =====================================
-There is no root password defined on this device!
-Use the "passwd" command to set up a new password
-in order to prevent unauthorized SSH logins.
---------------------------------------------------
-EOF
-fi
-
-if [ -x /usr/bin/apk ]; then
-cat << EOF
-
- OpenWrt recently switched to the "apk" package manager!
-
- OPKG Command           APK Equivalent      Description
- ------------------------------------------------------------------
- opkg install <pkg>     apk add <pkg>       Install a package
- opkg remove <pkg>      apk del <pkg>       Remove a package
- opkg upgrade           apk upgrade         Upgrade all packages
- opkg files <pkg>       apk info -L <pkg>   List package contents
- opkg list-installed    apk info            List installed packages
- opkg update            apk update          Update package lists
- opkg search <pkg>      apk search <pkg>    Search for packages
- ------------------------------------------------------------------
-
-For more https://openwrt.org/docs/guide-user/additional-software/opkg-to-apk-cheatsheet
-
-EOF
 fi
diff --git a/package/base-files/files/etc/profile.d/00-passwordless-root.sh b/package/base-files/files/etc/profile.d/00-passwordless-root.sh
new file mode 100644 (file)
index 0000000..fe98045
--- /dev/null
@@ -0,0 +1,11 @@
+if grep -Esq '^root::' /etc/shadow ; then
+cat << EOF
+
+ === WARNING! =====================================
+ There is no root password defined on this device!
+ Use the "passwd" command to set up a new password
+ in order to prevent unauthorized SSH logins.
+ --------------------------------------------------
+
+EOF
+fi
diff --git a/package/base-files/files/etc/profile.d/apk-cheatsheet.sh b/package/base-files/files/etc/profile.d/apk-cheatsheet.sh
new file mode 100644 (file)
index 0000000..4193367
--- /dev/null
@@ -0,0 +1,21 @@
+if [ -x /usr/bin/apk ] ; then
+cat << EOF
+
+ OpenWrt recently switched to the "apk" package manager!
+
+ OPKG Command           APK Equivalent      Description
+ ------------------------------------------------------------------
+ opkg install <pkg>     apk add <pkg>       Install a package
+ opkg remove <pkg>      apk del <pkg>       Remove a package
+ opkg upgrade           apk upgrade         Upgrade all packages
+ opkg files <pkg>       apk info -L <pkg>   List package contents
+ opkg list-installed    apk info            List installed packages
+ opkg update            apk update          Update package lists
+ opkg search <pkg>      apk search <pkg>    Search for packages
+ ------------------------------------------------------------------
+
+For more information visit:
+https://openwrt.org/docs/guide-user/additional-software/opkg-to-apk-cheatsheet
+
+EOF
+fi