#!/bin/bash                                                                             
                                            
upload_dir_stripper="/home/test/home/stripper_files/upload_stripper"
upload_dir_entwatch="/home/test/home/stripper_files/upload_entwatch"
upload_dir_bosshp="/home/test/home/stripper_files/upload_bosshp"
upload_dir_bspmaps="/home/test/home/stripper_files/upload_bspmaps"
upload_dir_mapcycle="/home/test/home/stripper_files/upload_mapcycle"

stripper_dir="/home/gameservers/css_ze/cstrike/addons/stripper/maps"
entwatch_dir="/home/gameservers/css_ze/cstrike/addons/sourcemod/configs/entwatch"
bosshp_dir="/home/gameservers/css_ze/cstrike/addons/sourcemod/configs/bosshp"
bspmaps_dir="/home/gameservers/css_ze/cstrike/maps"
cfg_dir="/home/gameservers/css_ze/cstrike/cfg"

stripper_maps_dir="/home/test/home/stripper_files/maps"
entwatch_end_dir="/home/test/home/stripper_files/entwatch"
bosshp_end_dir="/home/test/home/stripper_files/bosshp"
mapcycle_end_dir="/home/test/home/stripper_files/mapcycle"

#the mapcycle.txt file to add maps to the public nomlist.
# Check if the source directory exists                                                  
if [ -d "$upload_dir_mapcycle" ]; then                                                           
  for file in "$upload_dir_mapcycle"/*; do                                                       
        if [ -f "$file" ]; then
            if [ "$(basename "$file")" = "mapcycle.txt" ]; then
                # Move the mapcyle file to the destination directory
                chown gameservers:gameservers "$file"
                chmod 775 "$file"
                mv "$file" "$cfg_dir/"
                #echo "File '$file' moved successfully."
            fi
        fi
    done
fi

#copy files from real dir to the jail
if [ -d "$cfg_dir" ]; then
  for file in "$cfg_dir"/*; do
        if [ -f "$file" ]; then
            if [ "$(basename "$file")" = "mapcycle.txt" ]; then
                #copy the mapcycle file to mapcycle_end_dir 
                cp --force "$file" "$mapcycle_end_dir/"
                #echo "File '$file' moved successfully."
            fi
        fi
    done
fi

#chown the new files inside the jail.

if [ -d "$mapcycle_end_dir" ]; then
  for file in "$mapcycle_end_dir"/*; do
        if [ -f "$file" ]; then
            chown stripper_files:stripper_files "$file"
            chmod 775 "$file"
            #echo "File '$file' modified successfully."
        fi
    done
fi




#bsp map files
# Check if the source directory exists                                                  
if [ -d "$upload_dir_bspmaps" ]; then                                                           
  for file in "$upload_dir_bspmaps"/*; do                                                       
        if [ -f "$file" ]; then                                                         
            # Move each file to the destination directory
            chown gameservers:gameservers "$file"
            chmod 775 "$file"
            mv "$file" "$bspmaps_dir/"
            #echo "File '$file' moved successfully."
        fi
    done
fi

#we dont want to copy the files back. this only goes one direction.


#stripper files
# Check if the source directory exists                                                  
if [ -d "$upload_dir_stripper" ]; then                                                           
  for file in "$upload_dir_stripper"/*; do                                                       
        if [ -f "$file" ]; then                                                         
            # Move each file to the destination directory
            chown gameservers:gameservers "$file"
            chmod 775 "$file"
            mv "$file" "$stripper_dir/"
            #echo "File '$file' moved successfully."
        fi
    done
fi

#copy files from real dir to the jail

if [ -d "$stripper_dir" ]; then
  for file in "$stripper_dir"/*; do
        if [ -f "$file" ]; then
            #copy each file to stripper_maps_dir 
            cp --force "$file" "$stripper_maps_dir/"
            #echo "File '$file' moved successfully."
        fi
    done
fi

#chown the new files inside the jail.

if [ -d "$stripper_maps_dir" ]; then
  for file in "$stripper_maps_dir"/*; do
        if [ -f "$file" ]; then
            chown stripper_files:stripper_files "$file"
            chmod 775 "$file"
            #echo "File '$file' modified successfully."
        fi
    done
fi


# entwatch files.
# Check if the source directory exists                                                  
if [ -d "$upload_dir_entwatch" ]; then                                                           
  for file in "$upload_dir_entwatch"/*; do                                                       
        if [ -f "$file" ]; then                                                         
            # Move each file to the destination directory
            chown gameservers:gameservers "$file"
            chmod 775 "$file"
            mv "$file" "$entwatch_dir/"
            #echo "File '$file' moved successfully."
        fi
    done
fi


if [ -d "$entwatch_dir" ]; then
  for file in "$entwatch_dir"/*; do
        if [ -f "$file" ]; then
            #copy each file to entwatch_end_dir 
            cp --force "$file" "$entwatch_end_dir/"
            #echo "File '$file' moved successfully."
        fi
    done
fi

if [ -d "$entwatch_end_dir" ]; then
  for file in "$entwatch_end_dir"/*; do
        if [ -f "$file" ]; then
            chown stripper_files:stripper_files "$file"
            chmod 775 "$file"
            #echo "File '$file' modified successfully."
        fi
    done
fi

#bosshp files
# Check if the source directory exists                                                  
if [ -d "$upload_dir_bosshp" ]; then                                                           
  for file in "$upload_dir_bosshp"/*; do                                                       
        if [ -f "$file" ]; then                                                         
            # Move each file to the destination directory
            chown gameservers:gameservers "$file"
            chmod 775 "$file"
            mv "$file" "$bosshp_dir/"
            #echo "File '$file' moved successfully."
        fi
    done
fi


if [ -d "$bosshp_dir" ]; then
  for file in "$bosshp_dir"/*; do
        if [ -f "$file" ]; then
            #copy each file to entwatch_end_dir 
            cp --force "$file" "$bosshp_end_dir/"
            #echo "File '$file' moved successfully."
        fi
    done
fi

if [ -d "$bosshp_end_dir" ]; then
  for file in "$bosshp_end_dir"/*; do
        if [ -f "$file" ]; then
            chown stripper_files:stripper_files "$file"
            chmod 775 "$file"
            #echo "File '$file' modified successfully."
        fi
    done
fi
