Add %(unmailto) format function for List-Post headers
[mmh] / uip / mmh.sh
1 #!/bin/sh
2 # 2011  markus schnalke <meillo@marmaro.de>
3 #
4 # replacement for install-mh(1)
5 # set up mmh for the user
6 #
7 # Uses: folder(1)
8 #
9 # Todo: use chmod or set umask for created files?
10 # Todo: install signal handlers and tell how to abort
11
12
13 # the following constants must match the values in config/config.c
14 mmhdir=.mmh
15 profile=profile
16 mailstore=Mail
17
18
19 #
20 # process args
21 #
22 while [ $# -ge 1 ] ; do
23         case $1 in
24         -c*)
25                 # check if mmh is set up
26                 # Note: The mail storage dir gets silently created if
27                 #       everything else is properly set up.
28                 folder -create >/dev/null 2>&1
29                 exit $?
30                 ;;
31         -V*)
32                 echo "mmh has no own version number, thus this instead:"
33                 folder -Version
34                 exit 0
35                 ;;
36         -h*|*)
37                 echo "Usage: $0      -- set up mmh for you" >&2
38                 echo "       $0 -c   -- check if mmh is set up for you" >&2
39                 exit 1
40         esac
41         shift
42 done
43
44
45 cat <<!
46 Welcome to mmh, meillo's MH version
47 ===================================
48 This program does only one small, but important task: it sets up mmh for your
49 user account. Afterwards you can access the functions of mmh by using any of
50 the specialized tools from the mmh toolchest. The man page mmh(1) lists them.
51 Consult the man pages of the individual programs for further documentation.
52
53 But now, let's set up mmh for you ...
54
55 !
56
57
58 # fail early and loud
59 set -e
60
61
62 finish() {
63         cd "$mmhpath"
64         echo "Path: $mailstore" >"$profile"
65         echo 3.
66         folder
67         echo
68         echo "Enjoy ..."
69         exit 0
70 }
71
72
73 #
74 # mmh dir
75 #
76 mmhdir="${MMH:=$mmhdir}"
77 cd  # relative to HOME
78 echo 1.
79 if [ -d "$mmhdir" ] ; then
80         echo "--> Using existing mmh directory $mmhdir"
81 else
82         mkdir "$mmhdir" && echo "--> Created mmh directory $mmhdir"
83 fi
84 cd "$mmhdir"
85 mmhpath="`pwd`"
86
87
88 #
89 # profile
90 #
91 profile="${MMHP:=$profile}"  # relative to $mmhpath
92 if [ -f "$profile" ] ; then
93         echo 2.
94         echo "You already have an mmh profile."
95         printf "Do you want to edit the file now? [Y/n]  "
96         read answ
97         case "$answ" in
98         ''|Y*|y*)
99                 cd "$mmhpath"
100                 ${VISUAL:-${EDITOR:-vi}} "$profile"
101                 echo
102                 echo "Enjoy ..."
103                 exit 0
104                 ;;
105         *)
106                 echo "Exiting."
107                 exit 1
108                 ;;
109         esac
110 fi
111
112
113 #
114 # mail store
115 #
116 echo 2.
117 echo "Mmh needs a mail storage."
118 cd  # relative to HOME
119 if [ -d "$mailstore" ] ; then
120         echo "The suggested directory `pwd`/$mailstore already exists."
121         printf "Do you want to use it for mmh? [Y/n]  "
122         read answ
123         case "$answ" in
124         ''|Y*|y*)
125                 cd "$mailstore"
126                 echo "--> Using existing directory $mailstore"
127                 finish
128                 exit
129                 ;;
130         esac
131 fi
132 printf "Where do you want it to be located? [`pwd`/Mail]  "
133 read answ
134 if [ -z "$answ" ] ; then
135         answ="`pwd`/Mail"
136 fi
137 mkdir "$answ" && echo "--> Created $answ"
138 cd "$answ"
139 mailstore="`pwd`"
140 finish