#!/bin/sh
echo -en BEGIN:VCARD\\nVERSION:2.1\\n>vcf
for f in "Name" "Title" "Email Type" "Email" "Phone Type" "Phone Number" "Website";do
if [ -z $skip ];then
case "$f" in
"Name")
echo Name:
read name
if [ -z `echo -en $name|cut -f 1 -d \  ` ];then
continue
else
echo $name > textual
export namelen=`echo $name|wc -w`
export namectr=$namelen
while [ $namectr -ge 1 ];do
if [ -z $namestr ];then
export namestr=`echo $name|cut -f $namectr -d \  `
else
export namestr=$namestr";"`echo $name|cut -f $namectr -d \  `
fi
export namectr=$(($namectr-1))
done
export name="N:$name;;;"\\n"FN:$namestr"\\n
echo -en $name >> vcf
fi
;;
"Title")
echo Title:
read title
if [ -z `echo -en $title|cut -f 1 -d \  ` ];then
continue
else
echo $title >> textual
export title=ORG:\\n"TITLE:$title"\\n
echo -en $title >> vcf
fi
;;
"Email Type")
while true;do
echo select Email Type
echo "1: Home"
echo "2: Work"
echo "3: Other"
echo "4: None"
read emailtype
case "$emailtype" in
1)
export emailtype="HOME"
echo -n Home Email:  >> textual
break
;;
2)
export emailtype="WORK"
echo -n Work Email:  >> textual
break
;;
3)
export emailtype="OTHER"
echo -n Other Email:  >> textual
break
;;
4)
break
;;
*)
continue
;;
esac
done
if echo $emailtype|grep -qw 4;then
export skip=1
continue
else
export emailtype="EMAIL;$emailtype":
echo -en $emailtype >> vcf
fi
;;
"Email")
if [ -z $emailtype ];then
continue
else
echo Email
read email
fi
if [ -z `echo -en $email|cut -f 1 -d \  ` ];then
continue
else
echo \ $email >> textual
export email="$email"\\n
echo -en $email >> vcf
fi
;;
"Phone Type")
while true;do
echo select Phone Type
echo "1: Main"
echo "2: Mobile"
echo "3: Work"
echo "4: Work Fax"
echo "5: Home"
echo "6: Home Fax"
echo "7: Pager"
echo "8: Other"
echo "9: None"
read phonetype
case "$phonetype" in
1)
export phonetype="PREF"
echo -n Main Phone:  >> textual
break
;;
2)
export phonetype="CELL"
echo -n Cell Phone:  >> textual
break
;;
3)
export phonetype="WORK"
echo -n Work Phone:  >> textual
break
;;
4)
export phonetype="WORK;FAX"
echo -n Work Fax:  >> textual
break
;;
5)
export phonetype="HOME"
echo -n Home Phone:  >> textual
break
;;
6)
export phonetype="HOME;FAX"
echo -n Home Fax:  >> textual
ebreak
;;
7)
export phonetype="PAGER"
echo -n Pager:  >> textual
break
;;
8)
export phonetype="OTHER"
echo -n Other Phone:  >> textual
break
;;
9)
break
;;
*)
continue
;;
esac
done
if echo $phonetype|grep -qw 9;then
export skip=1
continue
else
export phonetype="TEL;$phonetype:"
echo -en $phonetype >> vcf
fi
;;
"Phone Number")
if [ -z $phonetype ];then
continue
else
echo Phone Number
read phone
fi
if [ -z `echo -en $phone|cut -f 1 -d \  ` ];then
export skip=1
continue
else
export phone="$phone"\\n
echo -en \ $phone >> textual
echo -en $phone >> vcf
fi
;;
"Website")
echo Website
read website
if [ -z `echo -en $website|cut -f 1 -d \  ` ];then
export skip=1
continue
else
echo Website: $website >> textual
export website="URL:$website"\\n
echo -en $website >> vcf
fi
;;
esac
else
unset skip
continue
fi
done
echo end:vcard>>vcf
qrencode -r vcf -t png -o barcode.png
cat textual|pbmtext|pnmtopng > textual.png
