Sven Ullmann
2 years ago
41 changed files with 668 additions and 634 deletions
-
4.gitignore
-
44bin/commands/install-plugin
-
59bin/commands/remove-project
-
165bin/includes/config
-
195bin/includes/main_functions
-
110bin/includes/project_manager
-
0bin/postscripts/plugins/.keep
-
41bin/project-manager
-
0plugins/db/src/commands/backup
-
0plugins/db/src/commands/create-config
-
0plugins/db/src/includes/includes
-
0plugins/git/src/commands/clone
-
0plugins/git/src/includes/includes
-
0plugins/shopware6/bin/includes/includes
-
2plugins/shopware6/notice.txt
-
0src/bak/commands/import_media.sh
-
0src/bak/commands/install_remote_system.sh
-
0src/bak/commands/install_shopware.sh
-
0src/bak/commands/make_local_database.sh
-
0src/bak/commands/switch_local_env.sh
-
0src/bak/functions/backup_db.sh
-
0src/bak/functions/clone_repo.sh
-
0src/bak/functions/create_database.sh
-
0src/bak/functions/create_directories.sh
-
0src/bak/functions/deploy.sh
-
0src/bak/functions/fetch_files.sh
-
0src/bak/functions/import_db.sh
-
0src/bak/functions/link_latest_db.sh
-
0src/bak/functions/write_shopware_env_file.sh
-
33src/commands/create-project
-
51src/commands/install-plugin
-
30src/commands/install-project-manager
-
16src/commands/list-projects
-
87src/commands/remove-project
-
9src/includes/bash_header
-
36src/includes/config
-
166src/includes/config.php
-
0src/includes/includes
-
222src/includes/main_functions
-
28src/includes/project_manager
-
0src/postscripts/plugins/.keep
@ -1,7 +1,7 @@ |
|||
/.idea |
|||
/.trash |
|||
/bin/postscripts/commands/* |
|||
/bin/postscripts/plugins/* |
|||
/src/postscripts/commands/* |
|||
/src/postscripts/plugins/* |
|||
/data/* |
|||
/etc/* |
|||
|
@ -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 |
@ -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 |
@ -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)); |
|||
} |
|||
} |
@ -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 |
@ -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,0 +1,2 @@ |
|||
composer create-project shopware/production <project-name> |
|||
bin/console system:install --basic-setup |
@ -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 |
@ -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 |
@ -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" "$@" |
@ -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,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 |
@ -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 |
Write
Preview
Loading…
Cancel
Save
Reference in new issue