Browse Source

refactoring

master
Sven Ullmann 2 years ago
parent
commit
e7e8d8fc5d
  1. 5
      .gitignore
  2. 3
      README.md
  3. 15
      bin/commands/create-project
  4. 3
      bin/commands/install-plugin
  5. 30
      bin/commands/install-project-manager
  6. 2
      bin/commands/list-projects
  7. 3
      bin/commands/remove-project
  8. 20
      bin/includes/bash_header
  9. 165
      bin/includes/config
  10. 30
      bin/includes/main_functions
  11. 191
      bin/includes/project_manager
  12. 24
      bin/project-manager
  13. 25
      etc/.config_template
  14. 3
      etc/.customers_template
  15. 5
      etc/.project_manager_config_template
  16. 3
      etc/.projects_template
  17. 3
      etc/.shortnames_template
  18. 57
      plugins/db/etc/config
  19. 44
      plugins/db/etc/config.json

5
.gitignore

@ -3,9 +3,6 @@
/bin/postscripts/commands/* /bin/postscripts/commands/*
/bin/postscripts/plugins/* /bin/postscripts/plugins/*
/data/* /data/*
/etc/config
/etc/projects
/etc/customers
/etc/shortnames
/etc/*
!/**/.keep !/**/.keep

3
README.md

@ -11,6 +11,9 @@ Hope you will enjoy. Free to use.
## Installation and first use ## Installation and first use
### Prerequisites
- PHP
### Install Project Manager ### Install Project Manager
In order to get you startet create first a folder, eg: In order to get you startet create first a folder, eg:

15
bin/commands/create-project

@ -59,19 +59,10 @@ confirm
makeProjectManagerDirectories "$shortname" makeProjectManagerDirectories "$shortname"
makeWorkspaceDirectories "$shortname" makeWorkspaceDirectories "$shortname"
addProjectConfig "$customer" "$project" "$shortname"
configSet "project_manager.projects.$shortname.customer" "$customer"
configSet "project_manager.projects.$shortname.project" "$project"
#if [ ! -f "$path/etc/config" ]
#then
# quoted="$(sedEscape "$project_manager_dir")"
# cat "$project_manager_dir/etc/.config_template" | \
# sed "s/app_customer=''/app_customer='$customer'/" | \
# sed "s/app_project=''/app_project='$project'/" | \
# sed "s/app_project_manager_dir=''/app_project_manager_dir='$quoted'/" \
# > "$path/etc/config"
#fi
postScript "$project_manager_dir/bin/postscripts/commands/create-project"
runPostscripts "$shortname" "commands/create-project"
echo echo
echoSuccess "Project has been created, please configure $project_dir/etc" echoSuccess "Project has been created, please configure $project_dir/etc"

3
bin/commands/install-plugin

@ -37,8 +37,7 @@ do
cp "$etc_file" "$project_dir/etc/plugins/$plugin/." cp "$etc_file" "$project_dir/etc/plugins/$plugin/."
done done
postScript "$project_manager_dir/bin/postscripts/commands/install-plugin"
postScript "$project_dir/bin/postscripts/commands/install-plugin"
runPostscripts "$shortname" "commands/install-plugin"
echo echo
echoSuccess "Plugin has been installed, please configure: $project_dir/etc/plugins/$plugin" echoSuccess "Plugin has been installed, please configure: $project_dir/etc/plugins/$plugin"

30
bin/commands/install-project-manager

