mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-12-25 08:10:12 +01:00
Refactored postinstall.sh script
Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
parent
3d1c52be12
commit
111bcce6e0
19
util/config-site.php.in
Normal file
19
util/config-site.php.in
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$config['SITE_NAME'] = '$HOSTNAME';
|
||||||
|
$config['SITE_URL'] = 'http://' . $config['SITE_NAME'] . '/';
|
||||||
|
$config['DIR_BASE'] = '$DOCROOT/';
|
||||||
|
|
||||||
|
$config['SMTP_DOMAIN'] = '$HOSTNAME';
|
||||||
|
$config['SMTP_FROMADDR'] = 'no-reply@' . $config['SMTP_DOMAIN'];
|
||||||
|
$config['ADMIN_EMAIL'] = 'admin@' . $config['SMTP_DOMAIN'];
|
||||||
|
|
||||||
|
$config['DB_DRIVER'] = 'mysql';
|
||||||
|
$config['DB_PREFIX'] = '';
|
||||||
|
$config['DB_HOSTNAME'] = '$MYSQL_HOSTNAME';
|
||||||
|
$config['DB_USERNAME'] = '$MYSQL_USERNAME';
|
||||||
|
$config['DB_PASSWORD'] = '$MYSQL_PASSWORD';
|
||||||
|
$config['DB_DATABASE'] = '$MYSQL_DATABASE';
|
||||||
|
|
||||||
|
$config['SMARTHOST'] = '$SMARTHOST';
|
||||||
|
$config['SMARTHOST_PORT'] = '$SMARTHOST_PORT';
|
@ -1,26 +1,32 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -o nounset
|
||||||
|
set -o errexit
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
INDEXER=$(which indexer 2>/dev/null)
|
SCRIPT_PATH="$(readlink -f "$0")"
|
||||||
SEARCHD=$(which searchd 2>/dev/null)
|
SCRIPT_DIR="${SCRIPT_PATH%/*}"
|
||||||
|
|
||||||
|
INDEXER="$(command -v indexer)"
|
||||||
|
SEARCHD="$(command -v searchd)"
|
||||||
CRON_ORIG="/tmp/crontab.piler.orig"
|
CRON_ORIG="/tmp/crontab.piler.orig"
|
||||||
CRON_TMP="/tmp/crontab.piler"
|
CRON_TMP="/tmp/crontab.piler"
|
||||||
PILERCONF_TMP="/tmp/config.piler.88"
|
PILERCONF_TMP="/tmp/config.piler.88"
|
||||||
SOCKET_HELPER_SCRIPT="aaa.pl"
|
SOCKET_HELPER_SCRIPT="aaa.pl"
|
||||||
CONFIG_SITE_PHP="${SYSCONFDIR}/piler/config-site.php"
|
PILER_CONFIG_DIR="${SYSCONFDIR}/piler"
|
||||||
|
CONFIG_SITE_PHP="${PILER_CONFIG_DIR}/config-site.php"
|
||||||
|
|
||||||
load_default_values() {
|
load_default_values() {
|
||||||
PILERUSER="piler"
|
PILERUSER="piler"
|
||||||
PILERGROUP="piler"
|
|
||||||
SYSCONFDIR=__SYSCONFDIR
|
SYSCONFDIR=__SYSCONFDIR
|
||||||
LOCALSTATEDIR=__LOCALSTATEDIR
|
LOCALSTATEDIR=__LOCALSTATEDIR
|
||||||
LIBEXECDIR=__LIBEXECDIR
|
LIBEXECDIR=__LIBEXECDIR
|
||||||
DATAROOTDIR=__DATAROOTDIR
|
DATAROOTDIR=__DATAROOTDIR
|
||||||
|
|
||||||
KEYTMPFILE="piler.key"
|
KEYTMPFILE="piler.key"
|
||||||
KEYFILE="${SYSCONFDIR}/piler/piler.key"
|
KEYFILE="${PILER_CONFIG_DIR}/piler.key"
|
||||||
|
|
||||||
HOSTNAME=$(hostname --fqdn)
|
HOSTNAME="$(hostname --fqdn)"
|
||||||
|
|
||||||
MYSQL_HOSTNAME="localhost"
|
MYSQL_HOSTNAME="localhost"
|
||||||
MYSQL_DATABASE="piler"
|
MYSQL_DATABASE="piler"
|
||||||
@ -29,7 +35,7 @@ load_default_values() {
|
|||||||
MYSQL_ROOT_PASSWORD=""
|
MYSQL_ROOT_PASSWORD=""
|
||||||
MYSQL_SOCKET=""
|
MYSQL_SOCKET=""
|
||||||
|
|
||||||
SPHINXCFG="${SYSCONFDIR}/piler/sphinx.conf"
|
SPHINXCFG="${PILER_CONFIG_DIR}/sphinx.conf"
|
||||||
|
|
||||||
WWWGROUP="apache"
|
WWWGROUP="apache"
|
||||||
DOCROOT="/var/piler/www"
|
DOCROOT="/var/piler/www"
|
||||||
@ -42,13 +48,15 @@ load_default_values() {
|
|||||||
|
|
||||||
|
|
||||||
make_certificate() {
|
make_certificate() {
|
||||||
if [[ ! -f "${SYSCONFDIR}/piler/piler.pem" ]]; then
|
local piler_pem="${PILER_CONFIG_DIR}/piler.pem"
|
||||||
|
|
||||||
|
if [[ ! -f "$piler_pem" ]]; then
|
||||||
echo -n "Making an ssl certificate ... "
|
echo -n "Making an ssl certificate ... "
|
||||||
openssl req -new -newkey rsa:4096 -days 3650 -nodes -x509 -subj "$SSL_CERT_DATA" -keyout "${SYSCONFDIR}/piler/piler.pem" -out 1.cert -sha1
|
openssl req -new -newkey rsa:4096 -days 3650 -nodes -x509 -subj "$SSL_CERT_DATA" -keyout "$piler_pem" -out 1.cert -sha1
|
||||||
cat 1.cert >> "${SYSCONFDIR}/piler/piler.pem"
|
cat 1.cert >> "$piler_pem"
|
||||||
chmod 640 "${SYSCONFDIR}/piler/piler.pem"
|
chmod 640 "$piler_pem"
|
||||||
chgrp "$PILERUSER" "${SYSCONFDIR}/piler/piler.pem"
|
chgrp "$PILERUSER" "$piler_pem"
|
||||||
rm 1.cert
|
rm -f 1.cert
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,7 +71,7 @@ display_install_intro() {
|
|||||||
askYN "Continue? [Y/N]" "N"
|
askYN "Continue? [Y/N]" "N"
|
||||||
if [[ "$response" != "yes" ]]; then
|
if [[ "$response" != "yes" ]]; then
|
||||||
echo "Aborted."
|
echo "Aborted."
|
||||||
exit
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
@ -79,18 +87,18 @@ check_user() {
|
|||||||
|
|
||||||
isFQDN() {
|
isFQDN() {
|
||||||
# we need min. 2 dots
|
# we need min. 2 dots
|
||||||
if [ x"$1" = "xdogfood" ]; then
|
if [[ x"$1" = "xdogfood" ]]; then
|
||||||
echo 1
|
echo 1
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ x"$1" = "x" ]; then
|
if [[ x"$1" = "x" ]]; then
|
||||||
echo 0
|
echo 0
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
NF=`echo $1 | awk -F. '{print NF}'`
|
NF="$(echo "$1" | awk -F. '{print NF}')"
|
||||||
if [ $NF -ge 2 ]; then
|
if [[ $NF -ge 2 ]]; then
|
||||||
echo 1
|
echo 1
|
||||||
else
|
else
|
||||||
echo 0
|
echo 0
|
||||||
@ -104,9 +112,9 @@ ask() {
|
|||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo -n "$PROMPT [$DEFAULT] "
|
echo -n "$PROMPT [$DEFAULT] "
|
||||||
read response
|
read -r response
|
||||||
|
|
||||||
if [ -z $response ]; then
|
if [[ -z "$response" ]]; then
|
||||||
response=$DEFAULT
|
response=$DEFAULT
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -126,12 +134,12 @@ askNonBlankNoEcho() {
|
|||||||
PROMPT=$1
|
PROMPT=$1
|
||||||
DEFAULT=$2
|
DEFAULT=$2
|
||||||
|
|
||||||
while [ 1 ]; do
|
while true; do
|
||||||
stty -echo
|
stty -echo
|
||||||
ask "$PROMPT" "$DEFAULT"
|
ask "$PROMPT" "$DEFAULT"
|
||||||
stty echo
|
stty echo
|
||||||
echo ""
|
echo ""
|
||||||
if [ ! -z $response ]; then
|
if [[ -n "$response" ]]; then
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
echo "A non-blank answer is required"
|
echo "A non-blank answer is required"
|
||||||
@ -140,12 +148,12 @@ askNonBlankNoEcho() {
|
|||||||
|
|
||||||
|
|
||||||
askNonBlank() {
|
askNonBlank() {
|
||||||
PROMPT=$1
|
PROMPT="$1"
|
||||||
DEFAULT=$2
|
DEFAULT="$2"
|
||||||
|
|
||||||
while [ 1 ]; do
|
while true; do
|
||||||
ask "$PROMPT" "$DEFAULT"
|
ask "$PROMPT" "$DEFAULT"
|
||||||
if [ ! -z $response ]; then
|
if [[ -n "$response" ]]; then
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
echo "A non-blank answer is required"
|
echo "A non-blank answer is required"
|
||||||
@ -157,23 +165,23 @@ askYN() {
|
|||||||
PROMPT=$1
|
PROMPT=$1
|
||||||
DEFAULT=$2
|
DEFAULT=$2
|
||||||
|
|
||||||
if [ "x$DEFAULT" = "xyes" -o "x$DEFAULT" = "xYes" -o "x$DEFAULT" = "xy" -o "x$DEFAULT" = "xY" ]; then
|
if [[ "x$DEFAULT" == "xyes" || "x$DEFAULT" == "xYes" || "x$DEFAULT" == "xy" || "x$DEFAULT" == "xY" ]]; then
|
||||||
DEFAULT="Y"
|
DEFAULT="Y"
|
||||||
else
|
else
|
||||||
DEFAULT="N"
|
DEFAULT="N"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
while [ 1 ]; do
|
while true; do
|
||||||
ask "$PROMPT" "$DEFAULT"
|
ask "$PROMPT" "$DEFAULT"
|
||||||
response=$(perl -e "print lc(\"$response\");")
|
response=$(perl -e "print lc(\"$response\");")
|
||||||
if [ -z $response ]; then
|
if [[ -z "$response" ]]; then
|
||||||
:
|
:
|
||||||
else
|
else
|
||||||
if [ $response = "yes" -o $response = "y" ]; then
|
if [[ "$response" == "yes" || "$response" == "y" ]]; then
|
||||||
response="yes"
|
response="yes"
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
if [ $response = "no" -o $response = "n" ]; then
|
if [[ "$response" == "no" || "$response" == "n" ]]; then
|
||||||
response="no"
|
response="no"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
@ -232,7 +240,7 @@ gather_mysql_account() {
|
|||||||
if [ $? -eq 0 ];
|
if [ $? -eq 0 ];
|
||||||
then
|
then
|
||||||
echo "mysql connection successful"; echo;
|
echo "mysql connection successful"; echo;
|
||||||
if [ $(echo $s | grep -c metadata) -eq 1 ]; then echo "ERROR: Detected metadata table in ${MYSQL_DATABASE}. Aborting"; exit 0; fi
|
if [[ $(echo "$s" | grep -c metadata) -eq 1 ]]; then echo "ERROR: Detected metadata table in ${MYSQL_DATABASE}. Aborting"; exit 0; fi
|
||||||
else
|
else
|
||||||
echo "ERROR: failed to connect to mysql";
|
echo "ERROR: failed to connect to mysql";
|
||||||
gather_mysql_account
|
gather_mysql_account
|
||||||
@ -254,37 +262,37 @@ make_cron_entries() {
|
|||||||
|
|
||||||
crontab -u "$PILERUSER" -l > "$CRON_ORIG"
|
crontab -u "$PILERUSER" -l > "$CRON_ORIG"
|
||||||
|
|
||||||
grep PILERSTART "$CRON_ORIG" > /dev/null 2>&1
|
if grep PILERSTART "$CRON_ORIG" > /dev/null 2>&1 != 0; then
|
||||||
if [ $? != 0 ]; then
|
|
||||||
cat /dev/null > "$CRON_ORIG"
|
cat /dev/null > "$CRON_ORIG"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
grep PILEREND "$CRON_ORIG" > /dev/null 2>&1
|
if grep PILEREND "$CRON_ORIG" > /dev/null 2>&1 != 0; then
|
||||||
if [ $? != 0 ]; then
|
|
||||||
cat /dev/null > "$CRON_ORIG"
|
cat /dev/null > "$CRON_ORIG"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
rm -f "$CRON_TMP"
|
rm -f "$CRON_TMP"
|
||||||
|
|
||||||
echo ""
|
{
|
||||||
echo "### PILERSTART" >> "$CRON_TMP"
|
echo "";
|
||||||
echo "5,35 * * * * ${LIBEXECDIR}/piler/indexer.delta.sh" >> "$CRON_TMP"
|
echo "### PILERSTART";
|
||||||
echo "30 2 * * * ${LIBEXECDIR}/piler/indexer.main.sh" >> "$CRON_TMP"
|
echo "5,35 * * * * ${LIBEXECDIR}/piler/indexer.delta.sh";
|
||||||
echo "3 * * * * ${LIBEXECDIR}/piler/watch_sphinx_main_index.sh" >> "$CRON_TMP"
|
echo "30 2 * * * ${LIBEXECDIR}/piler/indexer.main.sh";
|
||||||
echo "*/15 * * * * ${INDEXER} --quiet tag1 --rotate --config ${SYSCONFDIR}/piler/sphinx.conf" >> "$CRON_TMP"
|
echo "3 * * * * ${LIBEXECDIR}/piler/watch_sphinx_main_index.sh";
|
||||||
echo "*/15 * * * * ${INDEXER} --quiet note1 --rotate --config ${SYSCONFDIR}/piler/sphinx.conf" >> "$CRON_TMP"
|
echo "*/15 * * * * ${INDEXER} --quiet tag1 --rotate --config ${PILER_CONFIG_DIR}/sphinx.conf";
|
||||||
echo "30 6 * * * /usr/bin/php ${LIBEXECDIR}/piler/generate_stats.php --webui ${DOCROOT} >/dev/null" >> "$CRON_TMP"
|
echo "*/15 * * * * ${INDEXER} --quiet note1 --rotate --config ${PILER_CONFIG_DIR}/sphinx.conf";
|
||||||
echo "*/5 * * * * /usr/bin/find ${LOCALSTATEDIR}/piler/error -type f|wc -l > ${LOCALSTATEDIR}/piler/stat/error" >> "$CRON_TMP"
|
echo "30 6 * * * /usr/bin/php ${LIBEXECDIR}/piler/generate_stats.php --webui ${DOCROOT} >/dev/null";
|
||||||
echo "*/5 * * * * /usr/bin/find ${DOCROOT}/tmp -type f -name i.\* -exec rm -f {} \;" >> "$CRON_TMP"
|
echo "*/5 * * * * /usr/bin/find ${LOCALSTATEDIR}/piler/error -type f|wc -l > ${LOCALSTATEDIR}/piler/stat/error";
|
||||||
echo "### PILEREND" >> "$CRON_TMP"
|
echo "*/5 * * * * /usr/bin/find ${DOCROOT}/tmp -type f -name i.\* -exec rm -f {} \;";
|
||||||
|
echo "### PILEREND";
|
||||||
|
} >> "$CRON_TMP"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
make_new_key() {
|
make_new_key() {
|
||||||
dd if=/dev/urandom bs=56 count=1 of="$KEYTMPFILE" 2>/dev/null
|
dd if=/dev/urandom bs=56 count=1 of="$KEYTMPFILE" 2>/dev/null
|
||||||
|
|
||||||
if [ $(stat -c '%s' "$KEYTMPFILE") -ne 56 ]; then echo "could not read 56 bytes from /dev/urandom to ${KEYTMPFILE}"; exit 1; fi
|
if [ "$(stat -c '%s' "$KEYTMPFILE")" -ne 56 ]; then echo "could not read 56 bytes from /dev/urandom to ${KEYTMPFILE}"; exit 1; fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -399,39 +407,10 @@ SOCKHELPER
|
|||||||
|
|
||||||
|
|
||||||
webui_install() {
|
webui_install() {
|
||||||
|
|
||||||
chmod 770 "${DOCROOT}/tmp" "${DOCROOT}/images"
|
chmod 770 "${DOCROOT}/tmp" "${DOCROOT}/images"
|
||||||
chown "$PILERUSER" "${DOCROOT}/tmp"
|
chown "${PILERUSER}:${DOCROOT}" "${DOCROOT}/tmp"
|
||||||
chgrp "$WWWGROUP" "${DOCROOT}/tmp"
|
|
||||||
|
|
||||||
echo "<?php" > "$CONFIG_SITE_PHP"
|
envsubst "${SCRIPT_DIR}/config-site.php.in" > "$CONFIG_SITE_PHP"
|
||||||
echo >> "$CONFIG_SITE_PHP"
|
|
||||||
|
|
||||||
echo "\$config['SITE_NAME'] = '$HOSTNAME';" >> "$CONFIG_SITE_PHP"
|
|
||||||
echo "\$config['SITE_URL'] = 'http://' . \$config['SITE_NAME'] . '/';" >> "$CONFIG_SITE_PHP"
|
|
||||||
echo "\$config['DIR_BASE'] = '$DOCROOT/';" >> "$CONFIG_SITE_PHP"
|
|
||||||
|
|
||||||
echo >> "$CONFIG_SITE_PHP"
|
|
||||||
|
|
||||||
echo "\$config['SMTP_DOMAIN'] = '$HOSTNAME';" >> "$CONFIG_SITE_PHP"
|
|
||||||
echo "\$config['SMTP_FROMADDR'] = 'no-reply@$HOSTNAME';" >> "$CONFIG_SITE_PHP"
|
|
||||||
echo "\$config['ADMIN_EMAIL'] = 'admin@$HOSTNAME';" >> "$CONFIG_SITE_PHP"
|
|
||||||
|
|
||||||
echo >> "$CONFIG_SITE_PHP"
|
|
||||||
|
|
||||||
echo "\$config['DB_DRIVER'] = 'mysql';" >> "$CONFIG_SITE_PHP"
|
|
||||||
echo "\$config['DB_PREFIX'] = '';" >> "$CONFIG_SITE_PHP"
|
|
||||||
echo "\$config['DB_HOSTNAME'] = '$MYSQL_HOSTNAME';" >> "$CONFIG_SITE_PHP"
|
|
||||||
echo "\$config['DB_USERNAME'] = '$MYSQL_USERNAME';" >> "$CONFIG_SITE_PHP"
|
|
||||||
echo "\$config['DB_PASSWORD'] = '$MYSQL_PASSWORD';" >> "$CONFIG_SITE_PHP"
|
|
||||||
echo "\$config['DB_DATABASE'] = '$MYSQL_DATABASE';" >> "$CONFIG_SITE_PHP"
|
|
||||||
|
|
||||||
echo >> "$CONFIG_SITE_PHP"
|
|
||||||
|
|
||||||
echo "\$config['SMARTHOST'] = '$SMARTHOST';" >> "$CONFIG_SITE_PHP"
|
|
||||||
echo "\$config['SMARTHOST_PORT'] = $SMARTHOST_PORT;" >> "$CONFIG_SITE_PHP"
|
|
||||||
|
|
||||||
echo >> "$CONFIG_SITE_PHP"
|
|
||||||
|
|
||||||
echo "Done."
|
echo "Done."
|
||||||
}
|
}
|
||||||
@ -447,10 +426,6 @@ clean_up_temp_stuff() {
|
|||||||
load_default_values
|
load_default_values
|
||||||
|
|
||||||
|
|
||||||
#LOGFILE="/tmp/piler-install.log.$$"
|
|
||||||
#touch $LOGFILE
|
|
||||||
#chmod 600 $LOGFILE
|
|
||||||
|
|
||||||
preinstall_check
|
preinstall_check
|
||||||
|
|
||||||
display_install_intro
|
display_install_intro
|
||||||
|
Loading…
Reference in New Issue
Block a user