String padding

This commit is contained in:
Bob Mottram 2016-01-03 12:24:12 +00:00
parent d29885ebbc
commit 8ed901bac4
1 changed files with 32 additions and 29 deletions

View File

@ -114,72 +114,77 @@ function add_user {
fi fi
} }
function pad_string {
echo -n -e "$1" | sed -e :a -e 's/^.\{1,15\}$/& /;ta'
}
function show_domains { function show_domains {
echo 'Domains' echo 'Domains'
echo '=======' echo '======='
echo '' echo ''
if grep -q "Email onion domain" $COMPLETION_FILE; then if grep -q "Email onion domain" $COMPLETION_FILE; then
echo -n -e 'Email \t' echo -n -e "$(pad_string 'Email')"
echo -n -e "$(pad_string '')"
echo "$(cat ${COMPLETION_FILE} | grep 'Email onion domain' | awk -F ':' '{print $2}')" echo "$(cat ${COMPLETION_FILE} | grep 'Email onion domain' | awk -F ':' '{print $2}')"
fi fi
if grep -q "Wiki domain" $COMPLETION_FILE; then if grep -q "Wiki domain" $COMPLETION_FILE; then
echo -n -e 'Wiki \t' echo -n -e "$(pad_string 'Wiki')"
echo -n "$(cat ${COMPLETION_FILE} | grep 'Wiki domain' | awk -F ':' '{print $2}')" WIKIDOM=$(cat ${COMPLETION_FILE} | grep 'Wiki domain' | awk -F ':' '{print $2}')
echo -n -e '\t' echo -n -e "$(pad_string ${WIKIDOM})"
if [ -d /var/lib/tor/hidden_service_wiki ]; then if [ -d /var/lib/tor/hidden_service_wiki ]; then
echo -n "$(cat /var/lib/tor/hidden_service_wiki/hostname)" echo -n "$(cat /var/lib/tor/hidden_service_wiki/hostname)"
fi fi
echo '' echo ''
fi fi
if grep -q "Hubzilla domain" $COMPLETION_FILE; then if grep -q "Hubzilla domain" $COMPLETION_FILE; then
echo -n -e 'Hubzilla \t' echo -n -e "$(pad_string 'Hubzilla')"
echo -n "$(cat ${COMPLETION_FILE} | grep 'Hubzilla domain' | awk -F ':' '{print $2}')" HUBZILLADOM=$(cat ${COMPLETION_FILE} | grep 'Hubzilla domain' | awk -F ':' '{print $2}')
echo -n -e '\t' echo -n -e "$(pad_string ${HUBZILLADOM})"
if [ -d /var/lib/tor/hidden_service_hubzilla ]; then if [ -d /var/lib/tor/hidden_service_hubzilla ]; then
echo -n "$(cat /var/lib/tor/hidden_service_hubzilla/hostname)" echo -n "$(cat /var/lib/tor/hidden_service_hubzilla/hostname)"
fi fi
echo '' echo ''
fi fi
if grep -q "Blog domain" $COMPLETION_FILE; then if grep -q "Blog domain" $COMPLETION_FILE; then
echo -n -e 'Blog \t' echo -n -e "$(pad_string 'Blog')"
echo -n "$(cat ${COMPLETION_FILE} | grep 'Blog domain' | awk -F ':' '{print $2}')" BLOGDOM=$(cat ${COMPLETION_FILE} | grep 'Blog domain' | awk -F ':' '{print $2}')
echo -n -e '\t' echo -n -e "$(pad_string ${BLOGDOM})"
if [ -d /var/lib/tor/hidden_service_blog ]; then if [ -d /var/lib/tor/hidden_service_blog ]; then
echo -n "$(cat /var/lib/tor/hidden_service_blog/hostname)" echo -n "$(cat /var/lib/tor/hidden_service_blog/hostname)"
fi fi
echo '' echo ''
fi fi
if grep -q "GNU Social domain" $COMPLETION_FILE; then if grep -q "GNU Social domain" $COMPLETION_FILE; then
echo -n -e 'GNU Social\t' echo -n -e "$(pad_string 'GNU Social')"
echo -n "$(cat ${COMPLETION_FILE} | grep 'GNU Social domain' | awk -F ':' '{print $2}')" GNUSOCIALDOM=$(cat ${COMPLETION_FILE} | grep 'GNU Social domain' | awk -F ':' '{print $2}')
echo -n -e '\t' echo -n -e "$(pad_string ${GNUSOCIALDOM})"
if [ -d /var/lib/tor/hidden_service_microblog ]; then if [ -d /var/lib/tor/hidden_service_microblog ]; then
echo -n "$(cat /var/lib/tor/hidden_service_microblog/hostname)" echo -n "$(cat /var/lib/tor/hidden_service_microblog/hostname)"
fi fi
echo '' echo ''
fi fi
if grep -q "Owncloud domain" $COMPLETION_FILE; then if grep -q "Owncloud domain" $COMPLETION_FILE; then
echo -n -e 'Owncloud \t' echo -n -e "$(pad_string 'Owncloud')"
echo -n "$(cat ${COMPLETION_FILE} | grep 'Owncloud domain' | awk -F ':' '{print $2}')" OWNCLOUDDOM=$(cat ${COMPLETION_FILE} | grep 'Owncloud domain' | awk -F ':' '{print $2}')
echo -n -e '\t' echo -n -e "$(pad_string ${OWNCLOUDDOM})"
if [ -d /var/lib/tor/hidden_service_owncloud ]; then if [ -d /var/lib/tor/hidden_service_owncloud ]; then
echo -n "$(cat /var/lib/tor/hidden_service_owncloud/hostname)" echo -n "$(cat /var/lib/tor/hidden_service_owncloud/hostname)"
fi fi
echo '' echo ''
fi fi
if grep -q "Gogs domain" $COMPLETION_FILE; then if grep -q "Gogs domain" $COMPLETION_FILE; then
echo -n -e 'Gogs \t' echo -n -e "$(pad_string 'Gogs')"
echo -n "$(cat ${COMPLETION_FILE} | grep 'Gogs domain' | awk -F ':' '{print $2}')" GOGSDOM=$(cat ${COMPLETION_FILE} | grep 'Gogs domain' | awk -F ':' '{print $2}')
echo -n -e '\t' echo -n -e "$(pad_string ${GOGSDOM})"
if [ -d /var/lib/tor/hidden_service_git ]; then if [ -d /var/lib/tor/hidden_service_git ]; then
echo -n "$(cat /var/lib/tor/hidden_service_gogs/hostname)" echo -n "$(cat /var/lib/tor/hidden_service_gogs/hostname)"
fi fi
echo '' echo ''
fi fi
if grep -q "XMPP domain" $COMPLETION_FILE; then if grep -q "XMPP domain" $COMPLETION_FILE; then
echo -n -e 'XMPP \t' echo -n -e "$(pad_string 'XMPP')"
echo -n "$(cat ${COMPLETION_FILE} | grep 'XMPP domain' | awk -F ':' '{print $2}')" XMPPDOM=$(cat ${COMPLETION_FILE} | grep 'XMPP domain' | awk -F ':' '{print $2}')
echo -n -e '\t' echo -n -e "$(pad_string ${XMPPDOM})"
if [ -d /var/lib/tor/hidden_service_xmpp ]; then if [ -d /var/lib/tor/hidden_service_xmpp ]; then
echo -n "$(cat /var/lib/tor/hidden_service_xmpp/hostname)" echo -n "$(cat /var/lib/tor/hidden_service_xmpp/hostname)"
fi fi
@ -195,7 +200,7 @@ function show_users {
for d in /home/*/ ; do for d in /home/*/ ; do
USRNAME=$(echo "$d" | awk -F '/' '{print $3}') USRNAME=$(echo "$d" | awk -F '/' '{print $3}')
if [[ $USRNAME != "git" ]]; then if [[ $USRNAME != "git" ]]; then
echo -n "$USRNAME" echo -n -e "$(pad_string '${USRNAME}')"
# get the SIP extension # get the SIP extension
SIPEXT= SIPEXT=
while read ext; do while read ext; do
@ -208,16 +213,14 @@ function show_users {
fi fi
fi fi
done < $SIP_CONFIG_FILE done < $SIP_CONFIG_FILE
echo -e -n '\t'
if [ $SIPEXT ]; then if [ $SIPEXT ]; then
echo -n "SIP:${SIPEXT}" echo -n -e "$(pad_string 'SIP:${SIPEXT}')"
else
echo -n -e "$(pad_string '')"
fi fi
# size of the home directory # size of the home directory
echo -e -n '\t' echo "$(du -s -h /home/${USRNAME} | awk -F ' ' '{print $1}')"
echo -n "$(du -s -h /home/${USRNAME} | awk -F ' ' '{print $1}')"
echo ''
fi fi
done done
} }