aboutsummaryrefslogtreecommitdiff
path: root/send-refresh.sh
blob: 422f787c1dc451d0e28496a828dab0ecf62919fa (plain)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash

# Recursively delete directories by age (14 days), and only exactly at the depth of the base directory
#find /path/to/base/dir/ -mindepth 1 -maxdepth 1 -type d -ctime +14 -exec rm -rf {} \;


# Discover files in the user's home directory, older than 14 days, and delete them
#find /path/to/home/dir/ -mindepth 1 -maxdepth 1 -type f -ctime +14 -exec rm -rf {} \;
# Discover files in the user's home directory, younger than 14 days
#find /path/to/home/dir/ -mindepth 1 -maxdepth 1 -type f -ctime -14

# command for getting the filename out of a full path
#basename /path/to/file.zip

# Creating an arrays of home directory files:

webdir="testdir/website/"
homedir="testdir/home/"

young_files=()
while IFS=  read -r -d $'\0'; do
    young_files+=("$REPLY")
done < <(find $homedir -mindepth 1 -maxdepth 1 -type f -ctime -14 -name "*.zip" -print0)

old_files=()
while IFS=  read -r -d $'\0'; do
    old_files+=("$REPLY")
done < <(find $webdir* -mindepth 1 -maxdepth 1 -type f -ctime +14 -name "*.zip" -print0)
#                                                            +14 this should say

# Looping over said array:

echo " --- Young files ---"
for file in "${young_files[@]}"; do
    filename=$(basename "$file")
    checksum=$(md5sum "$file" | awk '{print $1;}')
    filesite=$webdir$checksum
    
    if mkdir "$filesite" ; then
        echo "Made directory, and it worked!"
        
        webpage=$filesite/index.html
        cat html/1.part >> $webpage
        echo \<h2\>\<a href="$filename"\>$filename\</a\>\</h2\> >> $webpage
        cat html/2.part >> $webpage
        stat $file >> $webpage
        zipinfo -1 $file | tree --fromfile . >> $webpage
        cat html/3.part >> $webpage
        
        mv "$file" "$filesite/$filename"
        
    else
        echo "Already done."
    fi
    
    echo "file: $file"
	echo "filename: $filename"
    echo "checksum: $checksum"
    
done 


echo " --- Old files ---"
for file in "${old_files[@]}"; do
    filename=$(basename "$file")
    checksum=$(md5sum "$file" | awk '{print $1;}')
    
    echo "file: $file"
	echo "filename: $filename"
    echo "checksum: $checksum"
    
    rm -rf $(dirname "$file")
    
done