rp

simple email tools
git clone https://git.parazyd.org/rp
Log | Files | Refs | README | LICENSE

rpinit (3720B)


      1 #!/bin/sh
      2 #
      3 # Copy me if you can
      4 # by parazyd
      5 #
      6 
      7 shareprefix="SHAREPREFIX"
      8 
      9 setupmutt() {
     10 	echo " * copying mutt files"
     11 	mkdir -p "$HOME/.rp/$1/mutt"
     12 	touch "$HOME/.rp/$1/mutt/muttpass"
     13 	for i in "$shareprefix"/mutt/*; do
     14 		cp -f "$shareprefix/mutt/$i" "$HOME/.rp/$1/mutt/"
     15 	done
     16 }
     17 
     18 usage() {
     19 	printf " * usage: %s [-u profilename]\\n" "$(basename "$0")"
     20 	printf "\\t-u: update\\n"
     21 	exit 1
     22 }
     23 
     24 [ -n "$1" ] && {
     25 	case "$1" in
     26 		-u)
     27 			[ -n "$2" ] || prof="$(readlink "$HOME"/.rp/default)"
     28 			setupmutt "$prof"
     29 			exit 0
     30 			;;
     31 		*)
     32 			usage
     33 			;;
     34 	esac
     35 }
     36 
     37 echo " * Welcome to rp!"
     38 echo " * Let's start initializing your rp setup."
     39 
     40 mkdir -p ~/.rp && cd ~/.rp || exit 1
     41 
     42 printf " * What should be the name of your profile? > "
     43 read -r profile  || exit 1
     44 mkdir -p "$profile" || exit 1
     45 echo
     46 
     47 [ -L default ] || ln -s "$profile" default
     48 
     49 echo " * Now the configuration begins."
     50 echo
     51 
     52 echo " * Enter the string value that should appear in your From: headers."
     53 echo "    An example is: Luther Blisset <luther@bliss.et>"
     54 printf " * from = "
     55 read -r from || exit 1
     56 echo
     57 
     58 echo "Please enter the network spec of your remote imap server."
     59 echo
     60 echo "Network specifications are for example:"
     61 echo "    tcp!mail.example.com!imap"
     62 echo "    tcp!mail.example.com!143"
     63 echo
     64 echo "For a direct TLS connection:"
     65 echo "    tcps!mail.example.com!imaps"
     66 echo "    tcps!mail.example.com!993"
     67 printf " * remote imap netspec  = "
     68 read -r rnet || exit 1
     69 echo
     70 
     71 echo "Please enter your remote imap username."
     72 printf " * remote imap username = "
     73 read -r ruser || exit 1
     74 echo
     75 
     76 echo "Please enter your remote imap password."
     77 printf " * remote imap password = "
     78 read -r rpass || exit 1
     79 echo
     80 
     81 
     82 echo "Please enter the network spec of your local imap server."
     83 echo
     84 echo "Network specifications are for example:"
     85 echo "    tcp!localhost!imap"
     86 echo "    tcp!localhost!143"
     87 echo
     88 echo "For a direct TLS connection:"
     89 echo "    tcps!localhost!imaps"
     90 echo "    tcps!localhost!993"
     91 printf " * local imap netspec  = "
     92 read -r lnet || exit 1
     93 echo
     94 
     95 echo "Please enter the username for your local imap server."
     96 printf " * local imap username = "
     97 read -r luser || exit 1
     98 echo
     99 
    100 echo "Please enter the password for your local imap server."
    101 printf " * local imap password = "
    102 read -r lpass || exit 1
    103 echo
    104 
    105 
    106 lproto="$(echo "$lnet" | cut -d'!' -f1)"
    107 lserv="$(echo "$lnet"  | cut -d'!' -f2)"
    108 lport="$(echo "$lnet"  | cut -d'!' -f3)"
    109 
    110 case "$lproto" in
    111 	tcp)
    112 		lproto=imap;;
    113 	tcps)
    114 		lproto=imaps;;
    115 esac
    116 
    117 case "$lport" in
    118 	imap)
    119 		lport=143;;
    120 	imaps)
    121 		lport=993;;
    122 esac
    123 
    124 cat <<EOF > "$profile"/muttrc
    125 # muttrc for $profile
    126 source ~/.rp/$profile/mutt/general
    127 source ~/.rp/$profile/mutt/headers
    128 source ~/.rp/$profile/mutt/keybindings
    129 source ~/.rp/$profile/mutt/colors
    130 source ~/.rp/$profile/mutt/sidebar
    131 source ~/.rp/$profile/mutt/gpg
    132 source ~/.rp/$profile/mutt/muttpass
    133 
    134 set from = "$from"
    135 set realname = "$(echo "$from" | cut -d'<' -f1)"
    136 
    137 set folder = "${lproto}://${luser}@${lserv}:${lport}"
    138 set spoolfile = "${lproto}://${luser}@${lserv}:${lport}/INBOX"
    139 
    140 set mailcap_path = ~/.rp/$profile/mutt/mailcap
    141 set header_cache = ~/.rp/$profile/tmp/mutt_hcache
    142 set header_cache_backend = lmdb
    143 
    144 # add your customizations in the following file
    145 source ~/.rp/$profile/muttrc-custom
    146 EOF
    147 echo "set imap_pass = $lpass" > ~/.rp/"$profile"/mutt/muttpass
    148 
    149 touch "$profile"/muttrc-custom
    150 
    151 cat <<EOF > "$profile"/config
    152 defaultfrom: $from
    153 rnet: $rnet
    154 ruser: $ruser
    155 rpass: $rpass
    156 lnet: $lnet
    157 luser: $luser
    158 lpass: $lpass
    159 EOF
    160 
    161 setupmutt "$profile"
    162 
    163 touch "$profile/whitelist.abook"
    164 
    165 [ -f "$profile/filters.txt" ] || {
    166 	cp "$shareprefix/misc/filters.txt" "$profile"
    167 }
    168 
    169 mkdir -p "$profile/tmp/mutt_hcache"
    170 
    171 echo "All done setting up rp!"
    172 echo "Your profile files are in ~/.rp/$profile"
    173 echo "Have fun!"