-
Notifications
You must be signed in to change notification settings - Fork 0
/
.fun
42 lines (39 loc) · 1.26 KB
/
.fun
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
#!/bin/bash
# Helper functions
## Detect current operating system
function os
{
UNAME=$(uname -a)
if [ $(echo $UNAME | awk '{print $1}') == "Darwin" ]; then
export OPERATING_SYSTEM="MacOS"
elif [ $(echo $UNAME | awk '{print $1}') == "Linux" ]; then
export OPERATING_SYSTEM="Linux"
elif [ ${UNAME:0:5} == "MINGW" ]; then
export OPERATING_SYSTEM="Windows"
export MSYS_NO_PATHCONV=1 # turn off path conversion
else
export OPERATING_SYSTEM="Other"
fi
}
## End os function
os
## Determine current host IP address
function hostip
{
case "${OPERATING_SYSTEM}" in
"Linux")
export HOST_IP=$(hostname -I | tr " " "\n" | head -1) # Linux
;;
"MacOS")
export HOST_IP=$(ifconfig | grep -v 127.0.0.1 | grep -v inet6 | grep inet | head -n 1 | awk '{print $2}') # Mac OS
;;
"Windows")
export HOST_IP=$( ((ipconfig | grep IPv4 | grep 10.187 | tail -1) && (ipconfig | grep IPv4 | grep 3. | head -1)) | tail -1 | awk '{print $14}' ) # Git bash
;;
*)
export HOST_IP=$(hostname)
;;
esac
}
## End hostip function
hostip