-
Notifications
You must be signed in to change notification settings - Fork 274
/
Copy pathclean_directory.sh
54 lines (43 loc) · 1.64 KB
/
clean_directory.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
# Delete all files and folders in the directory: /pythainlp/docs/<version>
# $1 : FTP_USER
# $2 : FTP_PASSWORD
# $3 : FTP_HOST
# $4 : Branch name
FTP_USER=$1
FTP_PASSWORD=$2
FTP_HOST=$3
BRANCH_NAME=$4
remove_all_files()
{
# DIRECTORY=$1
echo "Delete files in: $1"
for f in `curl --list-only --ftp-create-dirs --ipv4 ftp://$FTP_USER:$FTP_PASSWORD@$FTP_HOST/$1/`; do
if [[ -d "$f" ]] || [[ "$f" = _* ]] || [[ "$f" = .doctree ]] || [[ "$f" != *"."* ]]; then
echo "--- deleting files in folder: $1/$f";
remove_all_files $1/$f
else
echo "Delete a file: $f"
curl --ipv4 ftp://$FTP_USER:$FTP_PASSWORD@$FTP_HOST -Q "DELE $1/$f"
fi
done
}
remove_empty_folders()
{
echo "Delete empty folders in: $1"
for f in `curl --list-only --ftp-create-dirs --ipv4 ftp://$FTP_USER:$FTP_PASSWORD@$FTP_HOST/$1/`; do
if [[ -d "$f" ]] || [[ "$f" = _* ]] || [[ "$f" = fonts ]] || [[ "$f" = pythainlp ]] || [[ "$f" = .doctree ]] || [[ "$f" != *"."* ]]; then
echo "--- Deleting folders in: $1/$f";
remove_empty_folders $1/$f
curl --ipv4 ftp://$FTP_USER:$FTP_PASSWORD@$FTP_HOST -Q "RMD $1/$f"
else
echo "Delete a folder: $f"
curl --ipv4 ftp://$FTP_USER:$FTP_PASSWORD@$FTP_HOST -Q "RMD $1/$f"
fi
done
}
echo "Start removing all files within: public_html/pythainlp/docs/$BRANCH_NAME/";
remove_all_files public_html/pythainlp/docs/$BRANCH_NAME;
echo "Start removing all empty folders within: public_html/pythainlp/docs/$BRANCH_NAME/";
remove_empty_folders public_html/pythainlp/docs/$BRANCH_NAME;
echo "Done.";