6e93eb19194cd1c1f2e18fbbe6af4f7b4a6dd4f6
[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
103                 echo "Enjoy ..."
104                 exit 0
105                 ;;
106         *)
107                 echo "Exiting."
108                 exit 1
109                 ;;
110         esac
111 fi
112
113
114 #
115 # mail store
116 #
117 echo 2.
118 echo "Mmh needs a mail storage."
119 cd  # relative to HOME
120 if [ -d "$mailstore" ] ; then
121         echo "The suggested directory `pwd`/$mailstore already exists."
122         printf "Do you want to use it for mmh? [Y/n]  "
123         read answ
124         case "$answ" in
125         ''|Y*|y*)
126                 cd "$mailstore"
127                 echo "--> Using existing directory $mailstore"
128                 finish
129                 exit
130                 ;;
131         esac
132 fi
133 printf "Where do you want it to be located? [`pwd`/Mail]  "
134 read answ
135 if [ -z "$answ" ] ; then
136         answ="`pwd`/Mail"
137 fi
138 mkdir "$answ" && echo "--> Created $answ"
139 cd "$answ"
140 mailstore="`pwd`"
141 finish