#!/bin/sh
# $FreeWRT$

if ! grep /bin/mksh ${IPKG_INSTROOT}/etc/shells >/dev/null 2>&1; then
	echo /bin/mksh >>${IPKG_INSTROOT}/etc/shells
fi

if ! grep KSH_VERSION ${IPKG_INSTROOT}/etc/profile >/dev/null 2>&1; then
	echo 'if test -n "$KSH_VERSION"; then' >>${IPKG_INSTROOT}/etc/profile
	echo '	[[ -z $HOSTNAME ]] && export HOSTNAME=$(</proc/sys/kernel/hostname)' >>${IPKG_INSTROOT}/etc/profile
	echo '	export PS1='\''$(((rv=$?)) && print $rv\|)'\''"\$USER@${HOSTNAME:-noFQDN}:"'\''$(' >>${IPKG_INSTROOT}/etc/profile
	echo '		typeset tilde=~ path=${1:-${PWD:-$(pwd)}}' >>${IPKG_INSTROOT}/etc/profile
	echo '		typeset dots= path2=${path#$tilde}' >>${IPKG_INSTROOT}/etc/profile
	echo '		[[ $path2 = $path || -z $tilde || $tilde = / ]] || path=\~$path2' >>${IPKG_INSTROOT}/etc/profile
	echo '		let cmax="${COLUMNS:-80} / 3"' >>${IPKG_INSTROOT}/etc/profile
	echo '		(( cmax < 7 )) && let cmax=7' >>${IPKG_INSTROOT}/etc/profile
	echo '		while (( (${#dots} + ${#path}) > cmax )); do' >>${IPKG_INSTROOT}/etc/profile
	echo '			if [[ $path = *@(/)* ]]; then' >>${IPKG_INSTROOT}/etc/profile
	echo '				dots=.../' >>${IPKG_INSTROOT}/etc/profile
	echo '				path="${path#*/}"' >>${IPKG_INSTROOT}/etc/profile
	echo '			else' >>${IPKG_INSTROOT}/etc/profile
	echo '				dots=...' >>${IPKG_INSTROOT}/etc/profile
	echo '				path="${path#?????}"' >>${IPKG_INSTROOT}/etc/profile
	echo '			fi' >>${IPKG_INSTROOT}/etc/profile
	echo '		done' >>${IPKG_INSTROOT}/etc/profile
	echo '		print -nr -- "$dots$path")'\''" $(if (( $(id -u) )); then' >>${IPKG_INSTROOT}/etc/profile
	echo '			print -n \$; else print -n \#; fi) "' >>${IPKG_INSTROOT}/etc/profile
	echo 'fi' >>${IPKG_INSTROOT}/etc/profile
fi