@ -29,36 +29,14 @@ echoMainTitle "Install Sumedia Project Manager"
echo echo
echoSubTitle "Please configure Sumedia Project Manager" echoSubTitle "Please configure Sumedia Project Manager"
echo echo
workspaces_dir="$(readConsole "Workspaces dir" "Invalid selection" true "$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." &> /dev/null && pwd)")"
local_apache_httpdocs="$(readConsole "Local Apache httpdocs dir (optional)" "Invalid selection" true)"
sudo_password="$(readConsole "sudo password (optional)" "Invalid selection" true)"
if [ ! -f "$project_manager_dir/etc/config" ]
then
cat "$project_manager_dir/etc/.project_manager_config_template" | \
sed "s/project_manager_workspaces_dir=''/project_manager_workspaces_dir='$(sedEscape "$workspaces_dir")'/" | \
sed "s/project_manager_local_apache_httpdocs=''/project_manager_local_apache_httpdocs='$(sedEscape "$local_apache_httpdocs")'/" \
sed "s/project_manager_sudo_password=''/project_manager_sudo_password='$(sedEscape "$sudo_password")'/" \
> "$project_manager_dir/etc/config"
fi
if [ ! -f "$project_manager_dir/etc/projects" ]
then
cp "$project_manager_dir/etc/.projects_template" "$project_manager_dir/etc/projects"
fi
if [ ! -f "$project_manager_dir/etc/customers" ]
then
cp "$project_manager_dir/etc/.customers_template" "$project_manager_dir/etc/customers"
fi
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)"
if [ ! -f "$project_manager_dir/etc/shortnames" ]
then
cp "$project_manager_dir/etc/.shortnames_template" "$project_manager_dir/etc/shortnames"
fi
setConfig "project_manager.workspaces_dir" "$workspaces_dir"
setConfig "project_manager.apache_httpdocs" "$apache_httpdocs"
postScript "$project_manager_dir/bin/postscripts/commands/install-project-manager" postScript "$project_manager_dir/bin/postscripts/commands/install-project-manager"
postScript "$workspaces_dir/$customer/$project/bin/postscripts/commands/install-project-manager"
echo echo
echoSuccess "Project Manager has been installed." echoSuccess "Project Manager has been installed."

2
bin/commands/list-projects

@ -40,3 +40,5 @@ then
else else
listProjects listProjects
fi fi
postScript "$project_manager_dir/bin/postscripts/commands/list-projects"

3
bin/commands/remove-project

@ -51,7 +51,8 @@ mv "$workspace_dir" "$trash_path/workspace/$customer/$project"
removeProjectConfig "$shortname" removeProjectConfig "$shortname"
postScript "$project_manager_dir/bin/postscripts/commands/remove-project"
runPostscripts "$shortname" "commands/remove-project"
postScript "$trash_path/data/bin/postscripts/commands/remove-project"
echo echo
echoSuccess "Project has been removed" echoSuccess "Project has been removed"

20
bin/includes/bash_header

@ -4,20 +4,14 @@
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)/includes" source "$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)/includes"
project_manager_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." &> /dev/null && pwd)"
help="$(getParameter "--help" false "$*")" help="$(getParameter "--help" false "$*")"
if [ "$help" == true ] || [ "$1" == "" ] if [ "$help" == true ] || [ "$1" == "" ]
then then
usage
exit
if [ "$2" == false ]
then
usage
exit
fi
fi fi
project_manager_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../" &> /dev/null && pwd)"
config_file="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." &> /dev/null && pwd)/etc/config"
if [ -f "$config" ]; then source "$config_file"; fi
projects_file="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." &> /dev/null && pwd)/etc/projects"
if [ -f "$projects_file" ]; then source "$projects_file"; fi
customers_file="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." &> /dev/null && pwd)/etc/customers"
if [ -f "$customers_file" ]; then source "$customers_file"; fi
shortnames_file="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." &> /dev/null && pwd)/etc/shortnames"
if [ -f "$shortnames_file" ]; then source "$shortnames_file"; fi

165
bin/includes/config

@ -0,0 +1,165 @@
#!/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));
}
}

30
bin/includes/main_functions

@ -162,4 +162,34 @@ then
echo project_manager_sudo_password 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 fi

191
bin/includes/project_manager

