3 # @(#) $Id: register_host.sh,v 1.5 2009/06/24 17:06:21 dcid Exp $
6 # Copyright (C) 2009 Trend Micro Inc.
9 # This program is a free software; you can redistribute it
10 # and/or modify it under the terms of the GNU General Public
11 # License (version 3) as published by the FSF - Free Software
15 MYNAME="register_host.sh"
19 # Checking the location.
20 ls -la $MYNAME > /dev/null 2>&1
22 LOCALDIR=`dirname $0`;
25 ls -la $MYNAME > /dev/null 2>&1
27 echo "ERROR: You must run this script from the same directory."
35 if [ "x$1" = "x" -o "x$1" = "xhelp" -o "x$1" = "x-h" ]; then
37 echo " add <user@host> [<passwd>] (<additional_pass>)"
38 echo " list (passwords)"
43 if [ "x$1" = "xlist" ]; then
44 echo "*Available hosts: "
45 if [ "x$2" = "xpasswords" ]; then
46 cat $MYPASS | sort | uniq;
48 cat $MYPASS | cut -d "|" -f 1 | sort | uniq;
54 elif [ "x$1" = "xadd" ]; then
55 if [ "x$2" = "x" ]; then
56 echo "ERROR: Missing hostname name.";
57 echo "ex: $0 add <user@host> [<passwd>] (<additional_pass>)";
61 grep "$2|" $MYPASS > /dev/null 2>&1
63 echo "ERROR: Host '$2' already added.";
68 # Checking if the password was supplied.
69 if [ "x$3" = "x" ]; then
70 echo "Please provide password for host $2."
76 echo "Please provide additional password for host $2 (<enter> for empty)."
86 echo "$2|$INPASS|$ADDPASS" >> $MYPASS;
88 echo "ERROR: Unable to creating entry (echo failed)."
91 echo "*Host $2 added."
95 echo "ERROR: Invalid argument.";