Added laravel-init
This commit is contained in:
41
laravel-init
Executable file
41
laravel-init
Executable file
@@ -0,0 +1,41 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Current user.
|
||||
ME=$(whoami)
|
||||
|
||||
# Use PHP composer to check if the project requires Laravel framework and quit if not.
|
||||
if ! composer show | grep -q "laravel/framework"; then
|
||||
echo "This project does not require Laravel framework. Exiting."
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Show the version of Laravel installed.
|
||||
LARAVEL_VERSION=$(composer show --format=json | jq -r '.packages[]? | select(.name == "laravel/framework") | .version')
|
||||
echo "Laravel version: $LARAVEL_VERSION"
|
||||
|
||||
# Create required empty directories and add .gitignore to each of them:
|
||||
DIRECTORIES=(
|
||||
"storage/framework/cache"
|
||||
"storage/framework/sessions"
|
||||
"storage/framework/views/twig"
|
||||
"storage/app"
|
||||
"storage/logs"
|
||||
"storage/reports"
|
||||
"bootstrap/cache"
|
||||
)
|
||||
|
||||
for dir in "${DIRECTORIES[@]}"; do
|
||||
# Create directory if it doesn't exist
|
||||
if [ ! -d "$dir" ]; then
|
||||
mkdir -p "$dir"
|
||||
echo "Created directory: $dir"
|
||||
fi
|
||||
|
||||
# Add .gitignore file with !.gitignore content
|
||||
if [ ! -f "$dir/.gitignore" ]; then
|
||||
echo "!.gitignore" > "$dir/.gitignore"
|
||||
echo "Created .gitignore in: $dir"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "Laravel project directory initialized."
|
||||
62
laravelpermissions
Executable file
62
laravelpermissions
Executable file
@@ -0,0 +1,62 @@
|
||||
#!/bin/bash
|
||||
# Fix the directory and file pemission for Laravel-based projects.
|
||||
# Rev 2019-07-31 By Ali
|
||||
|
||||
ME=$(whoami)
|
||||
|
||||
if [ $1 ] ; then
|
||||
dir="/var/www/webapps/$1"
|
||||
else
|
||||
dir=$(pwd)
|
||||
fi
|
||||
|
||||
if [ -f "$dir/.env" ] ; then
|
||||
echo "Setting pemission for $dir...";
|
||||
|
||||
#sudo chown $ME:$ME ** -R
|
||||
#permissionreset
|
||||
|
||||
# Laravel Env
|
||||
sudo chmod 640 .env
|
||||
|
||||
# Delete cache directories
|
||||
sudo rm -rf $dir/storage/framework/views/twig
|
||||
|
||||
# Create common dirs
|
||||
mkdir -p $dir/storage/framework/cache
|
||||
mkdir -p $dir/storage/framework/sessions
|
||||
mkdir -p $dir/storage/framework/views/twig
|
||||
mkdir -p $dir/storage/app
|
||||
mkdir -p $dir/storage/logs
|
||||
mkdir -p $dir/storage/reports
|
||||
mkdir -p $dir/bootstrap/cache
|
||||
|
||||
# Bring them to GIT repo.
|
||||
echo -e "**\n!.gitignore" > $dir/storage/framework/cache/.gitignore
|
||||
echo -e "**\n!.gitignore" > $dir/storage/framework/sessions/.gitignore
|
||||
echo -e "**\n!.gitignore" > $dir/storage/framework/views/twig.gitignore
|
||||
echo -e "**\n!.gitignore" > $dir/storage/app/.gitignore
|
||||
echo -e "**\n!.gitignore" > $dir/storage/logs/.gitignore
|
||||
echo -e "**\n!.gitignore" > $dir/storage/reports/.gitignore
|
||||
|
||||
# Folder to be read/write by httpd
|
||||
sudo find $dir/config -type d -exec chmod 750 {} \;
|
||||
sudo find $dir/config -type f -exec chmod 640 {} \;
|
||||
sudo find $dir/bootstrap/cache -type d -exec chmod 770 {} \;
|
||||
sudo find $dir/bootstrap/cache -type f -exec chmod 660 {} \;
|
||||
sudo find $dir/storage -type d -exec chmod 770 {} \;
|
||||
sudo find $dir/storage -type f -exec chmod 660 {} \;
|
||||
|
||||
# To be writable by httpd.
|
||||
sudo chgrp www-data -R $dir/bootstrap/cache
|
||||
sudo chgrp www-data -R $dir/config
|
||||
sudo chgrp www-data -R $dir/storage
|
||||
|
||||
# Laravel Env
|
||||
sudo chmod 640 .env
|
||||
sudo chgrp www-data .env
|
||||
|
||||
echo "Done!"
|
||||
else
|
||||
echo "It doesn't looks like a Laravel project!"
|
||||
fi
|
||||
17
pm-task
17
pm-task
@@ -125,9 +125,18 @@ function subShell() {
|
||||
|
||||
# Help messages (keep at bottom). ----------------------------------------------
|
||||
function subHelp() {
|
||||
echo "Usage 1: pm-task [build|up|down|logs|sh|start|stop|resatart] [<argument>...] --help"
|
||||
echo "Usage 2: pm-task <project-name> - Go to the project directory."
|
||||
echo "Usage 3: pm-task (no arguments) - Go to the workspace directory."
|
||||
echo "Usage: pm-task <command> [<argument>...]"
|
||||
echo "Commands:"
|
||||
echo " build, rebuild Build the Docker Compose project."
|
||||
echo " daily, today Stream daily logs for the current project."
|
||||
echo " down, stop Stop and remove containers."
|
||||
echo " logs, log Stream logs for the current project."
|
||||
echo " ps Watch container stats."
|
||||
echo " reload Reload the service in the current project."
|
||||
echo " restart Restart the Docker Compose project."
|
||||
echo " stats Display container resource usage statistics."
|
||||
echo " up, start Start the Docker Compose project."
|
||||
echo " bash|rsh|sh Access a shell in the running container."
|
||||
}
|
||||
|
||||
# Task
|
||||
@@ -187,5 +196,7 @@ if [ $1 ]; then
|
||||
|
||||
# Go to the workspace when no argument is provided.
|
||||
else
|
||||
echo "Usage: pm-task <command> [<argument>...]"
|
||||
echo "Run 'pm-task --help' for more information."
|
||||
subGotoWorkspace
|
||||
fi
|
||||
|
||||
191
pm-task-old
Executable file
191
pm-task-old
Executable file
@@ -0,0 +1,191 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Pod Management Task Script for Docker or Podman.
|
||||
#
|
||||
# Do not run `./pm-task` directly, since the `cd` command will not work in this
|
||||
# way. Instead, run in `source pm-task` pattern. There is already an alias for
|
||||
# this in the `startup.sh` script, after running that script, simply run 'pm' to
|
||||
# use this script.
|
||||
#
|
||||
# To work with Podman, simply make `docker` an aliase to the `podman` command.
|
||||
|
||||
# Image building with docker compose.
|
||||
function subBuild() {
|
||||
|
||||
if [ -f compose.yaml ] || [ -f docker-compose.yml ] || [ -f container-compose.yml ]; then
|
||||
|
||||
ls -lah
|
||||
|
||||
export RANDOM_UUID=`uuid`
|
||||
docker compose build
|
||||
|
||||
read -ei Y -p "Restart container(s)? " confirm
|
||||
if [[ $confirm =~ ^[Yy]$ ]]; then
|
||||
docker compose down && docker compose up -d
|
||||
fi
|
||||
|
||||
# read -e -p "Restart nginx service in container? " confirm
|
||||
# if [[ $confirm =~ ^[Yy]$ ]]; then
|
||||
# docker exec -d nginx service nginx reload
|
||||
# fi
|
||||
|
||||
# Assume nginx is always in place.
|
||||
docker exec -d nginx service nginx reload
|
||||
|
||||
else
|
||||
echo 'Cannot build (niether compose.yaml, docker-compose.yml nor container-compose.yml is found).'
|
||||
fi
|
||||
}
|
||||
|
||||
function subGotoWorkspace() {
|
||||
case $HOSTNAME in
|
||||
Eighty)
|
||||
if [ $1 ]; then
|
||||
cd $HOME/docker/$1
|
||||
else
|
||||
cd $HOME/docker
|
||||
fi
|
||||
;;
|
||||
HiveDC)
|
||||
if [ $1 ]; then
|
||||
cd /mnt/workspace/docker/$1
|
||||
else
|
||||
cd /mnt/workspace/docker
|
||||
fi
|
||||
;;
|
||||
HivePM)
|
||||
if [ $1 ]; then
|
||||
cd /mnt/workspace/podman/$1
|
||||
else
|
||||
cd /mnt/workspace/podman
|
||||
fi
|
||||
;;
|
||||
libpodman)
|
||||
if [ $1 ]; then
|
||||
cd /podman/$1
|
||||
else
|
||||
cd /podman
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo Unrecognized host: $HOSTNAME
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Application logs streaming (single log).
|
||||
function subLogs() {
|
||||
docker logs -f $POD
|
||||
# # $1 is $2 of the script.
|
||||
# if [ $1 ]; then
|
||||
# # ELABORATE
|
||||
# docker exec -it $1 tail -s 5 -f /var/www/app/storage/logs/laravel.log
|
||||
# else
|
||||
# docker exec -it $POD tail -s 5 -f /var/www/app/storage/logs/laravel.log
|
||||
# fi
|
||||
}
|
||||
|
||||
# Application logs streaming (daily log).
|
||||
function subLogsDaily() {
|
||||
# $1 is $2 of the script.
|
||||
if [ $1 ]; then
|
||||
# ELABORATE
|
||||
docker exec -it $1 tail -s 5 -f /var/www/app/storage/logs/laravel-$TODAY.log
|
||||
else
|
||||
docker exec -it $POD tail -s 5 -f /var/www/app/storage/logs/laravel-$TODAY.log
|
||||
fi
|
||||
}
|
||||
|
||||
# Reload service in container (hard-coded, limited usage).
|
||||
function subReload() {
|
||||
case $POD in
|
||||
nginx)
|
||||
docker exec -it $POD service nginx reload
|
||||
;;
|
||||
*)
|
||||
# docker exec -it $POD service apache2 reload # No longer using Apache.
|
||||
docker exec -it $POD service nginx reload
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function subRestart() {
|
||||
docker compose down && docker compose up -d
|
||||
}
|
||||
|
||||
# Container shell access.
|
||||
function subShell() {
|
||||
# $1 is $2 of the script.
|
||||
if [ $1 ]; then
|
||||
docker exec -it $1 bash
|
||||
else
|
||||
docker exec -it $POD bash
|
||||
fi
|
||||
}
|
||||
|
||||
# Help messages (keep at bottom). ----------------------------------------------
|
||||
function subHelp() {
|
||||
echo "Usage 1: pm-task [build|up|down|logs|sh|start|stop|resatart] [<argument>...] --help"
|
||||
echo "Usage 2: pm-task <project-name> - Go to the project directory."
|
||||
echo "Usage 3: pm-task (no arguments) - Go to the workspace directory."
|
||||
}
|
||||
|
||||
# Task
|
||||
if [ $1 ]; then
|
||||
|
||||
# Assume the host is running podman when alias docket='podman' exists.
|
||||
if [ $(type -t docker) == "alias" ]; then
|
||||
COMMAND='podman'
|
||||
fi
|
||||
|
||||
# Assumed container is named after the directory name.
|
||||
TASK=$1
|
||||
TODAY=$(date +%Y-%m-%d)
|
||||
POD=${PWD##*/}
|
||||
|
||||
case $TASK in
|
||||
bash|rsh|sh)
|
||||
subShell $2
|
||||
;;
|
||||
build|rebuild)
|
||||
subBuild
|
||||
;;
|
||||
daily|today)
|
||||
subLogsDaily $2
|
||||
;;
|
||||
down|stop)
|
||||
docker compose down
|
||||
;;
|
||||
logs|log)
|
||||
subLogs $2
|
||||
;;
|
||||
ps)
|
||||
# Because `watch` has no idea of the alias.
|
||||
eval "watch -n 10 $COMMAND ps"
|
||||
;;
|
||||
reload)
|
||||
subReload
|
||||
;;
|
||||
restart)
|
||||
if [ $2 ]; then
|
||||
subGotoWorkspace $2
|
||||
fi
|
||||
subRestart $2
|
||||
;;
|
||||
stats)
|
||||
docker stats
|
||||
;;
|
||||
up|start)
|
||||
docker compose up -d
|
||||
;;
|
||||
--help)
|
||||
subHelp
|
||||
;;
|
||||
*)
|
||||
subGotoWorkspace $TASK
|
||||
esac
|
||||
|
||||
# Go to the workspace when no argument is provided.
|
||||
else
|
||||
subGotoWorkspace
|
||||
fi
|
||||
Reference in New Issue
Block a user