Browse Source

refactoring

master
Sven Ullmann 2 years ago
parent
commit
c53b3866e5
  1. 4
      .gitignore
  2. 44
      bin/commands/install-plugin
  3. 59
      bin/commands/remove-project
  4. 165
      bin/includes/config
  5. 195
      bin/includes/main_functions
  6. 110
      bin/includes/project_manager
  7. 0
      bin/postscripts/plugins/.keep
  8. 41
      bin/project-manager
  9. 0
      plugins/db/src/commands/backup
  10. 0
      plugins/db/src/commands/create-config
  11. 0
      plugins/db/src/includes/includes
  12. 0
      plugins/git/src/commands/clone
  13. 0
      plugins/git/src/includes/includes
  14. 0
      plugins/shopware6/bin/includes/includes
  15. 2
      plugins/shopware6/notice.txt
  16. 0
      src/bak/commands/import_media.sh
  17. 0
      src/bak/commands/install_remote_system.sh
  18. 0
      src/bak/commands/install_shopware.sh
  19. 0
      src/bak/commands/make_local_database.sh
  20. 0
      src/bak/commands/switch_local_env.sh
  21. 0
      src/bak/functions/backup_db.sh
  22. 0
      src/bak/functions/clone_repo.sh
  23. 0
      src/bak/functions/create_database.sh
  24. 0
      src/bak/functions/create_directories.sh
  25. 0
      src/bak/functions/deploy.sh
  26. 0
      src/bak/functions/fetch_files.sh
  27. 0
      src/bak/functions/import_db.sh
  28. 0
      src/bak/functions/link_latest_db.sh
  29. 0
      src/bak/functions/write_shopware_env_file.sh
  30. 33
      src/commands/create-project
  31. 51
      src/commands/install-plugin
  32. 30
      src/commands/install-project-manager
  33. 16
      src/commands/list-projects
  34. 87
      src/commands/remove-project
  35. 9
      src/includes/bash_header
  36. 36
      src/includes/config
  37. 166
      src/includes/config.php
  38. 0
      src/includes/includes
  39. 222
      src/includes/main_functions
  40. 28
      src/includes/project_manager
  41. 0
      src/postscripts/plugins/.keep

4
.gitignore

