-
Notifications
You must be signed in to change notification settings - Fork 0
/
mini_vault
executable file
·536 lines (532 loc) · 18.4 KB
/
mini_vault
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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
#! /bin/bash
# mini_bomba vault: encrypted file storage utility
#
# Copyright (C) 2021-2022 mini_bomba
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# Set the default variables if not specified
if [ -z "$MBV_RAMDISK_SIZE" ]
then
MBV_RAMDISK_SIZE=1G
fi
if [ -z "$MBV_FILE_LOCATION" ]
then
MBV_FILE_LOCATION=$HOME/.mini_bomba_vault
fi
if [ -z "$MBV_RAMDISK_LOCATION" ]
then
MBV_RAMDISK_LOCATION=/tmp/mini_bomba_vault-$USER
fi
# Get the program used for privilege elevation
FAIL=0
if [[ $EUID == 0 ]]
then
# running as root, does not need to elevate privileges
echo "Note: You're running this as root, and therefore you're accessing root's vaults." >&2
echo "If you want to access your own vaults, do not run this as root." >&2
root_auth=
elif ! [ -z "$MBV_USE_SUDO" ] || ! which pkexec > /dev/null 2>&1
then
# Use sudo (CLI auth)
if ! which sudo > /dev/null 2>&1
then
echo "Missing required dependency: sudo (or pkexec, if MBV_USE_SUDO is not set)" >&2
FAIL=1
fi
root_auth=$(which sudo)
else
# Use pkexec (GUI auth)
root_auth=$(which pkexec)
fi
# Check for dependencies
if ! which gpg > /dev/null 2>&1
then
echo "Missing required dependency: gpg" >&2
FAIL=1
fi
if ! which tar > /dev/null 2>&1
then
echo "Missing required dependency: tar" >&2
FAIL=1
fi
if ! which gzip > /dev/null 2>&1
then
echo "Missing recommended dependency: gzip" >&2
fi
if ! which zstd > /dev/null 2>&1
then
echo "Missing required dependency: zstd" >&2
FAIL=1
fi
if ! which pv > /dev/null 2>&1
then
echo "Missing required dependency: pv" >&2
FAIL=1
fi
if ! which du > /dev/null 2>&1
then
echo "Missing required dependency: du" >&2
FAIL=1
fi
if ! which awk > /dev/null 2>&1
then
echo "Missing required dependency: awk" >&2
FAIL=1
fi
if [ -z "$MBV_SKIP_OPEN" ] && ! which xdg-open > /dev/null 2>&1
then
echo "Missing optional dependency: xdg-open" >&2
echo "Ramdisk location will not be shown in the file manager." >&2
MBV_SKIP_OPEN=1
fi
if [ $FAIL -ne 0 ]
then
exit 1
fi
# Create the encrypted file directory if it is not there
if ! [ -d $MBV_FILE_LOCATION ]
then
mkdir $MBV_FILE_LOCATION
fi
chmod 700 $MBV_FILE_LOCATION
if ! [ -z "$(ls $MBV_FILE_LOCATION)" ]
then
chmod 600 $MBV_FILE_LOCATION/*.mbv{,2} 2> /dev/null
fi
# ... and the ramdisk directory
if ! [ -d $MBV_RAMDISK_LOCATION ]
then
mkdir $MBV_RAMDISK_LOCATION
chmod 700 $MBV_RAMDISK_LOCATION
fi
shopt -s dotglob
# Save current directory, for later
initial_wd=$PWD
if [[ $1 == "help" ]]
then
echo "mini_bomba vault: encrypted file storage utility"
echo "This program comes with ABSOLUTELY NO WARRANTY; for details use the 'license' subcommand."
echo "Available subcommands:"
echo " help - show this help message"
echo " list - list your vaults"
echo " create <name> [gpg key ID] - creates a new vault"
echo " open <name> - decrypts & mounts the vault"
echo " import <directory> <name> [gpg key ID] - imports the contents of the directory into a vault file"
echo " export <name> <directory> - exports the contents of the vault file into a directory"
echo " convert <name> - converts an mbv vault to mbv2 (gzip -> ZStandard compression)"
echo " license - shows more info about the warranty & license"
exit 0
elif [[ $1 == "warranty" ]] || [[ $1 == "license" ]]
then
echo " mini_bomba vault"
echo " Copyright (C) 2021 mini_bomba"
echo
echo " This program is free software: you can redistribute it and/or modify"
echo " it under the terms of the GNU General Public License as published by"
echo " the Free Software Foundation, either version 3 of the License, or"
echo " (at your option) any later version."
echo
echo " This program is distributed in the hope that it will be useful,"
echo " but WITHOUT ANY WARRANTY; without even the implied warranty of"
echo " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"
echo " GNU General Public License for more details."
echo
echo " You should have received a copy of the GNU General Public License"
echo " along with this program. If not, see <https://www.gnu.org/licenses/>."
elif [[ $1 == "list" ]]
then
echo "Your vault files:"
ls -lAh $MBV_FILE_LOCATION
echo
echo "Your unlocked vaults:"
ls -lAh $MBV_RAMDISK_LOCATION
exit 0
elif [[ $1 == "create" ]]
then
if [ -z "$2" ]
then
echo "Missing required param: name" >&2
exit 1
fi
if [[ $2 =~ ^~ ]]
then
echo "The vault name may not start with '~'!" >&2
echo "Vault files starting with '~' are reserved for partially saved vaults." >&2
exit 1
fi
if [ -e "$MBV_FILE_LOCATION/$2.mbv" ] || [ -e "$MBV_FILE_LOCATION/$2.mbv2" ]
then
echo "Vault '$2' already exists!" >&2
exit 1
fi
if [ -e "$MBV_FILE_LOCATION/~$2.mbv" ] || [ -e "$MBV_FILE_LOCATION/~$2.mbv2" ]
then
echo "Vault '$2' has a partially saved vault file!" >&2
exit 1
fi
echo -n "Creating... "
if [ -z "$3" ]
then
tar --zstd -cT/dev/null | gpg --encrypt --default-recipient-self -o $MBV_FILE_LOCATION/$2.mbv2 && chmod 600 $MBV_FILE_LOCATION/$2.mbv2 && echo "Created!" || echo "Failed!"
else
tar --zstd -cT /dev/null | gpg --encrypt -o $MBV_FILE_LOCATION/$2.mbv2 -u $3 -r $3 && chmod 600 $MBV_FILE_LOCATION/$2.mbv2 && echo "Created!" || echo "Failed!"
fi
exit $?
elif [[ $1 == "import" ]]
then
if [ -z "$2" ]
then
echo "Missing required params: input directory, vault name" >&2
exit 1
fi
if [ -z "$3" ]
then
echo "Missing required param: vault name" >&2
exit 1
fi
if ! [ -d "$2" ]
then
echo "'$2' is not a directory!" >&2
exit 1
fi
if [[ -z "$(ls -A $2)" ]]
then
echo "Input directory '$2' is empty!" >&2
echo "Use 'mini_vault create' to create an empty vault instead." >&2
exit 1
fi
if [[ $3 =~ ^~ ]]
then
echo "The vault name may not start with '~'!" >&2
echo "Vault files starting with '~' are reserved for partially saved vaults." >&2
exit 1
fi
if [ -e "$MBV_FILE_LOCATION/~$3.mbv" ]
then
echo "Vault '$3' has a partially saved vault file '~$3.mbv'!" >&2
echo "Please manually delete or move it in $MBV_FILE_LOCATION." >&2
exit 1
fi
if [ -e "$MBV_FILE_LOCATION/~$3.mbv2" ]
then
echo "Vault '$3' has a partially saved vault file '~$3.mbv2'!" >&2
echo "Please manually delete or move it in $MBV_FILE_LOCATION." >&2
exit 1
fi
if [ -e "$MBV_FILE_LOCATION/$3.mbv" ] || [ -e "$MBV_FILE_LOCATION/$3.mbv2" ]
then
echo "Vault '$3' already exists!" >&2
echo "Importing into this vault will cause its previous content to be overwritten!" >&2
echo -n "Enter 'YES' to continue: " >&2
read confirm
if [[ "$confirm" == "YES" ]]
then
echo "Overwriting previous vault..." >&2
else
echo "Aborted." >&2
exit 1
fi
fi
echo "Importing..."
file_size=$(du -sb $2 | awk '{print $1}')
if [ -z "$4" ]
then
cd $2 && ls -A | tar --verbatim-files-from --zstd -cT - | pv -s $file_size | gpg --encrypt -o $MBV_FILE_LOCATION/~$3.mbv2 --default-recipient-self --yes && chmod 600 $MBV_FILE_LOCATION/~$3.mbv2
else
cd $2 && ls -A | tar --verbatim-files-from --zstd -cT - | pv -s $file_size | gpg --encrypt -o $MBV_FILE_LOCATION/~$3.mbv2 -u $4 -r $4 --yes && chmod 600 $MBV_FILE_LOCATION/~$3.mbv2
fi
if [[ $? -eq 0 ]]
then
echo "Moving vault into place..."
mv $MBV_FILE_LOCATION/~$3.mbv2 $MBV_FILE_LOCATION/$3.mbv2 && (echo "Done!" && exit 0) || (echo "Failed!" && exit 1)
if [ -e "$MBV_FILE_LOCATION/$3.mbv" ]
then
echo "Removing old vault..."
rm "$MBV_FILE_LOCATION/$3.mbv"
fi
else
echo "Failed!"
exit 1
fi
elif [[ $1 == "export" ]] || [[ $1 == "extract" ]]
then
if [ -z "$2" ]
then
echo "Missing required params: vault name, output directory" >&2
exit 1
fi
if [ -z "$3" ]
then
echo "Missing required param: output directory" >&2
exit 1
fi
if [[ $2 =~ ^~ ]]
then
echo "The vault name may not start with '~'!" >&2
echo "Vault files starting with '~' are reserved for partially saved vaults." >&2
echo "If you're looking to open the partially saved vault file, please manually rename it in $MBV_FILE_LOCATION" >&2
exit 1
fi
if ! [ -e "$MBV_FILE_LOCATION/$2.mbv" ] && ! [ -e "$MBV_FILE_LOCATION/$2.mbv2" ]
then
echo "Vault '$2' does not exist! Use mini_vault create to create a new one!" >&2
exit 1
fi
if [ -e "$MBV_FILE_LOCATION/~$2.mbv" ]
then
echo "Vault '$2' has a partially saved vault file '~$2.mbv'!" >&2
echo "Please manually delete or move it in $MBV_FILE_LOCATION." >&2
exit 1
fi
if [ -e "$MBV_FILE_LOCATION/~$2.mbv2" ]
then
echo "Vault '$2' has a partially saved vault file '~$2.mbv2'!" >&2
echo "Please manually delete or move it in $MBV_FILE_LOCATION." >&2
exit 1
fi
if [ -e "$MBV_FILE_LOCATION/$2.mbv" ] && [ -e "$MBV_FILE_LOCATION/$2.mbv2" ]
then
echo "Vault '$2' has two versions: '$2.mbv' and '$2.mbv2'!" >&2
echo "Please manually rename or delete one of the versions in $MBV_FILE_LOCATION" >&2
exit 1
fi
if ! [ -d "$3" ]
then
echo "'$3' is not a directory!" >&2
exit 1
fi
if [ -n "$(ls -A $3)" ]
then
echo "'$3' is not empty!" >&2
exit 1
fi
echo "Exporting..."
cd $3
if [ -e "$MBV_FILE_LOCATION/$2.mbv" ]
then
file_size=$(du -sb $MBV_FILE_LOCATION/$2.mbv | awk '{print $1}')
gpg --decrypt -q $MBV_FILE_LOCATION/$2.mbv | pv -s $file_size | tar -xz
elif [ -e "$MBV_FILE_LOCATION/$2.mbv2" ]
then
file_size=$(du -sb $MBV_FILE_LOCATION/$2.mbv2 | awk '{print $1}')
gpg --decrypt -q $MBV_FILE_LOCATION/$2.mbv2 | pv -s $file_size | tar -x --zstd
fi
if [ -z "$MBV_SKIP_OPEN" ]
then
xdg-open . &
fi
cd $initial_wd
echo "Done!"
elif [[ $1 == "open" ]] || [[ $1 == "mount" ]]
then
if [ -z "$2" ]
then
echo "Missing required param: name" >&2
exit 1
fi
if [[ $2 =~ ^~ ]]
then
echo "The vault name may not start with '~'!" >&2
echo "Vault files starting with '~' are reserved for partially saved vaults." >&2
echo "If you're looking to open the partially saved vault file, please manually rename it in $MBV_FILE_LOCATION" >&2
exit 1
fi
if ! [ -e $MBV_FILE_LOCATION/$2.mbv ] && ! [ -e $MBV_FILE_LOCATION/$2.mbv2 ]
then
echo "Vault '$2' does not exist! Use mini_vault create to create a new one!" >&2
exit 1
fi
if [ -e "$MBV_FILE_LOCATION/~$2.mbv" ]
then
echo "Vault '$2' has a partially saved vault file '~$2.mbv'!" >&2
echo "Please manually delete or move it in $MBV_FILE_LOCATION." >&2
exit 1
fi
if [ -e "$MBV_FILE_LOCATION/~$2.mbv2" ]
then
echo "Vault '$2' has a partially saved vault file '~$2.mbv2'!" >&2
echo "Please manually delete or move it in $MBV_FILE_LOCATION." >&2
exit 1
fi
if [ -e "$MBV_FILE_LOCATION/$2.mbv" ] && [ -e "$MBV_FILE_LOCATION/$2.mbv2" ]
then
echo "Vault '$2' has two versions: '$2.mbv' and '$2.mbv2'!" >&2
echo "Please manually rename or delete one of the versions in $MBV_FILE_LOCATION" >&2
exit 1
fi
echo "Checking used gpg key..."
if [ -e "$MBV_FILE_LOCATION/$2.mbv" ]
then
VAULT_VERSION=1
key_id=$(gpg --list-packets $MBV_FILE_LOCATION/$2.mbv | grep -oP "[A-F0-9]{16}" | head -n 1)
elif [ -e "$MBV_FILE_LOCATION/$2.mbv2" ]
then
VAULT_VERSION=2
key_id=$(gpg --list-packets $MBV_FILE_LOCATION/$2.mbv2 | grep -oP "[A-F0-9]{16}" | head -n 1)
fi
if [ -z "$key_id" ]
then
echo "Unable to get key used, aborting" >&2
exit 1
fi
echo -n "Creating ramdisk... "
if [ -e $MBV_RAMDISK_LOCATION/$2 ]
then
echo "Error: Ramdisk location ($MBV_RAMDISK_LOCATION/$2) already exists!" >&2
exit 1
fi
mkdir $MBV_RAMDISK_LOCATION/$2
$root_auth bash -c "mount -t tmpfs -o size=$MBV_RAMDISK_SIZE mbv-$USER-$2 $MBV_RAMDISK_LOCATION/$2 && chown $USER:$USER $MBV_RAMDISK_LOCATION/$2 && chmod 700 $MBV_RAMDISK_LOCATION/$2"
if [[ $? -eq 0 ]]
then
echo "Done!"
else
echo "Failed, aborting!" >&2
rmdir $MBV_RAMDISK_LOCATION/$2
exit 1
fi
trap "echo 'Received SIGINT/TERM, aborting'; cd $initial_wd; $root_auth umount $MBV_RAMDISK_LOCATION/$2; rmdir $MBV_RAMDISK_LOCATION/$2; exit 1" SIGINT SIGTERM
echo "Decrypting & extracting files... "
cd $MBV_RAMDISK_LOCATION/$2
if [ $VAULT_VERSION -eq 1 ]
then
file_size=$(du -sb $MBV_FILE_LOCATION/$2.mbv | awk '{print $1}')
gpg --decrypt -q $MBV_FILE_LOCATION/$2.mbv | pv -s $file_size | tar -xz
elif [ $VAULT_VERSION -eq 2 ]
then
file_size=$(du -sb $MBV_FILE_LOCATION/$2.mbv2 | awk '{print $1}')
gpg --decrypt -q $MBV_FILE_LOCATION/$2.mbv2 | pv -s $file_size | tar -x --zstd
fi
cd $initial_wd
echo "Done!"
echo "Files ready in $MBV_RAMDISK_LOCATION/$2"
if [ -z "$MBV_SKIP_OPEN" ]
then
xdg-open $MBV_RAMDISK_LOCATION/$2 &
fi
d=0
while true
do
trap "echo -e '\nReceived SIGINT/TERM, unmounting without saving'; $root_auth umount $MBV_RAMDISK_LOCATION/$2; rmdir $MBV_RAMDISK_LOCATION/$2; exit 1" SIGINT SIGTERM
echo -n "Press return to save & unmount vault."
read
trap "echo 'CTRL+C is currently disabled to prevent data loss.' >&2" SIGINT SIGTERM
echo "Saving... "
if [ -z "$(ls -A $MBV_RAMDISK_LOCATION/$2)" ]
then
echo -n "Directory empty, creating empty vault... " >&2
if [ $VAULT_VERSION -eq 1 ]
then
tar -czT /dev/null | gpg --encrypt -o $MBV_FILE_LOCATION/~$2.mbv -u $key_id -r $key_id --yes
elif [ $VAULT_VERSION -eq 2 ]
then
tar --zstd -cT /dev/null | gpg --encrypt -o $MBV_FILE_LOCATION/~$2.mbv2 -u $key_id -r $key_id --yes
fi
else
file_size=$(du -sb $MBV_RAMDISK_LOCATION/$2 | awk '{print $1}')
if [ $VAULT_VERSION -eq 1 ]
then
cd $MBV_RAMDISK_LOCATION/$2 && ls -A | tar --verbatim-files-from -czT - | pv -s $file_size | gpg --encrypt -o $MBV_FILE_LOCATION/~$2.mbv -u $key_id -r $key_id --yes && chmod 600 $MBV_FILE_LOCATION/~$2.mbv
elif [ $VAULT_VERSION -eq 2 ]
then
cd $MBV_RAMDISK_LOCATION/$2 && ls -A | tar --verbatim-files-from --zstd -cT - | pv -s $file_size | gpg --encrypt -o $MBV_FILE_LOCATION/~$2.mbv2 -u $key_id -r $key_id --yes && chmod 600 $MBV_FILE_LOCATION/~$2.mbv2
fi
fi
if [[ $? -ne 0 ]]
then
echo "Failed!" >&2
cd $initial_wd
continue
fi
cd $initial_wd
echo "Saved!"
echo "Replacing current vault file with the new one..."
if [ $VAULT_VERSION -eq 1 ]
then
mv $MBV_FILE_LOCATION/~$2.mbv $MBV_FILE_LOCATION/$2.mbv
elif [ $VAULT_VERSION -eq 2 ]
then
mv $MBV_FILE_LOCATION/~$2.mbv2 $MBV_FILE_LOCATION/$2.mbv2
fi
echo -n "Unmounting ramdisk... "
$root_auth umount $MBV_RAMDISK_LOCATION/$2
if [[ $? -ne 0 ]]
then
echo "Failed!" >&2
continue
fi
echo "Unmounted!"
echo "Cleaning up..."
rmdir $MBV_RAMDISK_LOCATION/$2
break
done
trap - SIGINT SIGTERM
elif [[ $1 == "convert" ]] || [[ $1 == "update" ]]
then
if [ -z "$2" ]
then
echo "Missing required param: name" >&2
exit 1
fi
if [[ $2 =~ ^~ ]]
then
echo "The vault name may not start with '~'!" >&2
echo "Vault files starting with '~' are reserved for partially saved vaults." >&2
echo "If you're looking to open the partially saved vault file, please manually rename it in $MBV_FILE_LOCATION" >&2
exit 1
fi
if [ -e $MBV_FILE_LOCATION/$2.mbv2 ]
then
echo "Vault '$2' is already in the latest format!" >&2
exit 1
fi
if ! [ -e $MBV_FILE_LOCATION/$2.mbv ]
then
echo "Vault '$2' does not exist!" >&2
exit 1
fi
if [ -e "$MBV_FILE_LOCATION/~$2.mbv" ]
then
echo "Vault '$2' has a partially saved vault file '~$2.mbv'!" >&2
echo "Please manually delete or move it in $MBV_FILE_LOCATION." >&2
exit 1
fi
if [ -e "$MBV_FILE_LOCATION/~$2.mbv2" ]
then
echo "Vault '$2' has a partially saved vault file '~$2.mbv2'!" >&2
echo "Please manually delete or move it in $MBV_FILE_LOCATION." >&2
exit 1
fi
echo "Checking used gpg key..."
key_id=$(gpg --list-packets $MBV_FILE_LOCATION/$2.mbv | grep -oP "[A-F0-9]{16}" | head -n 1)
if [ -z "$key_id" ]
then
echo "Unable to get key used, aborting" >&2
exit 1
fi
echo "Updating vault..."
file_size=$(du -sb $MBV_FILE_LOCATION/$2.mbv | awk '{print $1}')
gpg --decrypt -q $MBV_FILE_LOCATION/$2.mbv | pv -s $file_size | gzip -dc | zstd | gpg --encrypt -o $MBV_FILE_LOCATION/~$2.mbv2 -u $key_id -r $key_id --yes && chmod 600 $MBV_FILE_LOCATION/~$2.mbv2
if [[ $? -eq 0 ]]
then
echo "Moving vault into place & removing old vault version..."
mv $MBV_FILE_LOCATION/~$2.mbv2 $MBV_FILE_LOCATION/$2.mbv2 && rm "$MBV_FILE_LOCATION/$2.mbv" && (echo "Done!" && exit 0) || (echo "Failed!" && exit 1)
else
echo "Failed!"
exit 1
fi
else
echo "Invalid subcommand, use mini_vault help to see subcommands."
exit 1
fi