summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authormsquare <msquare@notrademark.de>2018-09-02 16:55:35 +0200
committerGitHub <noreply@github.com>2018-09-02 16:55:35 +0200
commita103bc06e28f5eca6ba9c28c81ae1227d689f224 (patch)
tree759d675b621eed86b20f14abe448e83fa8d22562 /bin
parentbd8ceda6830f97247b73932b85ce41af5b8d2ab0 (diff)
parent2bebbeb1919e1d370ac5c0668e0db5ea63e73292 (diff)
Merge pull request #452 from MyIgel/rebuild-database
Rebuild database
Diffstat (limited to 'bin')
-rwxr-xr-xbin/deploy.sh73
-rwxr-xr-xbin/migrate38
2 files changed, 111 insertions, 0 deletions
diff --git a/bin/deploy.sh b/bin/deploy.sh
new file mode 100755
index 00000000..b731e36a
--- /dev/null
+++ b/bin/deploy.sh
@@ -0,0 +1,73 @@
+#!/usr/bin/env bash
+
+set -e
+
+remote_host=
+remote_path=
+deploy_id=
+
+show_help(){
+ echo "Usage: $0 [OPTION]..." >&2
+ echo "Deploys a software with rsync over ssh" >&2
+ echo "The options -i, -p and -r are required" >&2
+ echo "" >&2
+ echo " -h Display this help screen" >&2
+ echo " -i <id> Sets the id, a unique name for the deployment" >&2
+ echo " -p <path> Define the base path on the server" >&2
+ echo " -r <host> The remote server name and user" >&2
+}
+
+while getopts ":hi:p:r:" opt; do
+ case ${opt} in
+ h)
+ show_help
+ exit 1
+ ;;
+ r)
+ remote_host="$OPTARG"
+ ;;
+ p)
+ remote_path="$OPTARG"
+ ;;
+ i)
+ deploy_id="$OPTARG"
+ ;;
+ \?)
+ echo "Invalid option: -$OPTARG" >&2
+ exit 1
+ ;;
+ :)
+ echo "The option -$OPTARG requires an argument" >&2
+ exit 1
+ ;;
+ esac
+done
+
+if [ -z "${remote_host}" ] || [ -z "${remote_path}" ] || [ -z "${deploy_id}" ]; then
+ show_help
+ exit 1
+fi
+
+echo "syncing ${PWD}/ to ${remote_host}:${remote_path}/${deploy_id}/"
+
+rsync -vAax --exclude '.git*' --exclude .composer/ --exclude coverage/ --exclude node_modules/ \
+ -e "ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" \
+ ./ "${remote_host}:${remote_path}/${deploy_id}/"
+
+ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "${remote_host}" "
+ set -e
+
+ if [[ -f \"${remote_path}/current/config/config.php\" ]]; then
+ echo \"Config backup\"
+ cp \"${remote_path}/current/config/config.php\" \"${deploy_id}-config.php\"
+ fi
+
+ echo \"Changing symlink\"
+ unlink_cmd=\$(command -v unlink || command -v rm)
+ \$unlink_cmd \"${remote_path}/current\" && ln -s \"${remote_path}/${deploy_id}\" \"${remote_path}/current\"
+
+ if [[ -f \"${deploy_id}-config.php\" ]]; then
+ echo \"Restoring config\"
+ cp \"${deploy_id}-config.php\" \"${remote_path}/current/config/config.php\"
+ fi
+"
diff --git a/bin/migrate b/bin/migrate
new file mode 100755
index 00000000..ab3598d4
--- /dev/null
+++ b/bin/migrate
@@ -0,0 +1,38 @@
+#!/usr/bin/env php
+<?php
+
+use Composer\Autoload\ClassLoader;
+use Engelsystem\Application;
+use Engelsystem\Database\Migration\Migrate;
+use Engelsystem\Database\Migration\MigrationServiceProvider;
+
+require_once __DIR__ . '/../includes/application.php';
+
+/** @var $loader ClassLoader */
+$baseDir = __DIR__ . '/../db/migrations';
+
+/** @var Application $app */
+$app = app();
+$app->register(MigrationServiceProvider::class);
+
+/** @var Migrate $migration */
+$migration = $app->get('db.migration');
+$migration->setOutput(function ($text) { echo $text . PHP_EOL; });
+
+if (isset($argv[1]) && strtolower($argv[1]) == 'help') {
+ echo PHP_EOL . 'Usage: ' . $argv[1] . ' [up|down] [one-step]' . PHP_EOL . PHP_EOL;
+ exit;
+}
+
+$method = Migrate::UP;
+if (isset($argv[1]) && strtolower($argv[1]) == 'down') {
+ $argv = array_values($argv);
+ $method = Migrate::DOWN;
+}
+
+$oneStep = false;
+if (isset($argv[2]) && strtolower($argv[2]) == 'one-step') {
+ $oneStep = true;
+}
+
+$migration->run($baseDir, $method, $oneStep);