@ -1,7 +1,7 @@
/.idea
/.trash
/bin/postscripts/commands/*
/bin/postscripts/plugins/*
/src/postscripts/commands/*
/src/postscripts/plugins/*
/data/*
/etc/*

44
bin/commands/install-plugin

@ -1,44 +0,0 @@
#!/bin/bash
### DO NOT EDIT THIS FILE
source "$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." &> /dev/null && pwd)/includes/bash_header"
function usage {
echo
echoMainTitle "Installs a plugin"
echo
echoSubTitle "Usage:"
echo
echo "install-plugin [shortname] [plugin]"
echo
echo "--help Prints this message"
echo " "
}
shortname=$(getArgument "$1" "$(usage)" true)
plugin=$(getArgument "$2" "$(usage)" true)
customer=$(getCustomerFromShortname "$shortname")
project=$(getProjectFromShortname "$shortname")
project_dir="$project_manager_dir/data/$customer/$project"
plugin_dir="$project_manager_dir/plugins/$plugin"
echo
echoMainTitle "Install plugin"
if [ ! -d "$project_dir/etc/plugins/$plugin" ]
then
mkdir "$project_dir/etc/plugins/$plugin"
fi
etc_files=$(list "$plugin/etc")
for etc_file in "${etc_files[@]}"
do
cp "$etc_file" "$project_dir/etc/plugins/$plugin/."
done
runPostscripts "$shortname" "commands/install-plugin"
echo
echoSuccess "Plugin has been installed, please configure: $project_dir/etc/plugins/$plugin"
echo

59
bin/commands/remove-project

@ -1,59 +0,0 @@
#!/bin/bash
### DO NOT EDIT THIS FILE
source "$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." &> /dev/null && pwd)/includes/bash_header"
function usage {
echo
echoMainTitle "Removes a project"
echo
echoSubTitle "Usage:"
echo
echo "remove-project [shortname]"
echo
echo "This will remove the project and move the project files to ./.trash"
echo
echo "--help Prints this message"
echo
}
shortname="$(getArgument "$1" "$(usage)" true)"
customer="$(getCustomerFromShortname "$shortname")"
project="$(getProjectFromShortname "$shortname")"
pos="$(getProjectConfigPosition "$shortname")"
workspace_dir="$project_manager_workspaces_dir/$customer/$project"
project_dir="$project_manager_dir/data/$customer/$project"
echo
echoMainTitle "Remove project"
echo
echoSubTitle "Please verify data"
echo
echo "Project Path: $workspace_dir"
echo "Project Data Path: $project_dir"
echo
confirm
echo
echo "Moving files to trash"
rand=$(cat /proc/sys/kernel/random/uuid)
trash_path="$project_manager_dir/.trash/$rand"
mkdir "$trash_path"
mkdir "$trash_path/data"
mkdir "$trash_path/workspace"
mkdir "$trash_path/data/$customer"
mkdir "$trash_path/workspace/$customer"
mv "$project_dir" "$trash_path/data/$customer/$project"
mv "$workspace_dir" "$trash_path/workspace/$customer/$project"
removeProjectConfig "$shortname"
runPostscripts "$shortname" "commands/remove-project"
postScript "$trash_path/data/bin/postscripts/commands/remove-project"
echo
echoSuccess "Project has been removed"
echo

165
bin/includes/config

@ -1,165 +0,0 @@
#!/usr/bin/php
<?php
### DO NOT EDIT THIS FILE
function usage() {
echo "\n";
echo "Get and Set configuration parameters\n";
echo "\n";
echo "Usage:\n";
echo "\n";
echo "config get [configPath]\n";
echo "config set [configPath] [value]\n";
echo "config remove [configPath]\n";
echo "\n";
echo "configPath: The config path is in the format 'project_manager.workspaces_dir'\n";
echo "\n";
echo "--help Prints this message\n";
echo "\n";
exit;
}
if ($_SERVER['argc'] < 3 || $_SERVER['argv'] == '--help') {
usage();
}
global $project_manager_dir, $shortname, $configuration;
$configuration = [];
$project_manager_dir = dirname(dirname(__DIR__));
$command = $_SERVER['argv'][1];
$configPath = $_SERVER['argv'][2];
$value = $_SERVER['argv'][3] ?? null;
$shortname = substr($configPath, 0, strpos($configPath, '.'));
$configPath = substr($configPath, strpos($configPath, '.')+1);
if (function_exists($command)) {
loadProjectManagerConfig($project_manager_dir);
if ($shortname !== 'project_manager') {
loadProjectConfig();
}
$command();
}
function mergeConfig($file)
{
global $configuration;
$configuration = array_replace_recursive(
$configuration,
json_decode(file_get_contents($file), true)
);
}
function loadProjectManagerConfig()
{
global $configuration, $project_manager_dir;
$config_file = $project_manager_dir . '/etc/config.json';
mergeConfig($config_file);
}
function loadProjectConfig()
{
global $configuration, $project_manager_dir;
$customer = getCustomerFromShortname();
$project = getProjectFromShortname();
$config_file = "$project_manager_dir/data/$customer/$project/etc/config.json";
mergeConfig($config_file);
$plugin_dir = dirname($config_file) . '/plugins';
$dh = opendir($plugin_dir);
if ($dh) {
while (false !== ($file = readdir($dh))) {
if ('.' === $file || '..' === $file || !is_dir($plugin_dir/$file)) {
continue;
}
$config_file = "$plugin_dir/$file/etc/config.json";
mergeConfig($config_file);
}
}
}
function getCustomerFromShortname()
{
global $configuration, $shortname;
return $configuration['project_manager']['projects'][$shortname]['customer'] ?? null;
}
function getProjectFromShortname()
{
global $configuration, $shortname;
return $configuration['project_manager']['projects'][$shortname]['project'] ?? null;
}
function parsePath()
{
global $configPath;
$parsedPath = '';
foreach (explode('.', $configPath) as $part) {
$parsedPath .= "['$part']";
}
return $parsedPath;
}
function is()
{
global $configuration, $shortname;
return eval("return isset(\$configuration['$shortname']".parsePath().");");
}
function get()
{
global $configuration, $shortname;
if (!is()) {
exit(1);
}
$return = eval("return \$configuration['$shortname']".parsePath().";");
if (is_array($return)) {
$echo = '';
foreach (array_keys($return) as $value) {
$echo .= '"'.$value.'" ';
}
$echo = trim($echo, ' ');
echo $echo;
exit;
}
echo $return;
}
function set()
{
global $configuration, $shortname, $value;
if (!is()) {
exit(1);
}
eval("\$configuration['$shortname']".parsePath()." = '$value';");
writeConfig();
}
function remove()
{
global $configuration, $shortname;
if (!is()) {
exit(1);
}
eval("unset \$configuration['$shortname']".parsePath().";");
writeConfig();
}
function writeConfig()
{
global $configuration, $shortname, $project_manager_dir;
$customer = getCustomerFromShortname();
$project = getProjectFromShortname();
foreach($configuration as $shortname => $data) {
if ('project_manager' === $shortname) {
$config_file = "$project_manager_dir/etc/config.json";
} elseif ('project' === $shortname) {
$config_file = "$project_manager_dir/data/$customer/$project/etc/config";
} else {
$config_file = "$project_manager_dir/data/$customer/$project/etc/plugins/$shortname/config";
}
file_put_contents($config_file, json_encode([$shortname => $data], JSON_PRETTY_PRINT));
}
}

195
bin/includes/main_functions

@ -1,195 +0,0 @@
#!/bin/bash
### DO NOT EDIT THIS FILE
if [ true != ${includes_main_functions:-false} ]
then
includes_main_functions=true
function echoMainTitle {
echo -e "\033[38;5;214m$1\033[0m"
}
function echoSubTitle {
echo -e "\033[38;5;142m$1\033[0m"
}
function echoSmall {
echo -e "\033[38;5;240m$1\033[0m"
}
function echoSelect {
local select="$1"
local message="$2"
echo -e "\033[0;33m$select\033[0m $message"
}
function echoError {
echo -e "\033[0;91m$1\033[0m"
}
function echoWarning {
echo -e "\033[0;33m$1\033[0m"
}
function echoSuccess {
echo -e "\033[0;32m$1\033[0m"
}
function getParameter {
local name=$1
local has=$2
local parameters=($3)
for i in "${!parameters[@]}"
do
if [ "${parameters[$i]}" == "$name" ] && [ "$has" == true ]
then
((j=i+1))
echo "${parameters[$j]}"
elif [ "${parameters[$i]}" == "$name" ]
then
echo true
fi
done
}
function getArgument {
local var=$1
local errmsg=${2:-"Invalid Argument"}
local allow=${3:-true}
if [ "$allow" != false ] && [ "$(isAllowed "$var" "$allow")" == false ]
then
echo "$errmsg" >&2
exit 1
fi
echo "$var"
}
function isAllowed {
local var="$1"
local allow="$2"
local valid=true
if [ "$allow" == true ] && [ "$var" == "" ]
then
valid=false
elif [ "$allow" != false ] && [ "$allow" != true ]
then
allow=($allow)
local found=false
for i in "${!allow[@]}"
do
if [ "${allow[$i]}" == "$var" ]
then
found=true
fi
done
if [ "$found" != true ]
then
valid=false
fi
fi
echo $valid
}
function readConsole {
local message="$1"
local errmsg="$2"
local allow=${3:-false}
local default="$4"
if [ "$default" != "" ]
then
read -p "$message [default:$default]: " var
else
read -p "$message: " var
fi
if [ "$var" == "" ] && [ "$default" != "" ]
then
var="$default"
fi
if [ "$(isAllowed "$var" "$allow")" == false ]
then
echo "$errmsg" >&2
var=$(readConsole "$message" "$errmsg" "$allow" "$default")
fi
echo "$var"
}
function postScript {
local script=$(getArgument "$1" "Usage: postScript \"post_script.sh\"" true)
if [ -f "$script" ]
then
source "$script"
fi
}
function getConfig {
local env=$(getArgument "$1" "Usage getEnvVar [live|stage|local_live|local_stage] var" "live stage local_live local_stage")
local suffix=$(getArgument "$2" "Usage getEnvVar [live|stage|local_live|local_stage] var" true)
echo "$(eval "echo \"\$${env}_$suffix\"")"
}
function sedEscape {
echo "$1" | sed -r 's/([\$\.\*\/\[\\^])/\\\1/g' | sed 's/[]]/\[]]/g'
}
function confirm {
confirm="$(readConsole "Should i execute? [y,n]" "Invalid selection" "y n")"
if [ "$confirm" == "n" ]
then
echo
echoError "Aborting"
echo
exit
fi
}
function getSudoPassword {
if [ "${project_manager_sudo_password}" == "" ]
then
echo -n "Sudo Password:"
read -s project_manager_sudo_password
fi
echo project_manager_sudo_password
}
function runPostscripts {
local shortname="$(getArgument "$1")"
local script="$(getArgument "$2")"
local project="$(getProjectFromShortName "$shortname")"
local customer="$(getCustomerFromShortName "$shortname")"
local project_dir="$project_manager_dir/data/$customer/$project"
postScript "$project_manager_dir/bin/postscripts/$script"
postScript "$project_dir/bin/postscripts/$script"
}
function getConfig {
local configPath="$(getArgument "$1")"
local configScript="$project_manager_dir/bin/includes/config"
echo "$(source '$configScript' get "$configPath")"
}
function setConfig {
local configPath="$(getArgument "$1")"
local value="$(getArgument "$2")"
local configScript="$project_manager_dir/bin/includes/config"
source '$configScript' set "$configPath" "$value"
}
function removeConfig {
local configPath="$(getArgument "$1")"
local configScript="$project_manager_dir/bin/includes/config"
echo "$(source '$configScript' remove "$configPath")"
}
fi

110
bin/includes/project_manager

@ -1,110 +0,0 @@
#!/bin/bash
### DO NOT EDIT THIS FILE
if [ true != ${includes_project_manager:-false} ]
then
includes_project_manager=true
function getProjectFromShortname {
local shortname="$(getArgument "$1")"
for i in "${!project_manager_shortnames[@]}"
do
if [ "${project_manager_shortnames[$i]}" == "$shortname" ]
then
echo "${project_manager_projects[$i]}"
fi
done
}
function getCustomerFromShortname {
local shortname="$(getArgument "$1")"
for i in "${!project_manager_shortnames[@]}"
do
if [ "${project_manager_shortnames[$i]}" == "$shortname" ]
then
echo "${project_manager_customers[$i]}"
fi
done
}
function loadProjectConfig
{
local shortname="$(getArgument "$1")"
local customer="$(getCustomerFromShortname "$shortname")"
local project="$(getProjectFromShortname "$shortname")"
if [ "$customer" == "" ] || [ "$project" == "" ]
then
echo
echoError "Could not load project with name: $shortname"
echo
exit
fi
local path="$project_manager_dir/data/$customer/$project"
source "$path/etc/config"
}
function loadPluginConfig
{
local shortname="$(getArgument "$1")"
local customer="$(getCustomerFromShortname "$shortname")"
local project="$(getProjectFromShortname "$shortname")"
if [ "$customer" == "" ] || [ "$project" == "" ]
then
echo
echoError "Could not load project with name: $shortname"
echo
exit
fi
local path="$project_manager_dir/data/$customer/$project"
local plugin_path="$project_manager_dir/plugins"
local plugins="$(ls -t "$plugin_path")"
for plugin in ${plugins[*]}
do
if [ -f "$path/etc/plugins/$plugin/config" ]
then
source "$path/etc/plugins/$plugin/config"
fi
done
}
function makeProjectManagerDirectories {
local shortname="$(getArgument "$1")"
local customer="$(getArgument "$2")"
local project="$(getArgument "$3")"
path="$project_manager_dir/data/$customer/$project"
if [ ! -d "$path" ]; then mkdir -p "$path"; fi
if [ ! -d "$path/.ssh" ]; then mkdir "$path/.ssh"; fi
if [ ! -d "$path/backup" ]; then mkdir "$path/backup"; fi
if [ ! -d "$path/backup/database" ]; then mkdir "$path/backup/database"; fi
if [ ! -d "$path/bin" ]; then mkdir "$path/bin"; fi
if [ ! -d "$path/bin/postscripts" ]; then mkdir "$path/bin/postscripts"; fi
if [ ! -d "$path/bin/postscripts/plugins" ]; then mkdir "$path/bin/postscripts/plugins"; fi
if [ ! -d "$path/bin/includes" ]; then mkdir "$path/bin/includes"; fi
if [ ! -d "$path/bin/includes/plugins" ]; then mkdir "$path/bin/includes/plugins"; fi
if [ ! -d "$path/etc" ]; then mkdir "$path/etc"; fi
if [ ! -d "$path/etc/plugins" ]; then mkdir "$path/etc/plugins"; fi
if [ ! -d "$path/shared" ]; then mkdir "$path/shared"; fi
if [ ! -d "$path/shared/live" ]; then mkdir "$path/shared/live"; fi
if [ ! -d "$path/shared/stage" ]; then mkdir "$path/shared/stage"; fi
if [ ! -d "$path/var" ]; then mkdir "$path/var"; fi
if [ ! -d "$path/var/tmp" ]; then mkdir "$path/var/tmp"; fi
if [ ! -d "$path/var/latest" ]; then mkdir "$path/var/latest"; fi
}
function makeWorkspaceDirectories {
local shortname="$(getArgument "$1")"
local customer="$(getArgument "$2")"
local project="$(getArgument "$3")"
if [ ! -d "$project_manager_workspaces_dir/$customer/$project" ]; then mkdir -p "$project_manager_workspaces_dir/$customer/$project"; fi
}
fi

0
bin/postscripts/plugins/.keep

41
bin/project-manager

@ -1,5 +1,11 @@
#!/bin/bash
set -e
export TOP_PID=$$
function exit_program
{
kill -9 $TOP_PID &> /dev/null
}
### DO NOT EDIT THIS FILE
@ -13,16 +19,19 @@ function usage {
echo "project-manager [command] [command-args]"
echo "project-manager [plugin:command] [command-args]"
echo
echo "--skip-confirm with 'y' or 'n' - stops asking for action"
echo "--help Prints this message"
echo "--help [command] Prints the help message for a command"
echo "--help [plugin:command] Prints the help message for a command"
echo "[command] --help Prints the help message for a command"
echo "[plugin:command] --help Prints the help message for a plugin command"
echo "--list-commands List all commands"
echo "--list-commands [plugin] List all plugin commands"
echo "--list-plugins List all plugins"
echo
}
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)/includes/bash_header"
source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd)/src/includes/includes"
project_manager_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd)"
function list {
local dir=$1
@ -43,8 +52,8 @@ function list {
}
help="$(getParameter "--help" false "$*")"
list_commands="$(getParameter "--list-commands" false "$*")"
list_plugins="$(getParameter "--list-plugins" false "$*")"
list_commands="$(getParameter "--list-commands" "$*")"
list_plugins="$(getParameter "--list-plugins" "$*")"
if [[ "$1" == *"--"* ]]; then key=2; else key=1; fi
param="$(eval "echo \"\$${key}\"")"
@ -57,7 +66,7 @@ else
plugin=""
fi
if [ ! -f "$project_manager_dir/etc/config" ] || [ ! -f "$project_manager_dir/etc/projects" ]
if [ ! -f "$project_manager_dir/etc/config.json" ]
then
command="install-project-manager"
plugin=""
@ -65,13 +74,13 @@ fi
if [ "$1" == "" ] && [ "$command" == "" ]
then
use
usage
exit
fi
if [ "$help" == true ] && [ "$command" == "" ]
then
use
usage
exit
fi
@ -80,11 +89,11 @@ then
if [ "$command" == "" ] && [ "$list_commands" == false ] && [ "$list_plugins" == false ]
then
use
usage
exit
elif [ "$command" != "" ] && [ "$plugin" != "" ] && [ "$help" == true ]
then
file="$project_manager_dir/plugins/$plugin/commands/$command"
file="$project_manager_dir/plugins/$plugin/src/commands/$command"
if [ ! -f "$file" ]
then
echo
@ -97,7 +106,7 @@ then
fi
elif [ "$command" != "" ] && [ "$help" == true ]
then
file="$project_manager_dir/bin/commands/$command"
file="$project_manager_dir/src/commands/$command"
if [ ! -f "$file" ]
then
echo
@ -110,10 +119,10 @@ then
fi
elif [ "$command" != "" ] && [ "$list_commands" == true ]
then
list "plugins/$command/commands"
list "plugins/$command/src/commands"
elif [ "$list_commands" == true ]
then
list "bin/commands"
list "src/commands"
elif [ "$list_plugins" == true ]
then
list "plugins"
@ -123,9 +132,9 @@ else
if [ "$plugin" != "" ]
then
file="$project_manager_dir/plugins/$plugin/commands/$command"
file="$project_manager_dir/plugins/$plugin/src/commands/$command"
else
file="$project_manager_dir/bin/commands/$command"
file="$project_manager_dir/src/commands/$command"
fi
if [ ! -f "$file" ]
@ -143,5 +152,5 @@ else
fi
fi
postScript "$project_manager_dir/bin/postscripts/project-manager"
postScript "$project_manager_dir/src/postscripts/project-manager"
fi

0
plugins/db/commands/backup → plugins/db/src/commands/backup

0
plugins/db/commands/create-config → plugins/db/src/commands/create-config

0
plugins/db/includes/includes → plugins/db/src/includes/includes

0
plugins/git/commands/clone → plugins/git/src/commands/clone

0
plugins/git/includes/includes → plugins/git/src/includes/includes

0
plugins/shopware6/includes/includes → plugins/shopware6/bin/includes/includes

2
plugins/shopware6/notice.txt

@ -0,0 +1,2 @@
composer create-project shopware/production <project-name>
bin/console system:install --basic-setup

0
bin/bak/commands/import_media.sh → src/bak/commands/import_media.sh

0
bin/bak/commands/install_remote_system.sh → src/bak/commands/install_remote_system.sh

0
bin/bak/commands/install_shopware.sh → src/bak/commands/install_shopware.sh

0
bin/bak/commands/make_local_database.sh → src/bak/commands/make_local_database.sh

0
bin/bak/commands/switch_local_env.sh → src/bak/commands/switch_local_env.sh

0
bin/bak/functions/backup_db.sh → src/bak/functions/backup_db.sh

0
bin/bak/functions/clone_repo.sh → src/bak/functions/clone_repo.sh

0
bin/bak/functions/create_database.sh → src/bak/functions/create_database.sh

0
bin/bak/functions/create_directories.sh → src/bak/functions/create_directories.sh

0
bin/bak/functions/deploy.sh → src/bak/functions/deploy.sh

0
bin/bak/functions/fetch_files.sh → src/bak/functions/fetch_files.sh

0
bin/bak/functions/import_db.sh → src/bak/functions/import_db.sh

0
bin/bak/functions/link_latest_db.sh → src/bak/functions/link_latest_db.sh

0
bin/bak/functions/write_shopware_env_file.sh → src/bak/functions/write_shopware_env_file.sh

33
bin/commands/create-project → src/commands/create-project

@ -2,8 +2,6 @@
### DO NOT EDIT THIS FILE
source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd)/includes/bash_header"
function usage {
echo
echoMainTitle "Creates a new project"
@ -23,22 +21,24 @@ function usage {
echo " "
}
customer="$(getArgument "$1" "$(usage)")"
project="$(getArgument "$2" "$(usage)")"
shortname="$(getArgument "$3" "$(usage)")"
has_project="$(hasProject "$project")"
has_shortname="$(hasShortname "$shortname")"
source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd)/includes/bash_header"
customer="$(getArgument "$1" "$(usageError "Invalid customer")" true)"
project="$(getArgument "$2" "$(usageError "Invalid project")" true)"
shortname="$(getArgument "$3" "$(usageError "Invalid shortname")" true)"
has_shortname="$(hasConfig false "project_manager.projects.$shortname")"
if [ "$has_project" == true ]
if [ "$has_shortname" == true ]
then
echoError "Project already exists"
echoError "Shortname already exists"
echo
exit
fi
if [ "$has_shortname" == true ]
has_project="$(hasConfig false "project_manager.projects.$shortname.project")"
if [ "$has_project" == true ]
then
echoError "Shortname already exists"
echoError "Project already exists"
echo
exit
fi
@ -54,16 +54,15 @@ echoSubTitle "Please verify data"
echo
echo "Project path: $workspace_dir"
echo "Project data path: $project_dir"
echo "Shortname: $shortname"
echo
confirm
makeProjectManagerDirectories "$shortname"
makeWorkspaceDirectories "$shortname"
configSet "project_manager.projects.$shortname.customer" "$customer"
configSet "project_manager.projects.$shortname.project" "$project"
setConfig false "project_manager.projects.$shortname.customer" "$customer"
setConfig false "project_manager.projects.$shortname.project" "$project"
runPostscripts "$shortname" "commands/create-project"
runPostscripts "create-project" "$shortname"
echo
echoSuccess "Project has been created, please configure $project_dir/etc"
echoSuccess "Project has been created."
echo

51
src/commands/install-plugin

@ -0,0 +1,51 @@
#!/bin/bash
### DO NOT EDIT THIS FILE
function usage {
echo
echoMainTitle "Installs a plugin"
echo
echoSubTitle "Usage:"
echo
echo "install-plugin [shortname] [plugin]"
echo
echo "--help Prints this message"
echo " "
}
source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd)/includes/bash_header"
shortname=$(getArgument "$1" "$(usage)" true)
plugin=$(getArgument "$2" "$(usage)" true)
customer=$(getConfig false "project_manager.projects.$shortname.customer")
project=$(getConfig false "project_manager.projects.$shortname.project")
project_dir="$project_manager_dir/data/$customer/$project"
plugin_dir="$project_manager_dir/plugins/$plugin"
source="$project_manager_dir/plugins/$plugin/etc/config.json"
target="$project_dir/etc/$plugin/config.json"
etc_path="$(dirname "$target")"
if [ -f "$target" ]
then
echo
echoError "Plugin is already installed"
echo
exit
fi
echo
echoMainTitle "Install plugin"
if [ ! -d "$etc_path" ]
then
mkdir -p "$etc_path"
fi
cp "$source" "$target"
runPostscripts "install-plugin" "$shortname"
echo
echoSuccess "Plugin has been installed."
echo

30
bin/commands/install-project-manager → src/commands/install-project-manager

@ -2,8 +2,6 @@
### DO NOT EDIT THIS FILE
source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd)/includes/bash_header"
function usage {
echo
echoMainTitle "Install Sumedia Project Manager"
@ -16,12 +14,7 @@ function usage {
echo
}
help="$(getParameter "--help" false "$@")"
if [ "$help" == true ]
then
usage
exit
fi
source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd)/includes/bash_header"
echo
echoMainTitle "Install Sumedia Project Manager"
@ -31,12 +24,25 @@ echoSubTitle "Please configure Sumedia Project Manager"
echo
workspaces_dir="$(readConsole "Workspaces dir" "Invalid selection" true "$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." &> /dev/null && pwd)")"
apache_httpdocs="$(readConsole "Local Apache httpdocs dir (optional)" "Invalid selection" true)"
apache_httpdocs="$(readConsole "Local Apache httpdocs dir (optional)")"
config_source="$project_manager/etc/template/project_manager.json"
config_target="$project_manager/etc/config.json"
if [ ! -d "$(dirname "$config_target")" ]
then
mkdir -p "$(dirname $config_target)"
fi
if [ ! -f "$config_target" ]
then
cp "$source" "$target"
fi
setConfig "project_manager.workspaces_dir" "$workspaces_dir"
setConfig "project_manager.apache_httpdocs" "$apache_httpdocs"
setConfig false "project_manager.workspaces_dir" "$workspaces_dir"
setConfig false "project_manager.apache_httpdocs" "$apache_httpdocs"
postScript "$project_manager_dir/bin/postscripts/commands/install-project-manager"
runPostscripts "install-project-manager"
echo
echoSuccess "Project Manager has been installed."

16
bin/commands/list-projects → src/commands/list-projects

@ -2,7 +2,7 @@
### DO NOT EDIT THIS FILE
source "$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." &> /dev/null && pwd)/includes/bash_header"
source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd)/includes/bash_header"
function usage {
echo
@ -16,15 +16,19 @@ function usage {
echo
}
projects="$(getConfig "project_manager_dir.projects")"
function listProjects {
echo >&2
echoSubTitle "Projects list" >&2
echo >&2
for i in "${!projects[@]}"
for shortname in "${projects[@]}"
do
echo "- Shortname: ${shortnames[$i]}
Customer: ${customers[$i]}
Project: ${projects[$i]}" >&2
customer="$(getConfig "project_manager_dir.projects.$shortname.customer")"
project="$(getConfig "project_manager_dir.projects.$shortname.project")"
echo "- Shortname: $shortname
Customer: $customer
Project: $project" >&2
echo
done
}
@ -41,4 +45,4 @@ else
listProjects
fi
postScript "$project_manager_dir/bin/postscripts/commands/list-projects"
runPostscripts "list-projects"

87
src/commands/remove-project

@ -0,0 +1,87 @@
#!/bin/bash
### DO NOT EDIT THIS FILE
function usage {
echo
echoMainTitle "Removes a project"
echo
echoSubTitle "Usage:"
echo
echo "remove-project [shortname]"
echo
echo "This will remove the project and move the project files to ./.trash"
echo
echo "--help Prints this message"
echo
}
source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd)/includes/bash_header"
shortname="$(getArgument "$1" "$(usageError "shortname required")" true)"
if [ "$(hasConfig false "project_manager.projects.$shortname")" == false ]
then
echo
echoError "There is no project with shortname: $shortname"
echo
exit
fi
customer="$(getConfig false "project_manager.projects.$shortname.customer")"
project="$(getConfig false "project_manager.projects.$shortname.project")"
workspaces_dir="$(getConfig false "project_manager.workspaces_dir")"
workspace_dir="$workspaces_dir/$customer/$project"
project_dir="$project_manager_dir/data/$customer/$project"
echo
echoMainTitle "Remove project"
echo
echoSubTitle "Please verify data"
echo
echo "Project Path: $workspace_dir"
echo "Project Data Path: $project_dir"
echo
confirm
echo
echo "Moving files to trash"
rand="$shortname-$(cat /proc/sys/kernel/random/uuid)"
trash_path="$project_manager_dir/.trash/$rand"
project_source="$project_manager_dir/data/$customer/$project"
project_target="$trash_path/data/$customer/$project"
workspace_source="$workspaces_dir/$customer/$project"
workspace_target="$trash_path/workspace/$customer/$project"
if [ -d "$project_source" ]
then
mkdir -p "$project_target"
mv "$project_source" "$project_target"
fi
if [ -d "$workspace_source" ]
then
mkdir -p "$workspace_target"
mv "$workspace_source" "$workspace_target"
fi
if [ -d "$(dirname "$project_source")" ]
then
if [ "$(ls -A "$(dirname "$project_source")")" == "" ]; then rmdir "$(dirname "$project_source")"; fi
fi
if [ -d "$(dirname "$workspace_source")" ]
then
if [ "$(ls -A "$(dirname "$workspace_source")")" == "" ]; then rmdir "$(dirname "$workspace_source")"; fi
fi
removeConfig false "project_manager.projects.$shortname"
runPostscripts "$shortname" "commands/remove-project"
postScript "$trash_path/data/bin/postscripts/commands/remove-project"
echo
echoSuccess "Project has been removed"
echo

9
bin/includes/bash_header → src/includes/bash_header

@ -3,15 +3,12 @@
### DO NOT EDIT THIS FILE
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)/includes"
project_manager_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." &> /dev/null && pwd)"
skip_confirm="$(getParameter "--skip-confirm" "$*")"
help="$(getParameter "--help" false "$*")"
if [ "$help" == true ] || [ "$1" == "" ]
then
if [ "$2" == false ]
help="$(getParameter "--help" "$*")"
if [ "$help" == true ]
then
usage
exit
fi
fi

36
src/includes/config

@ -0,0 +1,36 @@
#!/bin/bash
### DO NOT EDIT THIS FILE
function usage {
echo
echoMainTitle "Sumedia Project Manager Configuration Layer"
echo
echoSubTitle "Usage:"
echo
echo "config has [shortname] [configPath]"
echo "config get [shortname] [configPath]"
echo "config set [shortname] [configPath] [value]"
echo "config remove [shortname] [configPath]"
echo
echo "[configPath] The config path is in the format 'project_manager.workspaces_dir'"
echo "[shortname] can be false"
echo
echo "--help Prints this message"
echo " "
exit
}
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)/bash_header"
command="$(getArgument "$1" "Invalid command given" "get set has remove")"
shortname="$(getArgument "$2" "Parameter shortname not given" true)"
configPath="$(getArgument "$3")"
if [ "$command" == "set" ]
then
value="$(getArgument "$4" "Parameter value not given" true)"
fi
PHP=`which php`
script="$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)/config.php"
$PHP "$script" "$@"

166
src/includes/config.php

@ -0,0 +1,166 @@
<?php
### DO NOT EDIT THIS FILE
global $project_manager_dir, $shortname, $configPath, $configuration;
$configuration = [];
$project_manager_dir = dirname(dirname(__DIR__));
$command = $_SERVER['argv'][1];
$shortname = $_SERVER['argv'][2];
$configPath = $_SERVER['argv'][3];
$value = $_SERVER['argv'][4] ?? null;
$pluginname = substr($configPath, 0, strpos($configPath, '.'));
$configPath = substr($configPath, strpos($configPath, '.')+1);
if (function_exists($command)) {
loadProjectManagerConfig();
if ($shortname !== "false") {
loadProjectConfig();
}
if (in_array($command, ['get', 'set', 'remove', 'has'])) {
$command();
}
}
function mergeConfig($file)
{
global $configuration;
if (!is_file($file)) {
return;
}
$configuration = array_merge(
$configuration,
json_decode(file_get_contents($file), true)
);
}
function loadProjectManagerConfig()
{
global $project_manager_dir;
$config_file = $project_manager_dir . '/etc/config.json';
mergeConfig($config_file);
}
function loadProjectConfig()
{
global $project_manager_dir;
$customer = getCustomerFromShortname();
$project = getProjectFromShortname();
$config_file = "$project_manager_dir/data/$customer/$project/etc/config.json";
mergeConfig($config_file);
$plugin_dir = dirname($config_file);
if(is_dir($plugin_dir)) {
$dh = opendir($plugin_dir);
if ($dh) {
while (false !== ($plugin = readdir($dh))) {
if ('.' === $plugin || '..' === $plugin || !is_dir($plugin_dir / $plugin)) {
continue;
}
$config_file = "$plugin_dir/$plugin/config.json";
mergeConfig($config_file);
}
}
}
}
function getCustomerFromShortname()
{
global $configuration, $shortname;
return $configuration['project_manager']['projects'][$shortname]['customer'] ?? null;
}
function getProjectFromShortname()
{
global $configuration, $shortname;
return $configuration['project_manager']['projects'][$shortname]['project'] ?? null;
}
function parsePath()
{
global $configPath;
$parsedPath = '';
foreach (explode('.', $configPath) as $part) {
$parsedPath .= "['$part']";
}
return $parsedPath;
}
function has()
{
echo is() ? 'true' : 'false';
}
function is()
{
global $configuration, $pluginname;
return eval("return isset(\$configuration['$pluginname']".parsePath().");");
}
function get()
{
global $configuration, $pluginname;
if (!is()) {
echo null;
exit(1);
}
$return = eval("return \$configuration['$pluginname']".parsePath().";");
if (is_array($return)) {
$echo = '';
foreach (array_keys($return) as $value) {
$echo .= '"'.$value.'" ';
}
$echo = trim($echo, ' ');
echo $echo;
exit;
}
echo $return;
}
function set()
{
global $configuration, $pluginname, $value;
$value = "null" === $value ? null : $value;
eval("\$configuration['$pluginname']".parsePath()." = \$value;");
writeConfig();
}
function remove()
{
global $configuration, $pluginname;
eval("unset(\$configuration['$pluginname']".parsePath().");");
writeConfig();
}
function writeConfig()
{
global $configuration, $project_manager_dir;
foreach($configuration as $pluginname => $data) {
if ('project_manager' === $pluginname) {
$config_file = "$project_manager_dir/etc/config.json";
} else {
$customer = getCustomerFromShortname();
$project = getProjectFromShortname();
if ('project' === $pluginname) {
$config_file = "$project_manager_dir/data/$customer/$project/etc/config.json";
} else {
$config_file = "$project_manager_dir/data/$customer/$project/etc/$pluginname/config.json";
if (!is_dir(dirname($config_file))) {
continue;
}
}
}
if (!is_dir(dirname($config_file))) {
mkdir(dirname($config_file), 0750, true);
}
if (!is_file($config_file)) {
touch($config_file);
}
file_put_contents($config_file, json_encode([$pluginname => $data], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
}
}

0
bin/includes/includes → src/includes/includes

222
src/includes/main_functions

@ -0,0 +1,222 @@
#!/bin/bash
### DO NOT EDIT THIS FILE
if [ true != ${includes_main_functions:-false} ]
then
includes_main_functions=true
function echoMainTitle {
echo -e "\033[38;5;214m$1\033[0m"
}
function echoSubTitle {
echo -e "\033[38;5;142m$1\033[0m"
}
function echoSmall {
echo -e "\033[38;5;240m$1\033[0m"
}
function echoSelect {
local select="$1"
local message="$2"
echo -e "\033[0;33m$select\033[0m $message"
}
function echoError {
echo -e "\033[0;91m$1\033[0m"
}
function echoWarning {
echo -e "\033[0;33m$1\033[0m"
}
function echoSuccess {
echo -e "\033[0;32m$1\033[0m"
}
function getParameter {
local name="$1"
local parameters=($2)
for i in "${!parameters[@]}"
do
if [[ "${parameters[$i]}" == *"--"* ]]
then
if [[ "${parameters[$i]}" == *"="* ]]
then
parameter="$(echo "${parameters[$i]}" | cut -d "=" -f 1)"
value="$(echo "${parameters[$i]}" | cut -d "=" -f 2)"
if [ "$parameter" == "$name" ]
then
echo "$value"
fi
else
if [ "${parameters[$i]}" == "$name" ]
then
echo true
fi
fi
fi
done
}
function getArgument {
local var="$1"
local errmsg="${2:-"Invalid Argument"}"
local allow="${3:-false}"
if [ "$allow" != false ] && [ "$(isAllowed "$var" "$allow")" == false ]
then
echo >&2
echoError "$errmsg" >&2
usage >&2
exit_program
fi
echo "$var"
}
function isAllowed {
local var="$1"
local allow="$2"
local valid=true
if [ "$allow" == true ] && [ "$var" == "" ]
then
valid=false
elif [ "$allow" != false ] && [ "$allow" != true ]
then
allow=($allow)
local found=false
for i in "${!allow[@]}"
do
if [ "${allow[$i]}" == "$var" ]
then
found=true
fi
done
if [ "$found" != true ]
then
valid=false
fi
fi
echo $valid
}
function readConsole {
local message="$1"
local errmsg="$2"
local allow=${3:-false}
local default="${4:-null}"
if [ "$default" != "" ] && [ "$default" != null ]
then
read -p "$message [default:$default]: " var
else
read -p "$message: " var
fi
if [ "$var" == "" ] && [ "$default" != "" ]
then
var="$default"
fi
if [ "$(isAllowed "$var" "$allow")" == false ]
then
echo "$errmsg" >&2
var=$(readConsole "$message" "$errmsg" "$allow" "$default")
fi
echo "$var"
}
function confirm {
if [ "$skip_confirm" == "n" ]
then
echo
echoError "Aborting"
echo
exit
fi
if [ "$skip_confirm" != "y" ]
then
confirm="$(readConsole "Should i execute? [y,n]" "Invalid selection" "y n")"
if [ "$confirm" == "n" ]
then
echo
echoError "Aborting"
echo
exit
fi
fi
}
function usageError {
error="$(getArgument "$1")"
echo
echoError "$error"
usage
exit
}
function postScript {
local script=$(getArgument "$1")
if [ -f "$script" ]
then
source "$script"
fi
}
function runPostscripts {
local script="$(getArgument "$1" "script is required" true)"
local shortname="$(getArgument "$2" "shortname is required" true)"
if [ "$shortname" != false ]
then
local project="$(getConfig false "project_manager.projects.$shortname.project")"
local customer="$(getConfig false "project_manager.projects.$shortname.customer")"
local project_dir="$project_manager_dir/data/$customer/$project"
fi
postScript "$project_manager_dir/src/postscripts/$script"
if [ "$shortname" != false ]
then
postScript "$project_dir/src/postscripts/$script"
fi
}
function getConfig {
local shortname="$(getArgument "$1" "shortname required" true)"
local configPath="$(getArgument "$2" "configPath required" true)"
local configScript="$project_manager_dir/src/includes/config"
echo "$(source "$configScript" get "$shortname" "$configPath")"
}
function setConfig {
local shortname="$(getArgument "$1" "shortname required" true)"
local configPath="$(getArgument "$2" "configPath required" true)"
local value="$(getArgument "$3" "value required" true)"
local configScript="$project_manager_dir/src/includes/config"
source "$configScript" set "$shortname" "$configPath" "$value"
}
function removeConfig {
local shortname="$(getArgument "$1" "shortname required" true)"
local configPath="$(getArgument "$2" "configPath required" true)"
local configScript="$project_manager_dir/src/includes/config"
source "$configScript" remove "$shortname" "$configPath"
}
function hasConfig {
local shortname="$(getArgument "$1" "shortname required" true)"
local configPath="$(getArgument "$2" "configPath required" true)"
local configScript="$project_manager_dir/src/includes/config"
echo "$(source "$configScript" has "$shortname" "$configPath")"
}
fi

28
src/includes/project_manager

@ -0,0 +1,28 @@
#!/bin/bash
### DO NOT EDIT THIS FILE
if [ true != ${includes_project_manager:-false} ]
then
includes_project_manager=true
function installPlugin {
local shortname="$(getArgument "$1")"
local customer="$(getConfig false "project_manager.projects.$shortname.customer")"
local project="$(getConfig false "project_manager.projects.$shortname.project")"
local plugin="$(getArgument "$2")"
local source_config_file="$project_manager_dir/plugins/$plugin/etc/config.json"
local target_config_dir="$project_manager_dir/data/$customer/$project/etc/$plugin"
local target_config_file="$target_config_dir/config.json"
if [ ! -d "$target_config_dir"]
then
mkdir -p "$target_config_dir"
fi
if [ ! -f "$target_config_file"]
then
cp "$source_config_file" "$target_config_source_config_file"
fi
}
fi

0
bin/postscripts/commands/.keep → src/postscripts/plugins/.keep

Loading…
Cancel
Save