@ -107,195 +107,4 @@ then
if [ ! -d "$project_manager_workspaces_dir/$customer/$project" ]; then mkdir -p "$project_manager_workspaces_dir/$customer/$project"; fi if [ ! -d "$project_manager_workspaces_dir/$customer/$project" ]; then mkdir -p "$project_manager_workspaces_dir/$customer/$project"; fi
} }
function addProjectConfig {
local shortname="$(getArgument "$1")"
local customer="$(getArgument "$2")"
local project="$(getArgument "$3")"
_addProject "$project"
_addCustomer "$customer"
_addShortname "$shortname"
}
function hasShortname {
local shortname="$(getArgument "$1")"
for i in "${!project_manager_shortnames[@]}"
do
if [ "${project_manager_shortname[$i]}" == "$shortname" ]
then
echo true
fi
done
echo false
}
function hasProject {
local project="$(getArgument "$1")"
for i in "${!project_manager_projects[@]}"
do
if [ "${project_manager_projects[$i]}" == "$project" ]
then
echo true
fi
done
echo false
}
function _addShortname {
local shortname="$(getArgument "$1")"
local hasShortname="$(hasShortname "$shortname")"
if [ "$hasShortname" == true ]
then
echo
echoError "Shortname already exists"
echo
exit
fi
local string='';
for i in "${!project_manager_shortnames[@]}"
do
string+="$(echo -e "\n\t'${project_manager_shortnames[$i]}'")"
done
string+="$(echo -e "\n\t'$shortname'")"
_writeShortnames "$string"
}
function _addProject {
local project="$(getArgument "$1")"
local hasProject="$(hasProject "$project")"
if [ "$hasProject" == true ]
then
echo
echoError "Project already exists"
echo
exit
fi
local string='';
for i in "${!project_manager_projects[@]}"
do
string+="$(echo -e "\n\t'${project_manager_projects[$i]}'")"
done
string+="$(echo -e "\n\t'$project'")"
_writeProjects "$string"
}
function _addCustomer {
local customer="$(getArgument "$1")"
local string='';
for i in "${!project_manager_customers[@]}"
do
string+="$(echo -e "\n\t'${project_manager_customers[$i]}'")"
done
string+="$(echo -e "\n\t'$customer'")"
_writeCustomers "$string"
}
function _writeShortnames {
local string="$(getArgument "$1")"
cat <<- EOF > "$project_manager_dir/etc/shortnames"
#!/bin/bash
project_manager_shortnames=($string
)
EOF
}
function _writeCustomers {
local string="$(getArgument "$1")"
cat <<- EOF > "$project_manager_dir/etc/customers"
#!/bin/bash
project_manager_customers=($string
)
EOF
}
function _writeProjects {
local string="$(getArgument "$1")"
cat <<- EOF > "$project_manager_dir/etc/projects"
#!/bin/bash
project_manager_projects=($string
)
EOF
}
function removeProjectConfig {
local shortname="$(getArgument "$1")"
local pos="$(getProjectConfigPosition "$shortname")"
_removeShortname "$pos"
_removeCustomer "$pos"
_removeProject "$pos"
}
function getProjectConfigPosition {
local shortname="$(getArgument "$1")"
for i in "${!project_manager_shortnames[@]}"
do
if [ "${$project_manager_shortnames[$i]}" == "$shortname" ]
then
((ret=i+1))
return "$ret"
fi
done
return 0
}
function _removeShortname {
local pos="$(getArgument "$1")"
local string='';
for i in "${!project_manager_shortnames[@]}"
do
((nr=i+1))
if [ "$pos" == "$nr" ]
then
continue
fi
string+="$(echo -e "\n\t'${project_manager_shortnames[$i]}'")"
done
_writeShortnames "$string"
}
function _removeProjects {
local pos="$(getArgument "$1")"
local string='';
for i in "${!project_manager_projects[@]}"
do
((nr=i+1))
if [ "$pos" == "$nr" ]
then
continue
fi
string+="$(echo -e "\n\t'${project_manager_projects[$i]}'")"
done
_writeProjects "$string"
}
function _removeCustomer {
local pos="$(getArgument "$1")"
local string='';
for i in "${!project_manager_customers[@]}"
do
((nr=i+1))
if [ "$pos" == "$nr" ]
then
continue
fi
string+="$(echo -e "\n\t'${project_manager_customers[$i]}'")"
done
_writeCustomers "$string"
}
fi fi

24
bin/project-manager

