forked from reynico/raspberry-noaa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.sh
executable file
·56 lines (41 loc) · 1.11 KB
/
common.sh
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
#!/bin/bash
## debug
# set -x
. "$HOME/.noaa.conf"
declare -A levels=([DEBUG]=0 [INFO]=1 [WARN]=2 [ERROR]=3)
log_level=${LOG_LEVEL}
## log function
log() {
local log_message=$1
local log_priority=$2
#check if level exists
[[ ${levels[$log_priority]} ]] || return 1
#check if level is enough
(( ${levels[$log_priority]} < ${levels[$log_level]} )) && return 2
#log here
echo "${log_priority} : ${log_message}"
}
## current date and folder structure
START_DATE=$(date '+%d-%m-%Y %H:%M')
## sane checks
if [ ! -d "${NOAA_HOME}" ]; then
mkdir -m 775 -p "${NOAA_HOME}"
fi
if [ ! -d "${NOAA_OUTPUT}/audio/" ]; then
mkdir -m 775 -p "${NOAA_OUTPUT}/audio/"
fi
if [ ! -d "${METEOR_OUTPUT}/audio/" ]; then
mkdir -m 775 -p "${METEOR_OUTPUT}/audio/"
fi
if [ ! -d "${RAMFS_AUDIO}/audio/" ]; then
mkdir -m 775 -p "${RAMFS_AUDIO}/audio/"
fi
if [ ! -d "${NOAA_OUTPUT}/images/thumb" ]; then
mkdir -m 775 -p "${NOAA_OUTPUT}/images/thumb"
fi
if [ ! -d "${NOAA_HOME}/map/" ]; then
mkdir -m 775 -p "${NOAA_HOME}/map/"
fi
if [ ! -d "${NOAA_HOME}/predict/" ]; then
mkdir -m 775 -p "${NOAA_HOME}/predict/"
fi