Ein für Shopware 6 vorbereitet Systemmanagment.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

158 lines
4.3 KiB

#!/bin/bash
source "$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." &> /dev/null && pwd)/etc/config"
source "$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." &> /dev/null && pwd)/etc/projects"
function usage {
echo
echoMainTitle "Creates a new project"
echo
echoSubTitle "Usage:"
echo
echo "create-project [customer] [project] [shortname]"
echo
echo "The given customer and project will result in the file directory as you have setted"
echo "it in project_manager/etc/projects configuration file:"
echo " - workspace_dir/customer/project"
echo " - data_dir/customer/project"
echo "It will set a configuration file for your project to:"
echo " - data_dir/customer/project/etc/config"
echo
echo "--help Prints this message"
echo
}
help="$(getParameter "--help" false "$@")"
if [ "$help" == true ] || [ "$1" == "" ]
then
usage
exit
fi
customer=$(getArgument "$1" "$(usage)" true)
project=$(getArgument "$2" "$(usage)" true)
shortname=$(getArgument "$3" "$(usage)" true)
for p in "${projects[@]}"
do
if [ "$p" == "$project" ]
then
echoError "Project already exists"
echo
exit
fi
done
for s in "${shortnames[@]}"
do
if [ "$s" == "$shortname" ]
then
echoError "Shortname already exists"
echo
exit
fi
done
echo
echoMainTitle "Create project"
echo
echoSubTitle "Please verify data"
echo
echo "Project Path: $workspaces_dir/$customer/$project"
echo "Project Data Path: $project_manager_dir/data/$customer/$project"
echo
confirm
projects_string='';
for i in "${!projects[@]}"
do
((nr=i+1))
projects_string+="$(echo -e "\n\t\"${projects[$i]}\" # $nr")"
done
((nr=nr+1))
projects_string+="$(echo -e "\n\t\"$project\" # $nr")"
shortnames_string='';
for i in "${!shortnames[@]}"
do
((nr=i+1))
shortnames_string+="$(echo -e "\n\t\"${shortnames[$i]}\" # $nr")"
done
((nr=nr+1))
shortnames_string+="$(echo -e "\n\t\"$shortname\" # $nr")"
customers_string='';
for i in "${!customers[@]}"
do
((nr=i+1))
customers_string+="$(echo -e "\n\t\"${customers[$i]}\" # $nr")"
done
((nr=nr+1))
customers_string+="$(echo -e "\n\t\"$customer\" # $nr")"
cat <<- EOF > "$project_manager_dir/etc/projects"
#!/bin/bash
projects=($projects_string
)
shortnames=($shortnames_string
)
customers=($customers_string
)
EOF
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/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
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
plugin_path="$project_manager_dir/plugins"
plugins=$(ls -t "$plugin_path")
for plugin in ${plugins[*]}
do
etc_file="$plugin_path/$plugin/etc/.config_template"
if [ -f "$etc_file" ] && [ ! -f "$path/etc/plugins/$plugin/config" ]
then
if [ ! -d "$path/etc/plugins/$plugin" ]
then
mkdir "$path/etc/plugins/$plugin"
fi
cp "$etc_file" "$path/etc/plugins/$plugin/config"
fi
done
if [ ! -d "$workspaces_dir/$customer/$project" ]; then mkdir -p "$workspaces_dir/$customer/$project"; fi
echo
echoSubTitle "Running postscripts ..."
postScript "$path/bin/postscripts/commands/create-project"
postScript "$workspaces_dir/$customer/$project/bin/postscripts/commands/create-project"
echo
echoSuccess "Project has been created, please configure: $path/etc/*"
echo