-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.sh
131 lines (115 loc) · 4.01 KB
/
update.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash
echo "NODEJS Skreen Updater";
echo "--------------------"
cwd=$(pwd)
echo "CWD: $cwd"
echo "Identifying platform...";
platform='unknown'
unamestr=`uname`
if [[ "$unamestr" == 'Linux' ]]; then
platform='linux'
elif [[ "$unamestr" == 'Darwin' ]]; then
platform='mac'
fi
echo "Platform: $platform, unamestr $unamestr";
askIfDif="true"
while getopts :a option
do
case "$option" in
a)
echo "-a flag passed, will automatically delete all files found to be not matching. (won't ask)"; askIfDif="false";
;;
h)
echo "Help: pass -a to automatically update files without y/n for each one."; exit 0;
;;
esac
done
confirm() {
# call with a prompt string or use a default
read -r -p "${1:-Are you sure? [y/N]} " response
case "$response" in
[yY][eE][sS]|[yY])
return 0
;;
*)
return 1
;;
esac
}
update() {
sudo rm -R "$cwd/tempSKREEN" || echo "No Skreen directory found; not deleting"
echo "Downloading temporary Skreen directory...";
sudo git clone git://github.com/aaroexxt/Skreen.git tempSKREEN;
IFS=$'\n'; set -f #set internal field seperator to fix spaces in filenames
cd tempSKREEN;
path=""
if [ -d "$1" ]; then
path=$1;
else
path="$cwd/tempSKREEN"
fi
echo "base path: $path"
recursivesize $path
unset IFS; set +f
echo "Changing permissions on downloaded folder";
sudo chmod 777 -R $cwd;
sudo rm -R "$cwd/tempSKREEN";
}
function recursivesize() {
files="$(find -L "$1" -type f)";
if [[ "$files" == "" ]]; then
echo "No files";
return 0;
fi
file_count=$(echo "$files" | wc -l)
echo "Found $file_count files to potentially update"
echo "$files" | while read file; do
#echo "Github file path: $file";
sliceCWD=${file#$cwd}
removeTempDir=$(echo $sliceCWD | sed 's,^[^/]*/,,' | sed 's,^[^/]*/,,') #slice twice to get rid of trailing slash and then dir
rawFN="$cwd/$removeTempDir"
sizeTemporary=`wc -c < $file` #tem
sizeCurrent=`wc -c < $rawFN`
if [ "$sizeTemporary" -ne "$sizeCurrent" ]; then
ignoreSequence=".git"
if ! [[ $file =~ $ignoreSequence ]]; then #make sure files aren't github files
if [ "$sizeCurrent" = "" ]; then
echo "Found directory that client has deleted: $rawFN"
else
echo && echo && echo
echo "Github filesize: "$sizeTemporary", CurrentDir filesizesize: "$sizeCurrent
if [ "$askIfDif" = "true" ]; then
read -p "File $rawFN doesn't match github file. Would you like to replace this file? [y/N]" </dev/tty response
case "$response" in
[yY][eE][sS]|[yY])
echo "Replacing file"; sudo rm $rawFN; sudo cp $file $rawFN; #will delete original file, then copy new
;;
*)
echo "Won't replace file.";
;;
esac
else
echo "File $rawFN doesn't match; autoreplacing.";
sudo rm $rawFN;
sudo cp $file $rawFN
fi
fi
fi
fi;
done
}
echo "YOU ARE RUNNING THE UPDATE SCRIPT";
echo "This could potentially erase parts or all of the current Skreen directory, which will destroy changes that you have made.";
confirm && update; #what a fancy oneliner heh
#some kind of awesome glitch happens when I do this
#for filename in tempCarOS/*; do
# rawFN=$($filename | sed -e 's/\/.*\///g')
# echo $rawFN
# lastModTemp=$(stat -f%z tempCarOS/$filename)
# lastModCurrent=$(stat -f%z $filename)
# echo $lastMod
#done
echo "Done updating."
echo "Run 'sudo bash $cwd/start.sh' to start the sever";
exit;
#VNC STUFF BELOW