-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·142 lines (99 loc) · 2.42 KB
/
setup.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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/bash
BASEDIR=$(dirname "$(readlink -f "$0")")
cd $BASEDIR
pwd
WORKDATE=$(date +"%Y%m%d")
WORKSEC=$(date +"%s")
CONF_FILE=psf_settings.ini
PGHOST=${PGHOST:-localhost}
get_port_conf() {
PGCONF=$( which pg_config )
if [[ -z ${PGCONF} ]]; then
echo "pg_config not found"
exit
else
PGBIN=$(pg_config --bindir)
for (( i=5432; i<5450; i+=1 )); do
PG_READY=$( ${PGBIN}/pg_isready -p ${i} )
RES="${?}"
# echo "RES=${RES} ${i}"
if [[ "0" == ${RES} ]]; then
# echo "in res "
PGPORT="${i}"
PGPORTS+=(${i})
# echo "${PGPORT}"
fi
done
VARCNT=$( printf '%s\n' "${PGPORTS[@]}" | wc -w )
if [[ ${VARCNT} == "0" ]]; then
echo "
Found no postgres ports. Is it running?
Configuring PSF for default of 5432.
"
CONF_PGPORT=${PGPORT:-5432}
fi
if [[ ${VARCNT} == "1" ]]; then
echo "Found an open pg port on ${PGPORTS}"
CONF_PGPORT="${PGPORTS}"
fi
if [[ ${VARCNT} -gt "1" ]]; then
max=${PGPORTS[0]}
for n in "${PGPORTS[@]}" ; do
((n > max)) && max=$n
done
CONF_PGPORT="${max}"
echo "
Found multiple PostgreSQL ports active on: ${PGPORTS[@]}.
Configuring PSF for highest port: ${CONF_PGPORT}
"
fi
fi
}
get_pg_user() {
echo "In pg_get_user"
PGADMINUSER=${PGADMINUSER:-postgres}
PGUSER=${PGUSER:-psfadmin}
}
get_pg_database() {
PGDATABASE=${PGDATABASE:-psf}
}
check_setup_ini() {
CONF_MOVED="${CONF_FILE}_${WORKSEC}"
if [[ -s ${CONF_FILE} ]]; then
echo "${CONF_FILE} exists, moving it to ${CONF_MOVED}"
mv ${CONF_FILE} ${CONF_MOVED}
fi
do_setup_ini
}
do_setup_ini() {
echo "${CONF_FILE} does not exist, creating it."
cat << _EOF_ > ${CONF_FILE}
### PostgreSQL Configuration ###
export PGADMINUSER=${PGADMINUSER}
export PGUSER=${PGUSER}
export PGHOST=${PGHOST}
export PGPORT=${CONF_PGPORT}
export PGDATABASE=${PGDATABASE}
PARSED_DATA_TABLE=psf_files
PARSED_DB_ENABLED=1
PGQRY="${PGBIN}/psql -AtX -U \${PGUSER} -h \${PGHOST} -p \${PGPORT} -d \${PGDATABASE} -c "
PGOUT="${PGBIN}/psql -AtXq -U \${PGUSER} -h \${PGHOST} -p \${PGPORT} -d \${PGDATABASE} -f "
# Uses a YYYYMMDD, adding seconds might be helpful.
WORKDATE=\$(date +"%Y%m%d")
WORKSEC=\$(date +"%s")
# Find files that are:
NOT_NEWER_THAN=\$(date --date '-1 min' +"%H:%M:%S")
PARSED_SQL_OUT=$(pwd)/temp_sql/${PARSED_DATA_TABLE}-data-\${WORKSEC}.sql
MP3_EXT=mp3
_EOF_
}
get_port_conf
get_pg_user
get_pg_database
check_setup_ini
echo "
**** Detected Postgres, Setup psf_settings.ini ****
**** PLEASE CHECK OUR WORK! ****
If Everything looks good, Setup a cron to run $(pwd)/psf.sh
"
exit