-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpull_thoughts
More file actions
executable file
·65 lines (55 loc) · 1.81 KB
/
pull_thoughts
File metadata and controls
executable file
·65 lines (55 loc) · 1.81 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
#
#TODO update
#this is where the notes are stored on server
tdir="/srv/www/thesite/public/t/" #t for 'text' i guess
buffer=${HOME}"/.tmp/tbuff/" #buffer dir to temporarily store the downloaded files
PREPEND=false
DBG=0
if [[ $1 ]]; then DBG=1; fi
#store the notes in a temporary buffer
if [[ ! -d $buffer ]]; then mkdir -p $buffer; fi
filelist=`ssh hb "ls ${tdir}"`
if [[ $filelist == "" ]]; then
echo "no new notes from server. will check local buffer"
else
scp -r hb:${tdir}/* $buffer"/"
fi
if [[ $DBG ]]; then
echo "remote text files:"
echo $filelist
fi
if [[ -z `ls $buffer` ]]; then
echo "nothing in buffer. exiting."
exit 0
fi
for f in `ls $buffer`; do
if [[ $DBG ]]; then
echo "checking "${f}
fi
#check if a file of the same name already exists locally.
#if so, prepend new note to it. NOTE: change to append if more practical
if [ -e ~/doc/${f} ]; then
fog=~/doc/${f}
if [[ $PREPEND ]]; then
if [[ $DBG ]]; then echo "backing up "${fog}; fi
cp ${fog} ${fog}.prev
if [[ $DBG ]]; then echo "prepending new data"; fi
cat ${buffer}/${f} > ${fog}
echo "" >> ${fog}
cat ${fog}.prev >> ${fog}
rm ${fog}".prev"
else
if [[ $DBG ]]; then echo "appending new data"; fi
cat ${buffer}/${f} >> ${fog}
fi
else
cat ${buffer}/${f} > ~/doc/${f}
fi
rm ${buffer}/${f}
#ssh hb "echo '' >> ${f}.bak; cat ${fog} >> ${f}.bak; rm ${f}; touch ${f}; chmod a+w ${f}; sudo chown www-data:www-data ${f}"
done
#backup remote files
d=`date +%s`
ssh hb "cd ${tdir}/..; tar -czvf .t.bak/${d}.tar.gz ${tdir}/*; rm ${tdir}/*"
#TODO delete old backups
#ssh hb "if [[ $((`find ~/.t.bak/ -type f | wc -l`)) -gt 5 ]]; then fi"