commit 22ed076ccf72e58096b6987ec861a502009ef545 Author: sHa Date: Fri Jun 7 09:31:24 2019 +0300 first init diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..2e7302d --- /dev/null +++ b/.env.example @@ -0,0 +1,3 @@ +STREAM_NAME=announce +ZULIP_HOST=shadoll.zulipchat.com +ZULIP_HASH=VUsqHUhn5AKndXSUKddYpTsNJm7kPKNY diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..60adae0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +!/**/.gitkeep +.env diff --git a/package.json b/package.json new file mode 100644 index 0000000..7d8a114 --- /dev/null +++ b/package.json @@ -0,0 +1,14 @@ +{ + "name": "sscripts", + "version": "1.0.0", + "description": "Useful Shell scripts for projects", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "sHa ", + "license": "MIT", + "bin": { + "hello.sh": "./scripts/hello.sh", + "hello.js": "./scripts/hello.js" + } +} diff --git a/scripts/app.artisan.sh b/scripts/app.artisan.sh new file mode 100755 index 0000000..8b2e414 --- /dev/null +++ b/scripts/app.artisan.sh @@ -0,0 +1,10 @@ +#!/bin/bash +# +# @package sscripts +# @author sHa +# @copyright 2019 shadoll +# @version 19.6.7 +# @link https://shadoll.dev +# + +docker-compose exec app php artisan "$@" diff --git a/scripts/app.composer.sh b/scripts/app.composer.sh new file mode 100755 index 0000000..29ed070 --- /dev/null +++ b/scripts/app.composer.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# +# @package sscripts +# @author sHa +# @copyright 2019 shadoll +# @version 19.6.7 +# @link https://shadoll.dev +# + + +docker-compose exec app composer "$@" diff --git a/scripts/app.git.sh b/scripts/app.git.sh new file mode 100755 index 0000000..1f63372 --- /dev/null +++ b/scripts/app.git.sh @@ -0,0 +1,10 @@ +#!/bin/bash +# +# @package sscripts +# @author sHa +# @copyright 2019 shadoll +# @version 19.6.7 +# @link https://shadoll.dev +# + +docker-compose exec app git "$@" diff --git a/scripts/app.npm.sh b/scripts/app.npm.sh new file mode 100755 index 0000000..831a643 --- /dev/null +++ b/scripts/app.npm.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# +# @package sscripts +# @author sHa +# @copyright 2019 shadoll +# @version 19.6.7 +# @link https://shadoll.dev +# + +# appname=$(awk -F'=' '/^APPNAME/ { print $2}' ./docker/.env) + +docker-compose exec app npm "$@" diff --git a/scripts/app.php.sh b/scripts/app.php.sh new file mode 100755 index 0000000..1b1cfc3 --- /dev/null +++ b/scripts/app.php.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# +# @package sscripts +# @author sHa +# @copyright 2019 shadoll +# @version 19.6.7 +# @link https://shadoll.dev +# + +# appname=$(awk -F'=' '/^APPNAME/ { print $2}' ./docker/.env) + +docker-compose exec app php "$@" diff --git a/scripts/app.yarn.sh b/scripts/app.yarn.sh new file mode 100755 index 0000000..5649a01 --- /dev/null +++ b/scripts/app.yarn.sh @@ -0,0 +1,10 @@ +#!/bin/bash +# +# @package sscripts +# @author sHa +# @copyright 2019 shadoll +# @version 19.6.7 +# @link https://shadoll.dev +# + +docker-compose exec app yarn "$@" diff --git a/scripts/db.dump.sh b/scripts/db.dump.sh new file mode 100755 index 0000000..f830ead --- /dev/null +++ b/scripts/db.dump.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# +# @package sscripts +# @author sHa +# @copyright 2019 shadoll +# @version 19.6.7 +# @link https://shadoll.dev +# + +DIR=$(dirname "$0") +ROOT=$(cd "$DIR"/.. && pwd) + +DATABASE=$(awk -F'=' '/^MYSQL_DATABASE/ { print $2}' $ROOT/docker/config.env) +PWD=$(awk -F'=' '/^MYSQL_ROOT_PASSWORD/ { print $2}' $ROOT/docker/config.env) + +docker-compose exec db /usr/bin/mysqldump --skip-comments -uroot --password=$PWD $DATABASE > $ROOT/storage/database/dump/database.sql 2>/dev/null diff --git a/scripts/db.restore.sh b/scripts/db.restore.sh new file mode 100755 index 0000000..fc64b73 --- /dev/null +++ b/scripts/db.restore.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# +# @package sscripts +# @author sHa +# @copyright 2019 shadoll +# @version 19.6.7 +# @link https://shadoll.dev +# + +DIR=$(dirname "$0") +ROOT=$(cd "$DIR"/.. && pwd) + +DATABASE=$(awk -F'=' '/^MYSQL_DATABASE/ { print $2}' $ROOT/docker/config.env) +PWD=$(awk -F'=' '/^MYSQL_ROOT_PASSWORD/ { print $2}' $ROOT/docker/config.env) + +docker-compose exec db /usr/bin/mysql -uroot --password=$PWD $DATABASE < $ROOT/storage/database/dump/database.sql diff --git a/scripts/docker.down.sh b/scripts/docker.down.sh new file mode 100755 index 0000000..b17b2b2 --- /dev/null +++ b/scripts/docker.down.sh @@ -0,0 +1,10 @@ +#!/bin/bash +# +# @package sscripts +# @author sHa +# @copyright 2019 shadoll +# @version 19.6.7 +# @link https://shadoll.dev +# + +docker-compose down "$@" diff --git a/scripts/docker.firstrun.sh b/scripts/docker.firstrun.sh new file mode 100755 index 0000000..d530eb9 --- /dev/null +++ b/scripts/docker.firstrun.sh @@ -0,0 +1,19 @@ +#!/bin/bash +# +# @package sscripts +# @author sHa +# @copyright 2019 shadoll +# @version 19.6.7 +# @link https://shadoll.dev +# + +DIR=$(dirname "$0") +ROOT=$(cd "$DIR"/.. && pwd) + +$ROOT/bin/app.composer install +$ROOT/bin/app.composer run-script post-root-package-install +$ROOT/bin/app.composer dump-autoload --optimize + +$ROOT/bin/fix_permissions + +$ROOT/bin/db.restore diff --git a/scripts/docker.up.sh b/scripts/docker.up.sh new file mode 100755 index 0000000..7948adc --- /dev/null +++ b/scripts/docker.up.sh @@ -0,0 +1,10 @@ +#!/bin/bash +# +# @package sscripts +# @author sHa +# @copyright 2019 shadoll +# @version 19.6.7 +# @link https://shadoll.dev +# + +docker-compose up -d "$@" diff --git a/scripts/fix_permissions.sh b/scripts/fix_permissions.sh new file mode 100755 index 0000000..96152c4 --- /dev/null +++ b/scripts/fix_permissions.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# +# @package sscripts +# @author sHa +# @copyright 2019 shadoll +# @version 19.6.7 +# @link https://shadoll.dev +# + +DIR=$(dirname "$0") +ROOT=$(cd "$DIR"/.. && pwd) + +sudo chmod -R a=rwX,go-rwX "$ROOT"/docker/.ssh/ + +sudo chown -R :www-data $ROOT +sudo chmod -R g+rwX $ROOT diff --git a/scripts/git.storage_push.sh b/scripts/git.storage_push.sh new file mode 100755 index 0000000..a63a00c --- /dev/null +++ b/scripts/git.storage_push.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# +# @package sscripts +# @author sHa +# @copyright 2019 shadoll +# @version 19.6.7 +# @link https://shadoll.dev +# + +DIR=$(dirname $BASH_SOURCE) +PROJECT=$(cd $DIR"/.."; pwd) +cd $PROJECT/storage + +git add . --all && +git commit -m "storage" +git push origin master --force diff --git a/scripts/git.submodule_pull.sh b/scripts/git.submodule_pull.sh new file mode 100755 index 0000000..4297a33 --- /dev/null +++ b/scripts/git.submodule_pull.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# +# @package sscripts +# @author sHa +# @copyright 2019 shadoll +# @version 19.6.7 +# @link https://shadoll.dev +# + +DIR=$(dirname "$0") +ROOT=$(cd "$DIR"/.. && pwd) + +chmod -R a=rwX,go-rwX "$ROOT"/docker/.ssh/ + +git submodule init +ssh-agent sh -c "ssh-add -D; ssh-add $ROOT/docker/.ssh/id_rsa; git submodule update" diff --git a/scripts/hello.js b/scripts/hello.js new file mode 100755 index 0000000..05581b5 --- /dev/null +++ b/scripts/hello.js @@ -0,0 +1,11 @@ +#!/usr/bin/env node + +// @package sscripts +// @author sHa +// @copyright 2019 shadoll +// @version 19.6.7 +// @link https://shadoll.dev + +const [,, ...args] = process.argv + +console.log(`Hello ${args}`) diff --git a/scripts/hello.sh b/scripts/hello.sh new file mode 100755 index 0000000..218e016 --- /dev/null +++ b/scripts/hello.sh @@ -0,0 +1,10 @@ +#!/bin/bash +# +# @package sscripts +# @author sHa +# @copyright 2019 shadoll +# @version 19.6.7 +# @link https://shadoll.dev +# + +echo "Hello! $@" diff --git a/scripts/zuilip.post-merge.sh b/scripts/zuilip.post-merge.sh new file mode 100755 index 0000000..defbad2 --- /dev/null +++ b/scripts/zuilip.post-merge.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# +# @package sscripts +# @author sHa +# @copyright 2019 shadoll +# @version 19.6.7 +# @link https://shadoll.dev +# + +DIR=`dirname "$(readlink -f "$0")"` +DIR=${DIR%/*} +if [ "${DIR##*/}" = ".git" ]; then + DIR=${DIR%/*} +fi + +test -z "$STREAM" && test -f $DIR/.env && STREAM=$(grep -e '^STREAM_NAME=.*' $DIR/.env | cut -d '=' -f2) +test -z "$STREAM" && STREAM="announce" + +test -z "$HASH" && test -f $DIR/.env && HASH=$(grep -e '^ZULIP_HASH=.*' $DIR/.env | cut -d '=' -f2) +test -z "$HASH" && HASH="VUsqHUhn5AKndXSUKddYpTsNJm7kPKNY" + +test -z "$URL" && test -f $DIR/.env && URL=$(grep -e '^ZULIP_HOST=.*' $DIR/.env | cut -d '=' -f2) +test -z "$URL" && URL="VUsqHUhn5AKndXSUKddYpTsNJm7kPKNY" + +HOST=`hostname` +REPO=$(basename -s .git `git config --get remote.origin.url`) +BRANCH=`git branch | grep \* | cut -d ' ' -f2` + +curl https://$URL/api/v1/messages \ + -u githook-bot@$URL:$HASH \ + -d "type=stream" \ + -d "to=$STREAM" \ + -d "subject=$REPO / $BRANCH" \ + -d "content=merged on $HOST" diff --git a/sscripts.code-workspace b/sscripts.code-workspace new file mode 100644 index 0000000..022c3e5 --- /dev/null +++ b/sscripts.code-workspace @@ -0,0 +1,8 @@ +{ + "folders": [ + { + "path": "." + } + ], + "settings": {} +}