Skip to content

Instantly share code, notes, and snippets.

@ansemjo
Last active April 19, 2019 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ansemjo/63100f63c4a25a7c1e7cad38913ec6b9 to your computer and use it in GitHub Desktop.
Save ansemjo/63100f63c4a25a7c1e7cad38913ec6b9 to your computer and use it in GitHub Desktop.
ash profile for OpenWRT devices
#!/bin/ash
# banners
[ -f /etc/banner ] && cat /etc/banner
[ -e /tmp/.failsafe ] && cat /etc/banner.failsafe
fgrep -sq '/ 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!'
}
# sysinfo
device=$(sed -n 's/.*"name": "\(.*\)"$/\1/p' /etc/board.json)
release=$(sed -n "s/.*DISTRIB_TARGET='\(.*\)'$/\1/p" /etc/openwrt_release)
updates=$(sed -n '/_core/s|.*\(://.*/targets/[a-z0-9]\+/[a-z0-9]\+/\).*|https\1|p' /etc/opkg/distfeeds.conf)
kernel=$(uname -mrsvo)
echo " device : $device"
echo " images : $updates"
echo " kernel : $kernel"
echo " uptime :$(uptime)"
echo
# environment
export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
export HOME=$(grep -e "^${USER:-root}:" /etc/passwd | cut -d ":" -f 6)
export HOME=${HOME:-/root}
# prompt line
export PS1="\e[0;1m\H \e[38;5;9m\w \e[0;1m\\$ \e[0m"
case "$TERM" in xterm*) export PS1='\[\e]0;\u@\h: \w\a\]'"$PS1" ;; esac
# aliases
[ -x /bin/more ] || alias more=less
[ -x /usr/bin/vim ] && alias vi=vim
alias ls='ls --color=auto'
alias ll='ls -alF' # all, long, classify; pretty verbose
alias lll='ls -lhARF' # dirlist, generates huge output for many subfolders!
# safeguard
alias rm='rm -i'
alias mv='mv -i'
alias cp='cp -i'
[ -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 $*; }
# enter temporary directory
alias tmp='cd `mktemp -d`'
# help the dropbear ssh client ..
alias ssh='ssh -i /root/.ssh/id_rsa'
alias scp='scp -i /root/.ssh/id_rsa'
# show status of network ports
alias ports='swconfig dev switch0 show | grep "link:" | sed "s/^[\t]*link: port:/port /"'
# Load more profiles
[ -n "$FAILSAFE" ] || {
for FILE in /etc/profile.d/*.sh; do
[ -e "$FILE" ] && . "$FILE"
done
unset FILE
}
# Password warning
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
@ansemjo
Copy link
Author

ansemjo commented Mar 20, 2019

sample:

Screenshot from 2019-03-20 20-36-51

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment