-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-website.sh
More file actions
executable file
·90 lines (71 loc) · 1.8 KB
/
Copy pathupdate-website.sh
File metadata and controls
executable file
·90 lines (71 loc) · 1.8 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
############################################################
# Do not use the script without understanding how it works #
############################################################
WEBSITE="$HOME/Website/"
ARCHIVE="$HOME/Documents/website-archive/"
CHANGELOG="$ARCHIVE/CHANGELOG"
ORIGINALDIR=$PWD
yes-or-no () {
read -r -p "$1 [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]
then
echo "Yes"
return 0
fi
return 2
}
listarchives () {
for line in $(cat $CHANGELOG | cut -f 1)
do
archives+=("$line")
done
echo "${#archives[@]}"
}
listarchives > /dev/null # Initiates the archives array
lastarchive () {
LOOP=0
for i in ${archives[*]}
do
if test $(echo "${archives[$LOOP]}" | grep hugo)
then
last=$i
fi
LOOP=$[$LOOP + 1]
done
echo "$last"
}
archivedate() {
echo $1 | cut -d "-" -f 2-4
}
archivever () {
echo "$1" | cut -d "-" -f 5 | cut -d "." -f 1 | cut -c 2-
}
ARCHIVESIZE=$(listarchives)
LASTARCHIVE=$(lastarchive)
if test "$(date -I)" = $(archivedate $LASTARCHIVE)
then
CURRENTVER=$[$(archivever $LASTARCHIVE) + 1]
fi
CURRENTARCHIVE=hugo-$(date -I)-v$CURRENTVER.tar.gz
cd $WEBSITE
rm -ri *.tar.gz
rm -rI public
read -r -p "Change message: " CHANGE
if test $(yes-or-no "Git commit and push changes ?")
then
git add .
git commit -m "$CHANGE"
git push
fi
hugo > /dev/null && echo "New website generated"
tar -czf $CURRENTARCHIVE public && echo "Archive $CURRENTARCHIVE created"
cp -a $CURRENTARCHIVE $ARCHIVE &&
echo -e "$CURRENTARCHIVE\t$CHANGE\t$(date)" >> $CHANGELOG &&
echo "$CURRENTARCHIVE archived to $ARCHIVE"
if test $(yes-or-no "Send archive to root@moowool.info:/var/www ?")
then
scp $CURRENTARCHIVE root@moowool.info:/var/www &&
echo "Archive transferred to website"
fi
cd $ORIGINALDIR