Repository navigation
Expand file tree
/
Copy pathfsit
More file actions
106 lines (90 loc) · 2.22 KB
/
Copy pathfsit
File metadata and controls
106 lines (90 loc) · 2.22 KB
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
#!/usr/bin/env bash
#cito M:755 O:0 G:0 T:/usr/local/bin/fsit
#------------------------------------------------------------------------------
# Project Name - ShellProjects/source/fsit
# Started On - Thu 28 Sep 23:58:07 BST 2017
# Last Change - Wed 23 Aug 18:45:05 BST 2023
# Author E-Mail - terminalforlife@yahoo.com
# Author GitHub - https://github.com/terminalforlife
#------------------------------------------------------------------------------
# Do nothing until the given file is touched.
#
# Features:
#
# N/A
#
# Bugs:
#
# N/A
#
# Dependencies:
#
# bash (>= 3.2.48)
#------------------------------------------------------------------------------
CurVer='2023-08-23'
Progrm='fsit'
Usage() {
read -d '' <<-EOF
Usage: $Progrm [OPTS] FILE
-h, --help - Displays this help information.
-v, --version - Output only the version datestamp.
-i, --interval N - Use a check interval of N seconds.
By default, the checking interval is 0.3 seconds.
EOF
printf '%s' "$REPLY"
}
Err() {
printf 'Err: %s\n' "$2" 1>&2
(( $1 > 0 )) && exit $1
}
while [[ -n $1 ]]; do
case $1 in
--help|-h)
Usage; exit 0 ;;
--version|-v)
printf '%s\n' "$CurVer"; exit 0 ;;
--interval|-i)
if [[ -z $2 ]]; then
Err 1 "Option '$1' requires an argument."
elif [[ $2 =~ ^([[:digit:]]+|[[:digit:]]+.[[:digit:]]+)$ ]]; then
shift; Interval=$1
else
Err 1 "Option '$1' given invalid argument."
fi ;;
-*)
Err 1 'Incorrect argument(s) specified.' ;;
*)
break ;;
esac
shift
done
if (( $# == 0 )); then
Err 1 'File required.'
elif (( $# > 1 )); then
Err 1 'Too many arguments.'
fi
Interactive=
[[ -t 1 ]] && Interactive='sleep'
DepCount=0
for Dep in stat $Interactive; do
if ! type -P "$Dep" &> /dev/null; then
Err 0 "Dependency '$Dep' not met."
(( DepCount++ ))
fi
done
(( DepCount > 0 )) && exit 1
Original=`stat -c '%Y' "$1" 2> /dev/null`
while :; do
if ! [[ -f $1 ]]; then
Err 1 "File '$1' not found."
elif ! [[ -r $1 ]]; then
Err 1 "File '$1' unreadable."
fi
(( Current > Original )) && break
if [[ -z $Interactive ]]; then
read -n 1 -st ${Interval:-0.3}
else
sleep ${Interval:-0.3}s
fi
Current=`stat -c '%Y' "$1" 2> /dev/null`
done