pvincent
1 month ago
3 changed files with 287 additions and 0 deletions
-
210recipes/limesurvey/crud.sh
-
61recipes/limesurvey/install.sh
-
16templates/apps/limesurvey/limesurvey-host.j2
@ -0,0 +1,210 @@ |
|||
#!/bin/bash |
|||
|
|||
function check_database_exists() { |
|||
db-maria list | grep -q "$longname" |
|||
} |
|||
|
|||
function check_port_used() { |
|||
# shellcheck disable=SC2034 |
|||
usedport=$(lxc exec "$container" -- bash -c "grep listen /etc/nginx/sites-enabled/$longname.conf | cut -d' ' -f6") |
|||
[[ "$usedport" == "$port" ]] |
|||
} |
|||
|
|||
function check_service_running() { |
|||
lxc exec "$container" -- bash -c "systemctl is-active --quiet nginx.service" |
|||
} |
|||
|
|||
function _read() { |
|||
disable_trace |
|||
check_database_exists |
|||
check_container "$container" |
|||
check_port_used |
|||
check_service_running |
|||
enable_trace |
|||
return 0 |
|||
} |
|||
|
|||
function _create() { |
|||
|
|||
echo "creating limesurvey instance for <$shortname> ..." |
|||
|
|||
mkdir -p "$MIAOU_CONFIGDIR/apps/limesurvey" |
|||
APP_PORT=$port APP_NAME=$shortname tera -e --env-key env -t "$MIAOU_BASEDIR/templates/apps/limesurvey/limesurvey-host.j2" -o "$MIAOU_CONFIGDIR/apps/limesurvey/$shortname.conf" "$MIAOU_CONFIGDIR/miaou.expanded.yaml" |
|||
echo "creating templates ... OK" |
|||
|
|||
echo "copying files to container <$container> ... " |
|||
lxc file push --uid 0 --gid 0 "$MIAOU_CONFIGDIR/apps/limesurvey/$shortname.conf" "$container/etc/nginx/sites-available/$longname.conf" |
|||
echo "copying files to container <$container> ... OK" |
|||
|
|||
if ! (db-maria list | grep -q "$longname"); then |
|||
echo "create empty database <$longname> ... " |
|||
db-maria create "$longname" |
|||
echo "create empty database <$longname> ... OK" |
|||
else |
|||
echo "database already exists!" |
|||
fi |
|||
|
|||
echo "initialize limesurvey $shortname $longname ..." |
|||
lxc exec "$container" -- bash <<EOF |
|||
set -Eeuo pipefail |
|||
if [[ ! -d /var/www/limesurvey/$shortname ]]; then |
|||
echo "installing new instance of limesurvey into /var/www/limesurvey/$shortname" |
|||
unzip -q /var/www/limesurvey-latest.zip -d /var/www/limesurvey/$shortname |
|||
mv /var/www/limesurvey/$shortname/limesurvey/* /var/www/limesurvey/$shortname |
|||
rm -rf /var/www/limesurvey/$shortname/limesurvey |
|||
else |
|||
echo "instance of limesurvey /var/www/limesurvey/$shortname already defined!" |
|||
fi |
|||
|
|||
if [[ ! -f /var/www/limesurvey/$shortname/application/config/config.php ]]; then |
|||
echo "create config.php" |
|||
cat << 'EOT2' > /var/www/limesurvey/$shortname/application/config/config.php |
|||
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); |
|||
return array( |
|||
'components' => array( |
|||
'db' => array( |
|||
'connectionString' => 'mysql:host=ct1.lxd;port=3306;dbname=$longname;', |
|||
'username' => '$longname', |
|||
'password' => '$longname', |
|||
'charset' => 'utf8mb4', |
|||
'emulatePrepare' => true, |
|||
'tablePrefix' => '', |
|||
), |
|||
|
|||
'session' => array ( |
|||
'sessionName'=>'$(genpasswd 10)', |
|||
), |
|||
|
|||
'urlManager' => array( |
|||
'urlFormat' => 'get', |
|||
'rules' => array(), |
|||
'showScriptName' => true, |
|||
), |
|||
|
|||
), |
|||
'config'=>array( |
|||
'debug'=>0, |
|||
'debugsql'=>0, // Set this to 1 to enanble sql logging, only active when debug = 2 |
|||
'mysqlEngine' => 'MYISAM', |
|||
) |
|||
); |
|||
EOT2 |
|||
echo 'initializing admin...' |
|||
cd /var/www/limesurvey/$shortname/application/commands |
|||
set +e |
|||
php console.php install pvincent reunion pvincent pvincent@arcode.re |
|||
[[ \$? -ne 0 ]] && echo 'already initialized!' |
|||
set -e |
|||
echo OK |
|||
echo 'Please visit URL with ?r=admin to log in!' |
|||
|
|||
else |
|||
echo "config.php already defined!" |
|||
fi |
|||
|
|||
chown -R www-data:www-data /var/www/limesurvey/$shortname |
|||
|
|||
echo "enabling limesurvey host into nginx" |
|||
ln -sf "/etc/nginx/sites-available/$longname.conf" "/etc/nginx/sites-enabled/$longname.conf" |
|||
|
|||
echo "reloading nginx" |
|||
nginx -tq && systemctl reload nginx |
|||
EOF |
|||
echo "initialize limesurvey $shortname $longname ... OK" |
|||
} |
|||
|
|||
function _update() { |
|||
echo "update" |
|||
} |
|||
|
|||
function _delete() { |
|||
echo "delete" |
|||
} |
|||
|
|||
function usage() { |
|||
echo "Usage: $COMMAND_NAME -c|r|u|d --port PORT --container CONTAINER --name NAME" |
|||
exit 2 |
|||
} |
|||
|
|||
### MAIN |
|||
|
|||
# init_strict |
|||
|
|||
COMMAND_NAME=$(basename "$0") |
|||
|
|||
# read the options |
|||
|
|||
TEMP=$(getopt -n "$COMMAND_NAME" -o crud --long port:,container:,name:,fqdn:,domain:,subdomain: -- "$@") |
|||
# shellcheck disable=SC2181 |
|||
[[ "$?" -eq 0 ]] || usage |
|||
eval set -- "$TEMP" |
|||
|
|||
action="unset" |
|||
port="unset" |
|||
container="unset" |
|||
shortname="unset" |
|||
longname="unset" |
|||
|
|||
# extract options and their arguments into variables. |
|||
while true; do |
|||
case "$1" in |
|||
--port) |
|||
port=$2 |
|||
shift 2 |
|||
;; |
|||
--fqdn) |
|||
shift 2 |
|||
;; |
|||
--container) |
|||
container=$2 |
|||
shift 2 |
|||
;; |
|||
--name) |
|||
shortname=$2 |
|||
longname="limesurvey-$shortname" |
|||
shift 2 |
|||
;; |
|||
--domain) |
|||
shift 2 |
|||
;; |
|||
--subdomain) |
|||
shift 2 |
|||
;; |
|||
-c) |
|||
[[ "$action" == "unset" ]] || usage |
|||
action="_create" |
|||
shift 1 |
|||
;; |
|||
-r) |
|||
[[ "$action" == "unset" ]] || usage |
|||
action="_read" |
|||
shift 1 |
|||
;; |
|||
-u) |
|||
[[ "$action" == "unset" ]] || usage |
|||
action="_update" |
|||
shift 1 |
|||
;; |
|||
-d) |
|||
[[ "$action" == "unset" ]] || usage |
|||
action="_delete" |
|||
shift 1 |
|||
;; |
|||
--) |
|||
shift |
|||
break |
|||
;; |
|||
*) |
|||
echoerr "Internal error: unrecognized option: <$1>" |
|||
exit 1 |
|||
;; |
|||
esac |
|||
done |
|||
|
|||
. "$MIAOU_BASEDIR/lib/init.sh" |
|||
[[ |
|||
"$action" != unset && |
|||
"$port" != unset && |
|||
"$container" != unset && |
|||
"$shortname" != unset ]] || usage |
|||
$action |
@ -0,0 +1,61 @@ |
|||
#!/bin/bash |
|||
|
|||
MANDATORY_PACKAGES_STRING="nginx php-fpm php-mysql php-zip php-gd php-xml php-ldap php-imap composer mariadb-client" |
|||
|
|||
### CHECK |
|||
|
|||
function check() { |
|||
PREFIX="recipe:limesurvey:check" |
|||
check_mandatory_packages || return 21 |
|||
check_limesurvey_zip || return 22 |
|||
return 0 |
|||
} |
|||
|
|||
function check_mandatory_packages() { |
|||
lxc exec "$CONTAINER" -- bash <<EOF |
|||
set -Eeuo pipefail |
|||
mapfile -t PACKAGES <<< "$MANDATORY_PACKAGES_STRING" |
|||
for package in \${PACKAGES[@]}; do |
|||
dpkg -l "\$package" 2>/dev/null | grep -q ^ii |
|||
done |
|||
EOF |
|||
} |
|||
|
|||
function check_limesurvey_zip() { |
|||
lxc exec "$CONTAINER" -- test -f /var/www/limesurvey-latest.zip |
|||
} |
|||
|
|||
### INSTALL |
|||
|
|||
function install() { |
|||
PREFIX="recipe:limesurvey:install" |
|||
: $PREFIX |
|||
launch_container "$CONTAINER" |
|||
echo "initializing limesurvey ... " |
|||
|
|||
lxc exec "$CONTAINER" -- bash <<EOF |
|||
set -Eeuo pipefail |
|||
echo installing limesurvey... |
|||
apt-get install -y $MANDATORY_PACKAGES_STRING |
|||
rm -f /etc/nginx/sites-enabled/default |
|||
rm -f /etc/nginx/sites-available/default |
|||
systemctl reload nginx |
|||
|
|||
latest_release=\$(curl -s https://community.limesurvey.org/downloads/ | grep 'https://download.limesurvey.org/latest-master/.*\.zip' -o) |
|||
wget "\$latest_release" -qO /var/www/limesurvey-latest.zip |
|||
mkdir -p /var/www/limesurvey |
|||
EOF |
|||
echo "OK" |
|||
|
|||
} |
|||
|
|||
### MAIN |
|||
|
|||
. "$MIAOU_BASEDIR/lib/init.sh" |
|||
arg1_required "$@" |
|||
readonly CONTAINER="$1" |
|||
|
|||
check || ( |
|||
install |
|||
check |
|||
) |
@ -0,0 +1,16 @@ |
|||
server { |
|||
listen {{ env.APP_PORT }}; |
|||
server_name localhost; |
|||
root /var/www/limesurvey/{{ env.APP_NAME }}; |
|||
|
|||
index index.php; |
|||
|
|||
location / { |
|||
try_files $uri $uri/ /index.php?$args; |
|||
} |
|||
|
|||
location ~ \.php$ { |
|||
include snippets/fastcgi-php.conf; |
|||
fastcgi_pass unix:/var/run/php/php-fpm.sock; |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue