cb27ae82ddac373d376e2a8447edc910e81390fc
[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 will always create the folder if input is no tty!)
29                 echo | folder >/dev/null 2>&1
30                 exit $?
31                 ;;
32         -v*)
33                 echo "mmh has no own version number, thus this instead:"
34                 folder -version
35                 exit 0
36                 ;;
37         -h*|*)
38                 echo "Usage: $0      -- set up mmh for you" >&2
39                 echo "       $0 -c   -- check if mmh is set up for you" >&2
40                 exit 1
41         esac
42         shift
43 done
44
45
46 cat <<!
47 Welcome to mmh, meillo's MH version
48 ===================================
49 This program does only one small, but important task: it sets up mmh for your
50 user account. Afterwards you can access the functions of mmh by using any of
51 the specialized tools from the mmh toolchest. The man page mmh(1) lists them.
52 Consult the man pages of the individual programs for further documentation.
53
54 But now, let's set up mmh for you ...
55
56 !
57
58
59 # fail early and loud
60 set -e
61
62
63 finish() {
64         cd "$mmhpath"
65         echo "Path: $mailstore" >"$profile"
66         echo 3.
67         folder
68         echo
69         echo "Enjoy ..."
70         exit 0
71 }
72
73
74 #
75 # mmh dir
76 #
77 mmhdir="${MMH:=$mmhdir}"
78 cd  # relative to HOME
79 echo 1.
80 if [ -d "$mmhdir" ] ; then
81         echo "--> Using existing mmh directory $mmhdir"
82 else
83         mkdir "$mmhdir" && echo "--> Created mmh directory $mmhdir"
84 fi
85 cd "$mmhdir"
86 mmhpath="`pwd`"
87
88
89 #
90 # profile
91 #
92 profile="${MMHP:=$profile}"  # relative to $mmhpath
93 if [ -f "$profile" ] ; then
94         echo 2.
95         echo "You already have an mmh profile."
96         printf "Do you want to edit the file now? [Y/n]  "
97         read answ
98         case "$answ" in
99         ''|Y*|y*)
100                 cd "$mmhpath"
101                 ${VISUAL:-${EDITOR:-vi}} "$profile"
102                 echo 3.
103                 folder
104                 echo
105                 echo "Enjoy ..."
106                 exit 0
107                 ;;
108         *)
109                 echo "Exiting."
110                 exit 1
111                 ;;
112         esac
113 fi
114
115
116 #
117 # mail store
118 #
119 echo 2.
120 echo "Mmh needs a mail storage."
121 cd  # relative to HOME
122 if [ -d "$mailstore" ] ; then
123         echo "The suggested directory `pwd`/$mailstore already exists."
124         printf "Do you want to use it for mmh? [Y/n]  "
125         read answ
126         case "$answ" in
127         ''|Y*|y*)
128                 cd "$mailstore"
129                 echo "--> Using existing directory $mailstore"
130                 finish
131                 exit
132                 ;;
133         esac
134 fi
135 printf "Where do you want it to be located? [`pwd`/Mail]  "
136 read answ
137 if [ -z "$answ" ] ; then
138         answ="`pwd`/Mail"
139 fi
140 mkdir "$answ" && echo "--> Created $answ"
141 cd "$answ"
142 mailstore="`pwd`"
143 finish