~johanvandegriff/unix-shell-programming-revised-edition-programs

unix-shell-programming-revised-edition-programs/mail/install_mail -rw-r--r-- 6.6 KiB
fc214385Johan Vandegriff added other old scripts, some newer ones too 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#!/bin/sh
install=""
until [ -n "$install" ]
do
  echo "Do you want to install in your home directory,$HOME?(y/n)"
  read answer
  case $answer in
    y) install=$HOME;;
    n) echo "Where do you want to install?"
       read "install";;
    *) echo "Bad choice"
  esac
done

if [ ! -d "$install" ]
then
  echo "$install does not exist."
else
  if [ -d "$install/mail" ]
  then
    echo "$install/mail already exists."
  else

mkdir "$install/mail/"
mkdir "$install/mail/files"
mkdir "$install/mail/programs"
#programs/showmail
echo '#!/bin/bash
name="$1"
home="$2"
echo "_______
Unread |
-----------------------------------------------"
cd "$home"/mail/users/$name/unread
if [ `ls | grep "txt~"` ]
then
  rm `ls | grep "txt~"`
fi
ls -1 "$home"/mail/users/$name/unread
echo "_____
Read |
-----------------------------------------------"
ls -1 "$home"/mail/users/$name/read' > "$install/mail/programs/showmail"
chmod 755 "$install/mail/programs/showmail"

#programs/sendmail
echo '#!/bin/bash
name="$1"
person="$2"
home="$3"

if [ -d "$home/mail/users/$person/unread" ]
then
  goodchoice=""
  clear
  until [ "$goodchoice" = "true" ]
  do
    cd "$home/mail/users/$person/unread"
    echo -n "subject?"
    read subject
    filename=`echo -n "$subject" | tr " " "_"`

    if [ -f "$home/mail/users/$person/unread/$subject" ]
    then
      clear
      echo "$subject already exists!"
    else
      if [ -n "$subject" ]
      then
        echo "




--$name" > "$filename"
        gedit --new-window "$filename"
        goodchoice="true"
        echo `date`":	$subject sent from $name to $person" >> "$home"/mail/files/log.txt
      else
        clear
      fi
    fi
  done
else
  clear
  echo "$person does not exist"
  read a
fi' > "$install/mail/programs/sendmail"
chmod 755 "$install/mail/programs/sendmail"

#programs/checkmail
echo '#!/bin/bash
name="$1"
home="$2"

maildir="$home/mail/users/$name"

echo "Which mail do you want to read?"
"$home"/mail/programs/showmail "$name" "$home"
read file
echo
if [ -f "$maildir/unread/$file" ]
then
  clear
  file="$maildir/unread/$file"
  echo "--------------------------------------"
  cat "$file"
  echo "--------------------------------------"
  echo `date`":	"`basename $file`" read by $name" >> "$home"/mail/files/log.txt
  mv "$file" "$maildir/read/"
elif [ -f "$maildir/read/$file" ]
then
  clear
  file="$maildir/read/$file"
  echo "--------------------------------------"
  cat "$file"
  echo "--------------------------------------"
  echo `date`":	"`basename $file`" read by $name" >> "$home"/mail/files/log.txt
else
  if [ -n "$file" ]
  then
    file=`basename $file`
  fi
  clear
  echo "$file does not exist."
fi

read a' > "$install/mail/programs/checkmail"
chmod 755 "$install/mail/programs/checkmail"

#programs/startmail
echo '#!/bin/bash
home="$1"
if [ ! -d "$home/mail/users" ]
then
  mkdir mail/users
fi
echo -n "Select a name or choose a new name:
"
ls -1 "$home"/mail/users
echo
read name
if [ ! -n "$name" ]
then
  name=User
fi
name=`echo "$name" | tr " " "_"`
maildir="$home/mail/users/$name"
if [ ! -d "$maildir" ]
then
  mkdir "$maildir"
  cd "$maildir"
  mkdir "read" "unread"
  cd "$home"
  echo "New password for $name:"
  read password
  password=`echo "$password" | rev`
  perl -e mc2tpq3tnuvpqb834tow43t8bwpb6t8mb7p34tv23vpqbn438print unpack "H*", "mc2tpq3tnuvpqb834tow43t8bwpb6t8mb7p34tv23vpqbn438"$password\"" | rev > "$maildir/.password"
