-
Notifications
You must be signed in to change notification settings - Fork 0
/
Install_latest.tbird
executable file
·404 lines (365 loc) · 12.2 KB
/
Install_latest.tbird
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
#!/bin/bash
#
# Copyright © 2023 Pablo Sanchez
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# The Software is provided "as is", without warranty of any kind,
# express or implied, including but not limited to the warranties of
# merchantability, fitness for a particular purpose and
# noninfringement. In no event shall the authors or copyright holders be
# liable for any claim, damages or other liability, whether in an action
# of contract, tort or otherwise, arising from, out of or in connection
# with the Software or the use or other dealings in the Software.
#
########################################################
# Bootstrap our Globals
########################################################
THIS_SCRIPT=$(readlink -f "$0")
THIS_SCRIPT_DIR=$(dirname "$THIS_SCRIPT")
cd "$THIS_SCRIPT_DIR"
if [ $? -ne 0 ] ; then
printf "$(basename $0) - failed to cd $THIS_SCRIPT_DIR\n"
exit 1
fi
GLOBALS=src/Globals
if [ ! -r $GLOBALS ] ; then
printf "$(basename $0) - cannot access $GLOBALS\n"
exit 1
fi
. "$GLOBALS"
if [ $? -ne 0 ] ; then
printf "$(basename $0) - error accessing $GLOBALS\n"
exit 1
fi
########################################################
# Functions
########################################################
print_section_separator()
{
printf -- "~~~~~~~~~~~~~~~~~~~~\n"
}
is_install_or_upgrade()
{
if [ ! -d "$INSTALL_DIR" ] ; then
printf "The install directory ($INSTALL_DIR) does not exist.\n"
printf '\n'
printf 'This is a new installation.\n'
printf '\n'
printf "Press ENTER to proceed with a fresh install ... "
read IT
SW='install'
else
printf "Upgrading $INSTALL_DIR\n"
printf "\n"
printf "The files in this directory will not be affected:\n"
printf "\n"
printf "\t$INSTALL_DIR/$LOCAL_DIR/\n"
printf '\n'
printf "Press ENTER to proceed with an update ... "
read IT
SW='upgrade'
fi
}
prompt_a_profile_dir()
{
PROMPT='CTRL-C to abort: '
printf "$PROMPT"
while [ 1 ] ; do
read PROFILE_DIR
PROFILE_DIR=$(echo $PROFILE_DIR | sed -e 's/^[ ]+//g' -e 's/[ ]+$//g' )
if [ -z "$PROFILE_DIR" ] ; then
printf "$PROMPT"
continue
fi
if [ ! -d "$PROFILE_DIR" ] ; then
printf "Could not access $PROFILE_DIR\n"
printf "$PROMPT"
else
break
fi
done
}
profile_dir_missing()
{
printf 'Could not access a Thunderbird profile in the standard location[1][2].\n'
printf 'See the article below on how to find it.\n'
printf '\n'
printf '\thttps://support.mozilla.org/en-US/kb/profiles-where-thunderbird-stores-user-data\n'
printf '\n'
printf "\t[1] - Legacy: $HOME/.thunderbird/xxxxxxxx.default\n"
printf "\t[2] - Current: $HOME/.thunderbird/xxxxxxxx.default-release\n"
printf '\n'
printf "Enter the full path name to your profile.\n"
prompt_a_profile_dir;
}
#
# Handle the three cases:
#
# 1) No profile was found. Provide tips on how to find it.
# 2) A single profile was found. Use it.
# 3) More than one profile was found. Provide .msf count to help the user
# determine which to use. We default their choice to the profile with
# the greatest number of .msf's
#
get_tbird_profile_dir()
{
print_section_separator
declare -a PROFILE_LIST
readarray -t PROFILE_LIST < <(find $HOME/.thunderbird/*.default* -maxdepth 1 -type d -name '*.default*' 2> /dev/null)
N=${#PROFILE_LIST[@]}
N_PLUS_1=$((N+1))
if [ $N -eq 0 ] ; then
profile_dir_missing
elif [ $N -eq 1 ] ; then
PROFILE_DIR="${PROFILE_LIST[0]}"
printf "Found Thunderbird profile $PROFILE_DIR\n"
else # More than one profile found
NUMBER_RE='^[0-9]+$'
printf "Select one of the profiles:\n"
printf "\n"
I=1
DEFAULT=1
PREV_MSF_COUNT=0
for ((I=0; $I<$N; I++)); do
MSF_COUNT=$(find ${PROFILE_LIST[$I]} -name '*.msf' | wc -l)
if [ $MSF_COUNT -gt $PREV_MSF_COUNT ] ; then
PREV_MSF_COUNT=$MSF_COUNT
DEFAULT=$((I+1))
fi
printf "%d) [%4d] ${PROFILE_LIST[$I]}\n" $(($I+1)) $MSF_COUNT
done
printf '\n'
printf '\t- The .msf count is in parenthesis - []\n'
printf "\t- More than likely, you can ignore directories with a zero count\n"
printf '\n'
printf "Options: 1 - %d or %d to enter a different directory.\n" $N $N_PLUS_1
while [ 1 ] ; do
printf "Yes boss [Default = $DEFAULT]? "
read IT
IT=$(echo $IT | sed -e 's/^[ ]+//g' -e 's/[ ]+$//g' )
if [ -z "$IT" ] ; then
PROFILE_DIR="${PROFILE_LIST[$((DEFAULT-1))]}"
break
else
if [[ $IT =~ $NUMBER_RE ]] ; then # It's a number
if [ $IT -ge 1 -a $IT -le $N_PLUS_1 ] ; then
if [ $IT -eq $N_PLUS_1 ] ; then
printf '\n'
printf "Enter the full path name to your profile.\n"
prompt_a_profile_dir
else
PROFILE_DIR="${PROFILE_LIST[$((IT-1))]}"
fi
break
fi
fi
printf 'Invalid\n'
fi
done
fi
}
install_tree()
{
print_section_separator
# Copy the source tree
printf "Installing software in $INSTALL_DIR\n"
cp -rad $SRC_DIR $INSTALL_DIR
if [ $? -ne 0 ] ; then
printf "$(basename $0) - failed to cp -radv $SRC_DIR $INSTALL_DIR\n"
exit 1
fi
}
undo_install()
{
printf "$(basename $0) - undoing install"
rm -rf $INSTALL_DIR
if [ $? -ne 0 ] ; then
printf "$(basename $0) - failed to clean up partial install rm -rf $INSTALL_DIR\n"
fi
exit 1
}
initial_conf_settings()
{
# Configure `tbird_new_msgs.conf'
printf "Configuring $INSTALL_DIR/$LOCAL_DIR/$CONF_DIR/$TBIRD_NEW_MSGS_CONF\n"
printf '\n'
printf '\tSetting TBIRD_DIR="'$PROFILE_DIR'"'"\n"
echo 'TBIRD_DIR="'$PROFILE_DIR'"' >> $INSTALL_DIR/$LOCAL_DIR/$CONF_DIR/$TBIRD_NEW_MSGS_CONF
if [ $? -ne 0 ] ; then
printf "$(basename $0) - failed to create TBIRD_DIR=...\n"
undo_install
fi
printf '\n'
printf "Configuring $INSTALL_DIR/$LOCAL_DIR/$CONF_DIR/$NBIFF_CONF\n"
printf '\n'
printf '\tSetting DEFAULT_GEN_NEW_MSGS="'$TBIRD_NEW_MSGS'"'"\n"
echo 'DEFAULT_GEN_NEW_MSGS="'$TBIRD_NEW_MSGS'"' >> $INSTALL_DIR/$LOCAL_DIR/$CONF_DIR/$NBIFF_CONF
if [ $? -ne 0 ] ; then
printf "$(basename $0) - failed to create DEFAULT_GEN_NEW_MSGS= ...\n"
undo_install
fi
printf '\tSetting MUA_AFFECT_WINDOW="'$TBIRD_AFFECT_WINDOW'"'"\n"
echo 'MUA_AFFECT_WINDOW="'$TBIRD_AFFECT_WINDOW'"' >> $INSTALL_DIR/$LOCAL_DIR/$CONF_DIR/$NBIFF_CONF
if [ $? -ne 0 ] ; then
printf "$(basename $0) - failed to create MUA_AFFECT_WINDOW= ...\n"
undo_install
fi
printf '\n'
printf 'Software installed!\n'
printf '\n'
printf "Press ENTER to view software requirements ... "
read IT
}
helpful_links()
{
printf 'Refer to the "Table of contents"[1] for the following:\n'
printf '\n'
printf '\t- Software requirements\n'
printf '\t- Troubleshooting\n'
printf '\n'
printf '[1] - https://github.com/pablo-blueoakdb/nbiff#table-of-contents\n'
printf '\n'
}
post_install_notes()
{
print_section_separator
printf "The script below does the following:\n"
printf "\n"
printf "\t1) Starts 'nbiff' in the background.\n"
printf "\t2) Starts 'Thunderbird' and waits for it to complete.\n"
printf "\t3) Upon exiting 'Thunderbird', 'nbiff' is shutdown.\n"
printf "\n"
printf "To manually run it now:\n"
printf "\n"
printf "\t1) Exit 'Thunderbird'\n"
printf "\t2) $INSTALL_DIR/$SYSTRAY_DIR/Run_tbird_nbiff &\n"
printf "\n"
printf "Tips:\n"
printf "\n"
printf "\t- Click on the systray icon for mail details\n"
printf "\t- Some may have a tool tip by hovering over the icon\n"
printf "\n"
helpful_links
printf "Software $SW done.\n"
}
upgrade_tree()
{
print_section_separator
printf "Upgrading software in $INSTALL_DIR\n"
# Step 1: exclude the entire $LOCAL_DIR
rsync -a --delete --exclude $LOCAL_DIR $SRC_DIR/ $INSTALL_DIR/
if [ $? -ne 0 ] ; then
printf "$(basename $0) - failed to rsync(1) ...\n"
exit 1
fi
# Step 2: replace $LOCAL_DIR/$CONF/[0-9][0-9].* files
# a) Delete the old links
printf '\n'
printf "Clearing $INSTALL_DIR/$LOCAL_DIR/$LOCAL_ICONS_DIR/[0-9][0-9].*\n"
find $INSTALL_DIR/$LOCAL_DIR/$LOCAL_ICONS_DIR -name '[0-9][0-9].*' | xargs rm -f
if [ $? -ne 0 ] ; then
printf "$(basename $0) - find/rm failed ...\n"
exit 1
fi
printf '\n'
printf "Sync source to $INSTALL_DIR/$LOCAL_DIR/$LOCAL_ICONS_DIR/[0-9][0-9].*\n"
rsync -a $SRC_DIR/$LOCAL_DIR/$LOCAL_ICONS_DIR/[0-9][0-9].* $INSTALL_DIR/$LOCAL_DIR/$LOCAL_ICONS_DIR/
if [ $? -ne 0 ] ; then
printf "$(basename $0) - failed to rsync(2) ...\n"
exit 1
fi
printf '\n'
printf "Software upgrade complete, press ENTER to continue ... "
read IT
}
#
# o All code written below must be able to be re-runnable N-times without affecting more than
# one change.
# o If/when necessary, upgrade the local configuration settings.
# o The code has to be written to keep previous versions in mind.
#
upgrade_conf_settings()
{
print_section_separator
printf "Upgrading $INSTALL_DIR/$LOCAL_DIR/$CONF_DIR/$NBIFF_CONF\n"
printf '\n'
# Fix typo?
grep --silent 'Installtion' "$INSTALL_DIR/$LOCAL_DIR/$CONF_DIR/$NBIFF_CONF" > /dev/null 2>&1
STATUS=$?
if [ $STATUS -eq 0 ] ; then
printf "\tFixing typo: ^Installtion^Installation^\n"
sed -i 's/Installtion/Installation/g' "$INSTALL_DIR/$LOCAL_DIR/$CONF_DIR/$NBIFF_CONF"
if [ $? -ne 0 ] ; then
printf "$(basename $0) - typo fix failed.\n"
fi
fi
# Add MUA_AFFECT_WINDOW?
grep --silent '^MUA_AFFECT_WINDOW=' "$INSTALL_DIR/$LOCAL_DIR/$CONF_DIR/$NBIFF_CONF" > /dev/null 2>&1
STATUS=$?
if [ $STATUS -eq 1 ] ; then
printf '\tSetting MUA_AFFECT_WINDOW="'$TBIRD_AFFECT_WINDOW'"'"\n"
echo 'MUA_AFFECT_WINDOW="'$TBIRD_AFFECT_WINDOW'"' >> $INSTALL_DIR/$LOCAL_DIR/$CONF_DIR/$NBIFF_CONF
if [ $? -ne 0 ] ; then
printf "$(basename $0) - failed to create MUA_AFFECT_WINDOW=\n"
fi
fi
# Add SWAP_MOUSE_ACTION?
grep --silent 'SWAP_MOUSE_ACTION=' "$INSTALL_DIR/$LOCAL_DIR/$CONF_DIR/$NBIFF_CONF" > /dev/null 2>&1
STATUS=$?
if [ $STATUS -eq 1 ] ; then
printf "\tAdding #SWAP_MOUSE_ACTION=1\n"
echo '#SWAP_MOUSE_ACTION=1 # default is 0, non-zero swaps' >> $INSTALL_DIR/$LOCAL_DIR/$CONF_DIR/$NBIFF_CONF
if [ $? -ne 0 ] ; then
printf "$(basename $0) - failed to create SWAP_MOUSE_ACTION=\n"
fi
fi
printf '\n'
printf "Upgraded conf, press ENTER to continue ... "
read IT
}
post_upgrade_notes()
{
print_section_separator
printf 'To run the latest version:\n'
printf '\n'
printf '\t1) Exit `Thunderbird`\n'
printf "\t2) $INSTALL_DIR/$SYSTRAY_DIR/Run_tbird_nbiff &\n"
printf '\n'
helpful_links
printf "Software $SW done.\n"
}
########################################################
# Main
########################################################
########################################################
# Initialize
########################################################
TBIRD_INSTALL_DIR="$HOME/.thunderbird"
# Override the `Global' variables
TBIRD_NEW_MSGS_CONF="$(basename "$TBIRD_NEW_MSGS_CONF")"
NBIFF_CONF="$(basename "$NBIFF_CONF")"
########################################################
# Main
########################################################
is_install_or_upgrade
if [ "$SW" == 'install' ] ; then
get_tbird_profile_dir
install_tree
initial_conf_settings
post_install_notes
else
upgrade_tree
upgrade_conf_settings
post_upgrade_notes
fi
exit 0