-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathos.sh
More file actions
executable file
·86 lines (72 loc) · 2.68 KB
/
Copy pathos.sh
File metadata and controls
executable file
·86 lines (72 loc) · 2.68 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
#!/usr/bin/env bash
# shellcheck source=./modules/bash-commons/src/log.sh
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/log.sh"
# Return the available memory on the current OS in MB
function os_get_available_memory_mb {
free -m | awk 'NR==2{print $2}'
}
# Returns true (0) if this is an Amazon Linux server at the given version or false (1) otherwise. The version number
# can use regex. If you don't care about the version, leave it unspecified.
function os_is_amazon_linux {
local -r version="$1"
grep -q "Amazon Linux * $version" /etc/*release
}
# Returns true (0) if this is an Ubuntu server at the given version or false (1) otherwise. The version number
# can use regex. If you don't care about the version, leave it unspecified.
function os_is_ubuntu {
local -r version="$1"
grep -q "Ubuntu $version" /etc/*release
}
# Returns true (0) if this is a CentOS server at the given version or false (1) otherwise. The version number
# can use regex. If you don't care about the version, leave it unspecified.
function os_is_centos {
local -r version="$1"
grep -q "CentOS Linux release $version" /etc/*release
}
# Returns true (0) if this is a RedHat server at the given version or false (1) otherwise. The version number
# can use regex. If you don't care about the version, leave it unspecified.
function os_is_redhat {
local -r version="$1"
grep -q "Red Hat Enterprise Linux Server release $version" /etc/*release
}
# Returns true (0) if this is an OS X server or false (1) otherwise.
function os_is_darwin {
[[ $(uname -s) == "Darwin" ]]
}
# Validate that the given file has the given checksum of the given checksum type, where type is one of "md5" or
# "sha256".
function os_validate_checksum {
local -r filepath="$1"
local -r checksum="$2"
local -r checksum_type="$3"
case "$checksum_type" in
sha256)
log_info "Validating sha256 checksum of $filepath is $checksum"
echo "$checksum $filepath" | sha256sum -c
;;
md5)
log_info "Validating md5 checksum of $filepath is $checksum"
echo "$checksum $filepath" | md5sum -c
;;
*)
log_error "Unsupported checksum type: $checksum_type."
exit 1
esac
}
# Returns true (0) if this the given command/app is installed and on the PATH or false (1) otherwise.
function os_command_is_installed {
local -r name="$1"
command -v "$name" > /dev/null
}
# Get the username of the current OS user
function os_get_current_users_name {
id -u -n
}
# Get the name of the primary group for the current OS user
function os_get_current_users_group {
id -g -n
}
# Returns true (0) if the current user is root or sudo and false (1) otherwise.
function os_user_is_root_or_sudo {
[[ "$EUID" == 0 ]]
}