-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutilities.sh
More file actions
74 lines (65 loc) · 1.6 KB
/
utilities.sh
File metadata and controls
74 lines (65 loc) · 1.6 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
#!/usr/bin/env bash
askForReboot()
{
while true; do
read -rp "Reboot (recommended)? (y/n)" yn
case $yn in
[Yy]* ) reboot; exit;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
}
# Takes two arguments
# First is name of service to wait for
# Second is period to wait after attempting to wait for service (not all services properly report)
startServiceAndWaitUntilItIsRunning()
{
isActive=$(systemctl status "$1" | grep "Active: active (running)\|Active: active (listening)")
systemctl enable --now $1
while [ -z "$isActive" ] ; do
echo "Waiting for $1 to become active"
sleep 3
isActive=$(systemctl status "$1" | grep "Active: active (running)\|Active: active (listening)")
done
if [ ! -z "$2" ]; then
sleep $(($2))
fi
}
function getMaxKey()
{
local max=-1
local array=("$@")
for key in "${!array[@]}"; do
if [ $((${key})) -gt $((${max})) ]; then
max=${key}
fi
done
echo "$max";
}
uncommentZshrcPath()
{
if grep -Eqs "^export PATH=(.*)" "$ZSHRC_FILE"
then
echo ".zshrc PATH already uncommented. skipping...";
else
sed -i '/^\# export PATH=\(.*\)/{p;s//export PATH=\1/;}' "$ZSHRC_FILE"
fi
}
addToZshrcPath()
{
uncommentZshrcPath;
if grep -Fqs "$1" "$ZSHRC_FILE"
then
echo ".zshrc PATH already contains '$1'. skipping...";
else
sed -i "s@^\(export PATH=\)\(.*\)\(:\$PATH\)@\1\2:$1\3@g" "$ZSHRC_FILE";
fi
}
getlatesttag()
{
git -c 'versionsort.suffix=-' \
ls-remote --exit-code --refs --sort='version:refname' --tags "$1" '*.*.*' |
tail --lines=1 |
cut --delimiter='/' --fields=3
}