@ -3,23 +3,10 @@ set -e
### DO NOT EDIT THIS FILE ### DO NOT EDIT THIS FILE
project_manager_dir="$(readlink -f "$(dirname "$(readlink -f ${BASH_SOURCE[0]})")/..")"
source "$project_manager_dir/bin/includes/includes"
if [ -f "$project_manager_dir/etc/config" ]
then
source "$project_manager_dir/etc/config"
fi
if [ -f "$project_manager_dir/etc/projects" ]
then
source "$project_manager_dir/etc/projects"
fi
function use {
function usage {
echo echo
echoMainTitle "Sumedia Project Manager" echoMainTitle "Sumedia Project Manager"
echoSmall "Manager: $project_manager_dir" echoSmall "Manager: $project_manager_dir"
echoSmall "Workspaces: $workspaces_dir"
echo echo
echoSubTitle "Usage:" echoSubTitle "Usage:"
echo echo
@ -35,6 +22,8 @@ function use {
echo echo
} }
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)/includes/bash_header"
function list { function list {
local dir=$1 local dir=$1
@ -154,12 +143,5 @@ else
fi fi
fi fi
echo
echoSubTitle "Running postscripts ..."
postScript "$project_manager_dir/bin/postscripts/project-manager" postScript "$project_manager_dir/bin/postscripts/project-manager"
echo
echoSuccess "Project Manager done"
echo
fi fi

25
etc/.config_template

@ -1,25 +0,0 @@
#!/bin/bash
### LOCAL STAGE ENV
# url to stage
local_stage_url=''
# The httpdocs folder on your server
local_stage_httpdocs_path=''
### LOCAL LIVE ENV
# url to live
local_live_url=''
# The httpdocs folder on your server
local_live_httpdocs_path=''
### POSTSCRIPTS
app_dir=
if [ -f '$app_dir/etc/post_config.sh' ]
then
source '$app_dir/etc/post_config.sh'
fi

3
etc/.customers_template

@ -1,3 +0,0 @@
#!/bin/bash
project_manager_customers=()

5
etc/.project_manager_config_template

@ -1,5 +0,0 @@
#!/bin/bash
project_manager_workspaces_dir=''
project_manager_local_apache_httpdocs='' # leave empty if you don't want to use
project_manager_sudo_password='' # leave empty to fetch on call

3
etc/.projects_template

@ -1,3 +0,0 @@
#!/bin/bash
project_manager_projects=()

3
etc/.shortnames_template

@ -1,3 +0,0 @@
#!/bin/bash
project_manager_shortnames=()

57
plugins/db/etc/config

@ -1,57 +0,0 @@
#!/bin/bash
### STAGE
db_stage_socket=''
db_stage_host=''
db_stage_port=''
db_stage_database=''
db_stage_user=''
db_stage_password=''
# the admmin user is used to create and drop databases
db_stage_admin_user=''
db_stage_admin_password=''
### LIVE
db_live_socket=''
db_live_host=''
db_live_port=''
db_live_database=''
db_live_user=''
db_live_password=''
# the admmin user is used to create and drop databases
db_live_admin_user=''
db_live_admin_password=''
### LOCAL_STAGE
# you can drive you local installation with a copy of stage or live
db_local_stage_socket=''
db_local_stage_host=''
db_local_stage_port=''
db_local_stage_database=''
db_local_stage_user=''
db_local_stage_password=''
# the admmin user is used to create and drop databases
db_local_stage_admin_user=''
db_local_stage_admin_password=''
### LOCAL_LIVE
# you can drive you local installation with a copy of stage or live
db_local_live_socket=''
db_local_live_host=''
db_local_live_port=''
db_local_live_database=''
db_local_live_user=''
db_local_live_password=''
# the admmin user is used to create and drop databases
db_local_live_admin_user=''
db_local_live_admin_password=''

44
plugins/db/etc/config.json

@ -0,0 +1,44 @@
{
"db": {
"stage": {
"socket": "",
"host": "",
"port": "",
"database": "",
"user": "",
"password": "",
"admin_user": "",
"admin_password": ""
},
"live": {
"socket": "",
"host": "",
"port": "",
"database": "",
"user": "",
"password": "",
"admin_user": "",
"admin_password": ""
},
"local_stage": {
"socket": "",
"host": "",
"port": "",
"database": "",
"user": "",
"password": "",
"admin_user": "",
"admin_password": ""
},
"local_live": {
"socket": "",
"host": "",
"port": "",
"database": "",
"user": "",
"password": "",
"admin_user": "",
"admin_password": ""
}
}
}
Loading…
Cancel
Save