else
  echo "Password for $name:"
  read password
  password=`echo "$password" | rev`
  password=`perl -e mc2tpq3tnuvpqb834tow43t8bwpb6t8mb7p34tv23vpqbn438print unpack "H*", "mc2tpq3tnuvpqb834tow43t8bwpb6t8mb7p34tv23vpqbn438"$password\"" | rev`
  correct=`cat $maildir/.password`
  if [ "$password" != "$correct" ]
  then
    echo "Incorrect Password."
    > "$home"/mail/files/name.txt
    echo `date`":	Failed Password for $name" >> "$home"/mail/files/log.txt
    echo `date`":	Failed Password Attempt: $password" > "$maildir/unread/$RANDOM"
    exit 1
  fi
fi
echo $name > "$home"/mail/files/name.txt
echo `date`":	Logged in as $name" >> "$home"/mail/files/log.txt' | sed "s/mc2tpq3tnuvpqb834tow43t8bwpb6t8mb7p34tv23vpqbn438/'/g" > "$install/mail/programs/startmail"
chmod 755 "$install/mail/programs/startmail"

#programs/mailprog
echo '#!/bin/bash
echo "
 ___      ___       __       _____   _
|   \    /   |     /  \     |_   _| | |
| |\ \  / /| |    / /\ \      | |   | |
| | \ \/ / | |   / /__\ \     | |   | |
| |  \__/  | |  / ______ \   _| |_  | |____
|_|        | | /_/      \_\ |_____| |______|
"

sleep 2
home='"$install"'
name=""
while [ "$name" == "" ]
do
  clear
  "$home"/mail/programs/startmail "$home"
  name=`cat "$home"/mail/files/name.txt`
done
while true
do
  clear
  echo "
============================
=               _____      =
= |\  /|   /\     |   |    =
= | \/ |  /__\    |   |    =
= |    | /    \ __|__ |___ =
=                          =
============================"
  echo "User: " $name
  echo "Mail:"
  "$home"/mail/programs/showmail "$name" "$home"
  echo "==============================================="
  echo "What do you want to do(1-5)?"
  echo "1.Send a message to any user."
  echo "2.Read a message in your inbox."
  echo "3.Log out of your account."
  echo "4.List all the users."
  echo "5.exit."
  read choice
  cd
  case "$choice" in
    1) clear
       echo "Choose a person:"
       ls -1 "$home"/mail/users
       echo
       read person
       "$home"/mail/programs/sendmail "$name" "$person" "$home";;
    2) clear
       "$home"/mail/programs/checkmail "$name" "$home";;
    3) clear
       echo `date`":	Logged out form $name" >> "$home"/mail/files/log.txt
       name=""
       while [ "$name" == "" ]
       do
         clear
         "$home"/mail/programs/startmail "$home"
         name=`cat "$home"/mail/files/name.txt`
       done;;
    4) clear
       ls -1 "$home"/mail/users
       read a;;
    5) echo `date`":	Logged out form $name" >> "$home"/mail/files/log.txt
       echo `date`":	Exited" >> "$home"/mail/files/log.txt
       exit;;
    5) more "$home"/mail/files/log.txt;;
  esac
done' > "$install/mail/programs/mailprog"
chmod 755 "$install/mail/programs/mailprog"

#mailprog.desktop
echo '#!/usr/bin/env xdg-open

[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Terminal=true
Icon[en_US]=gnome-panel-launcher
Name[en_US]=Mail Program
Exec='"$install"'/mail/programs/mailprog
Name=Mail Program
Icon=gnome-panel-launcher

' > "$install/mail/mailprog.desktop"
chmod 755 "$install/mail/mailprog.desktop"

mkdir "$install/mail/users"
#read.txt
echo 'Run '"$install"'/mail/Mail Program to start.
Delete '"$install"'/mail to uninstall

' > "$install/mail/read.txt"
chmod 755 "$install/mail/read.txt"


    echo "Installation has been successfully completed."
  fi
fi
echo "Press ENTER to exit."
read a