#!/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 "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 } help="$(getParameter "--help" false "$@")" if [ "$help" == true ] || [ "$1" == "" ] then usage exit fi shortname="$(getArgument "$1" "$(usage)" true)" customer="$(getCustomerFromShortname "$shortname")" project="$(getProjectFromShortname "$shortname")" index=false for i in "${!shortnames[@]}" do if [ "${shortnames[$i]}" == "$shortname" ] then index="$i" fi done if [ "$index" == false ] then echo echoError "Could not find project: $shortname" echo exit fi echo echoMainTitle "Remove 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 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 projects_string=''; for i in "${!projects[@]}" do if [ "$i" != "$index" ] then ((nr=nr+1)) projects_string+="$(echo -e "\n\t\"${projects[$i]}\" # $nr")" fi done nr=0 shortnames_string=''; for i in "${!shortnames[@]}" do if [ "$i" != "$index" ] then ((nr=nr+1)) shortnames_string+="$(echo -e "\n\t\"${shortnames[$i]}\" # $nr")" fi done nr=0 customers_string=''; for i in "${!customers[@]}" do if [ "$i" != "$index" ] then ((nr=nr+1)) customers_string+="$(echo -e "\n\t\"${customers[$i]}\" # $nr")" fi done cat <<- EOF > "$project_manager_dir/etc/projects" #!/bin/bash projects=($projects_string ) shortnames=($shortnames_string ) customers=($customers_string ) EOF echo echoSubTitle "Running postscripts ..." postScript "$path/bin/postscripts/commands/remove-project" postScript "$workspaces_dir/$customer/$project/bin/postscripts/commands/remove-project" echo echoSuccess "Project has been remove, (moved to ./.trash)" echo