Browse Source

add directory validations

master
Sven Ullmann 2 years ago
parent
commit
1cb23e661e
  1. 94
      bin/commands/create-project
  2. 44
      bin/commands/remove-project
  3. 8
      plugins/git/commands/clone

94
bin/commands/create-project

@ -59,49 +59,26 @@ echoMainTitle "Create project"
echo echo
echoSubTitle "Please verify data" echoSubTitle "Please verify data"
echo echo
echo "Project Path: $workspaces_dir/$customer/$project"
echo "Project Data Path: $project_manager_dir/data/$customer/$project"
echo "Project path: $workspaces_dir/$customer/$project"
echo "Project data path: $project_manager_dir/data/$customer/$project"
echo echo
confirm 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
)
if [ -d "$project_manager_dir/data/$customer/$project" ] || [ -d "$project_manager_dir/data/$customer/$project" ]
then
echo
echoError "Data path already exists"
echo
exit
fi
EOF
if [ -d "$workspaces_dir/$customer/$project" ] || [ -d "$workspaces_dir/$customer/$project" ]
then
echo
echoError "Path already exists"
echo
exit
fi
path="$project_manager_dir/data/$customer/$project" path="$project_manager_dir/data/$customer/$project"
@ -148,6 +125,45 @@ done
if [ ! -d "$workspaces_dir/$customer/$project" ]; then mkdir -p "$workspaces_dir/$customer/$project"; fi if [ ! -d "$workspaces_dir/$customer/$project" ]; then mkdir -p "$workspaces_dir/$customer/$project"; fi
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
echo echo
echoSubTitle "Running postscripts ..." echoSubTitle "Running postscripts ..."
postScript "$path/bin/postscripts/commands/create-project" postScript "$path/bin/postscripts/commands/create-project"

44
bin/commands/remove-project

@ -56,6 +56,28 @@ echo "Project Data Path: $project_manager_dir/data/$customer/$project"
echo echo
confirm confirm
echo
echo "Moving files to trash"
customer_dir_list=($(ls -t "$project_manager_dir/data/$customer"))
has_more_dirs=$(if [ "${#customer_dir_list[@]}" -gt 1 ]; then echo true; else echo false; fi)
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_manager_dir/data/$customer/$project" "$trash_path/data/$customer/$project"
mv "$workspaces_dir/$customer/$project" "$trash_path/workspace/$customer/$project"
if [ "$has_more_dirs" != true ]
then
rmdir "$project_manager_dir/data/$customer"
rmdir "$workspaces_dir/$customer"
fi
nr=0 nr=0
projects_string=''; projects_string='';
for i in "${!projects[@]}" for i in "${!projects[@]}"
@ -101,28 +123,6 @@ customers=($customers_string
EOF EOF
echo
echo "Moving files to trash"
customer_dir_list=($(ls -t "$project_manager_dir/data/$customer"))
has_more_dirs=$(if [ "${#customer_dir_list[@]}" -gt 1 ]; then echo true; else echo false; fi)
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_manager_dir/data/$customer/$project" "$trash_path/data/$customer/$project"
mv "$workspaces_dir/$customer/$project" "$trash_path/workspace/$customer/$project"
if [ "$has_more_dirs" != true ]
then
rmdir "$project_manager_dir/data/$customer"
rmdir "$workspaces_dir/$customer"
fi
echo echo
echoSubTitle "Running postscripts ..." echoSubTitle "Running postscripts ..."
postScript "$path/bin/postscripts/commands/remove-project" postScript "$path/bin/postscripts/commands/remove-project"

8
plugins/git/commands/clone

@ -42,14 +42,14 @@ echo "GIT User: $git_ssh_user"
echo "GIT Domain: $git_ssh_domain" echo "GIT Domain: $git_ssh_domain"
echo "Install Location: $workspaces_dir/$customer/$project" echo "Install Location: $workspaces_dir/$customer/$project"
echo echo
confirm="$(readConsole "Should i execute [y,n]:" "Invalid selection" "y n")"
confirm
if [ "$confirm" == "n" ]
if [ ! -d "$workspaces_dir/$customer/$project" ]
then then
echo echo
echoError "Aborting"
echoError "Wprkspace dir not exists"
echo echo
exit;
exit
fi fi
sshAddKey "git" sshAddKey "git"

Loading…
Cancel
Save