-
Notifications
You must be signed in to change notification settings - Fork 11
/
upload-CI.sh
112 lines (101 loc) · 3.06 KB
/
upload-CI.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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/bash
# This file is pure insanity.
# I apologize in advance if you're trying to do something with it.
# Get server epoch time into TIMEVAR
#TIMEVAR=$(ssh [email protected] 'date +%s')
TIMEVAR=$(ssh [email protected] 'date +%Y%m%d%H%M')
if [ $? -eq 0 ]
then
echo "TIMEVAR: $TIMEVAR"
else
echo "error code: $?"
echo "failed getting server time, exiting"
exit 1
fi
NEWDIR=pixls-$TIMEVAR
echo "NEWDIR: $NEWDIR"
# Get the current, active directory name
CURRDIR=$(ssh [email protected] 'cd ~/pixls-deploy/; find . -mindepth 1 -maxdepth 1 -type d -name pixls* -printf "%P\n"')
if [ $? -eq 0 ]
then
echo "CURRDIR: $CURRDIR"
else
echo "error code: $?"
echo "failed getting current directory, exiting"
exit 1
fi
# Hardlink copy current directory to new directory
# (this is the dir we will rsync against/into
ssh [email protected] "cd ~/pixls-deploy/; cp -la $CURRDIR $NEWDIR"
if [ $? -eq 0 ]
then
echo "cp -al successful"
else
echo "exit code: $?"
echo "cp -al failed! ... Continuing"
fi
# rsync into new directory, pixls-$TIMEVAR/
rsync -PSauve ssh --exclude='.DS_Store' build/ [email protected]:/home4/pixlsus/pixls-deploy/$NEWDIR/
if [ $? -eq 0 ]
then
echo "rsync successful."
else
echo "exit code: $?"
echo "rsync failed!"
# failed, so delete the directory
echo "cleaning up $NEWDIR"
ssh [email protected] "rm -r /home4/pixlsus/pixls-deploy/$NEWDIR"
if [ $? -eq 0 ]
then
echo "Removed ~/pixls-deploy/$NEWDIR"
else
echo "Uh oh. Check the directory, I might not have cleaned up"
fi
exit 1
fi
# create symlink inside new directory to ~/files
ssh [email protected] "ln -s ~/files ~/pixls-deploy/$NEWDIR/files"
if [ $? -eq 0 ]
then
echo "ln -s ~/files ~/pixls-deploy/$NEWDIR/files"
echo "Created symlink to ~/files"
else
echo "exit code: $?"
echo "ln -s for ~/files/ failed!"
echo "Check it manually! Continuing..."
fi
# create a temporary symlink to the new directory
ssh [email protected] "ln -s ~/pixls-deploy/$NEWDIR ~/public_html-tmp"
if [ $? -eq 0 ]
then
echo "ln -s successful"
echo "created ~/public_html-tmp -> ~/pixls-deploy/$NEWDIR"
else
echo "exit code: $?"
echo "ln -s failed!"
# failed, so delete the directory
echo "cleaning up (rm -r $NEWDIR)"
ssh [email protected] 'rm -r /home4/pixlsus/pixls-deploy/$NEWDIR'
if [ $? -eq 0 ]
then
echo "Removed ~/pixls-deploy/$NEWDIR"
else
echo "Uh oh. Check the directory, I might not have cleaned up"
fi
exit 1
fi
# Now move tmp symlink to actual public_html
ssh [email protected] "mv -Tf ~/public_html-tmp ~/public_html"
if [ $? -eq 0 ]
then
echo "mv -Tf ~/public_html-tmp ~/public_html successful"
else
echo "exit code: $?"
echo "Failed to mv -Tf ~/public_html-tmp ~/public_html!"
# failed, so handle it
echo "Check the symlinks and manually replace if needed"
exit 1
fi
# At the end, migrate and move old directories
ssh [email protected] rm -r "~/pixls-deploy/previous*"
ssh [email protected] mv "~/pixls-deploy/$CURRDIR" "~/pixls-deploy/${CURRDIR//pixls/previous}"