RUNME.sh 7.51 KB
Newer Older
kimon-satan's avatar
school  
kimon-satan committed
1 2
#!/bin/bash

Simon Katan's avatar
Simon Katan committed
3 4 5
checksums=( "01112" "23824" "40805" "xxxxx" "65646" )
words=("cod" "inventor" "journey" "xxxxx" "forest")
mark=0
kimon-satan's avatar
kimon-satan committed
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
command="python"

function loadPython {

	curl -s -o baseutils.py http://igor.gold.ac.uk/~skata001/underland/pt2/baseutils > /dev/null
	curl -s -o levelCodes http://igor.gold.ac.uk/~skata001/underland/pt2/levelCodes > /dev/null

	if hash python 2>/dev/null; then
		echo "python found">/dev/null
	else
		var="#!/usr/bin/python2"
		sed -i '1s|.*|'$var'|' baseutils.py
		command="python2"
	fi

	chmod 777 baseutils.py
}

function checkScript {

	filename=$1

	loadPython

	mark=$($command baseutils.py $filename "mark")
	username=$($command baseutils.py $filename "getusername")

	#echo $mark

}

function checkWord {


	isMemoryValid=false
	isPrevMemoryValid=false
	local crc="00000"

	old_IFS=$IFS
	IFS=$'\n'
	lines=($(cat memories.txt)) # array
	IFS=$old_IFS

	for p in "${lines[@]}"; do
		crc=$($command baseutils.py "x" "addcrc" ${p:0:4} $crc)
		#echo $p
		#echo $crc
	done

	#echo $crc

	local prevIndex=$(( $1 -  1 ))

	if [ "$crc" = "${checksums[$1]}" ] ; then
		isMemoryValid=true
Simon Katan's avatar
Simon Katan committed
61
		local level=$((200 + $1))
kimon-satan's avatar
kimon-satan committed
62 63 64 65 66 67 68 69 70 71
		$command baseutils.py $filename "score" $level ${words[$1]}
	elif [ "$crc" = "${checksums[$prevIndex]}" ]; then
		isPrevMemoryValid=true
	fi

	rm baseutils.py
	rm levelCodes

}

kimon-satan's avatar
school  
kimon-satan committed
72 73 74 75
function pause {
	local count=0
	while [ $count -lt $1 ]; do
		echo ...
Simon Katan's avatar
Simon Katan committed
76 77
		sleep 2
		let count=count+1
kimon-satan's avatar
school  
kimon-satan committed
78 79 80
	done
}

Simon Katan's avatar
Simon Katan committed
81
function task1 {
kimon-satan's avatar
kimon-satan committed
82
	clear
Simon Katan's avatar
Simon Katan committed
83
	pause 1
kimon-satan's avatar
kimon-satan committed
84 85
	echo "Hi"
	pause 1
Simon Katan's avatar
Simon Katan committed
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
	echo "It’s so nice of canary.bird to have brought you here. Let me introduce myself. "
	pause 1
	echo "I am the famous mock turtle."
	pause 1
	echo "What do you mean you’ve never heard of a mock turtle !"
	pause 1
	echo "I’m the thing that Mock Turtle Soup is made from."
	pause 1
	clear
	echo "I’m very sad. Can you help me ?"
	pause 1
	echo "Great I knew you would."
	pause 1
	clear
	echo "I am very old and I used to have so many memories"
	pause 1
	echo "but now they have all slipped away."
	pause 1
	echo "Check the memories.txt in this directory and you will see that it’s totally blank"
	pause 1
	echo "It wasn’t always this way."
	pause 1
	clear
	echo "My mind used to be full of rich and delicious memories."
	pause 1
	echo "Now I need you to find them"
	pause 1
	echo "I hear that you have just learnt how to use a strange tool called git which can help you recover things when you’ve lost them."
	pause 1
	echo "Let’s start by recovering my very first memory."
kimon-satan's avatar
kimon-satan committed
116
	pause 1
Simon Katan's avatar
Simon Katan committed
117
	echo "Use 'git log --oneline' to find out its name and then cut and paste this into the first line of my memories."
kimon-satan's avatar
kimon-satan committed
118
	pause 1
Simon Katan's avatar
Simon Katan committed
119
	echo "Be sure to use a proper code editor like atom or sublime. Don't use textedit or notepad !"
kimon-satan's avatar
kimon-satan committed
120
	pause 1
Simon Katan's avatar
Simon Katan committed
121
	echo "Once you have done this RUNME again"
kimon-satan's avatar
kimon-satan committed
122
	pause 1
Simon Katan's avatar
Simon Katan committed
123
}
kimon-satan's avatar
kimon-satan committed
124

Simon Katan's avatar
Simon Katan committed
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
function task2 {
	clear
	echo "Ah yes school that was my first memory."
	pause 1
	echo "I went to school in the sea."
	pause 1
	echo "Most of my classmates were fish."
	pause 1
	echo "Tuna mostly but also some cod"
	pause 1
	echo "Nobody understood me there."
	pause 1
	echo "It was a sad and lonely time."
	pause 1
	echo "Perhaps you can help me find a happier memory ?"
	pause 1
	clear
	echo "I think my second year of school was a little happier"
	pause 1
	echo "Find the commit using 'git log --oneline' and travel back in time by using 'git checkout' "
	pause 1
	pause 1
	echo "When you go back in time my memories will be different"
	pause 1
	echo "Don't be alarmed. This is totally natural."
	pause 1
	echo "However, make sure you use git 'commit -am' to store these memories first or they will be lost again."
	pause 1
	echo "Once you have travelled back in time, RUNME and I will tell you my memories from that time."
	pause 1
	echo "Return to this time (the master branch) with the happy memory and add it to a new line in memories.txt"
kimon-satan's avatar
kimon-satan committed
156 157 158
}


Simon Katan's avatar
Simon Katan committed
159
function task3 {
kimon-satan's avatar
kimon-satan committed
160
	clear
Simon Katan's avatar
Simon Katan committed
161
	echo "Ah Tortoise yes I remember her."
kimon-satan's avatar
kimon-satan committed
162
	pause 1
Simon Katan's avatar
Simon Katan committed
163
	echo "Thankyou I feel much better about my school days now."
kimon-satan's avatar
kimon-satan committed
164
	pause 1
Simon Katan's avatar
Simon Katan committed
165
	echo "Ah I remember so much more now"
kimon-satan's avatar
kimon-satan committed
166
	pause 1
Simon Katan's avatar
Simon Katan committed
167
	echo "After I left school I became an inventor"
kimon-satan's avatar
kimon-satan committed
168
	pause 1
Simon Katan's avatar
Simon Katan committed
169 170 171 172 173 174
	echo "I would have been a great success but for one problem"
	pause 1
	echo "With each new invention I forgot the last"
	pause 3
	clear
	echo "Use 'git tag -l' to view all the tags for my inventions"
kimon-satan's avatar
kimon-satan committed
175
	pause 1
Simon Katan's avatar
Simon Katan committed
176
	echo "Each tagged commit has an invention in it in a file called inventions.txt"
kimon-satan's avatar
kimon-satan committed
177
	pause 1
Simon Katan's avatar
Simon Katan committed
178
	echo "Now use the form 'git checkout tagName -- inventions.txt' to bring each invention to the present"
kimon-satan's avatar
kimon-satan committed
179
	pause 1
Simon Katan's avatar
Simon Katan committed
180 181 182 183 184 185 186
	echo "Notice that each inventions.txt replaces the old inventions.txt"
	pause 1
	echo "Luckily you are here so that you can help me to not forget them"
	pause 1
	echo "Each time open inventions.txt and cut and paste the invention to a new line of memories.txt"
	pause 1
	echo "When you have found all of my inventions RUNME again"
kimon-satan's avatar
kimon-satan committed
187 188
}

Simon Katan's avatar
Simon Katan committed
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
function task4 {
	clear
	echo "Everything is becoming clearer to me now"
	pause 1
	echo "Something is coming out the fog of my memory"
	pause 1
	echo "I seem to remember something about a long journey"
	pause 1
	echo "Use 'git branch -r' to find a remote branch for this"
	pause 1
	echo "Then use 'git checkout' to explore the branch and RUNME"
	pause 1
	echo "When you go back in time, all of the current memories will disappear"
	pause 1
	echo "Don't be alarmed. This is totally natural as they won't have happened yet."
	pause 1
	echo "However you must commit the current memories here first using 'git commit -am'"
	pause 1
	echo "I wouldn't want to lose those wonderful memories again."
}
kimon-satan's avatar
kimon-satan committed
209

Simon Katan's avatar
Simon Katan committed
210
function task5 {
kimon-satan's avatar
kimon-satan committed
211
	clear
Simon Katan's avatar
Simon Katan committed
212 213 214 215 216
	echo "Thankyou so much."
	pause 1
	echo "I can remember everything now !"
	pause 1
	echo "I've just remembered something very important that Rabbit told me"
kimon-satan's avatar
kimon-satan committed
217
	pause 1
Simon Katan's avatar
Simon Katan committed
218
	echo "Your name is $username right ? "
kimon-satan's avatar
kimon-satan committed
219
	pause 1
Simon Katan's avatar
Simon Katan committed
220
	echo "Well then you need to go see Caterpillar in the forest"
kimon-satan's avatar
kimon-satan committed
221
	pause 1
Simon Katan's avatar
Simon Katan committed
222
	echo "You'll find him by the magic toadstool"
kimon-satan's avatar
kimon-satan committed
223
	pause 1
Simon Katan's avatar
Simon Katan committed
224
	echo "http://gitlab.doc.gold.ac.uk/underland/magicToadstool.git"
kimon-satan's avatar
kimon-satan committed
225
	pause 1
Simon Katan's avatar
Simon Katan committed
226
	echo "Don't forget to keep you score file safe (you know the one thats starts with 'aiw_'). "
kimon-satan's avatar
kimon-satan committed
227
	pause 1
Simon Katan's avatar
Simon Katan committed
228
	echo "Maybe you could store it in a repo of your own ?"
kimon-satan's avatar
kimon-satan committed
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
}

function badMemory {
	clear
	echo "It looks like something is wrong in your memories"
	pause 1
	echo "Perhaps you tried to take a short cut ?"
	pause 1
	echo "Remember that there are no short cuts in underland"
	pause 1
	echo "Remove any extra memories that you just added and try again"
}

filename=$1

if [ ${#filename} = 0 ] ;then
	pause 1
	echo "To run me you must pass a valid path to your score file as an argument."
	pause 1
	echo "For example ~/Desktop/aiw_skata001"
	pause 1
	echo "Have another go".
	exit
elif [ ! -f $filename ] ;then
	pause 1
	echo "The scorefile cannot be found in that location"
	pause 1
	echo "Have another go".
	exit
else
	checkScript $1
Simon Katan's avatar
Simon Katan committed
260
	if [ $mark -eq 1 ]; then
kimon-satan's avatar
kimon-satan committed
261
		checkWord 0
Simon Katan's avatar
Simon Katan committed
262 263 264 265 266 267 268
		if [ "$isMemoryValid" = true ]; then
			task2
		else
			task1
			#echo "fail"
		fi
	elif [ $mark -eq 4 ]; then
kimon-satan's avatar
kimon-satan committed
269
		checkWord 1
Simon Katan's avatar
Simon Katan committed
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
		if [ "$isMemoryValid" = true ]; then
			task3
		elif [ "$isPrevMemoryValid" = true ]; then
			task2
		else
			badMemory
		fi
	elif [ $mark -eq 6 ]; then
		checkWord 2

		if [ "$isMemoryValid" = true ]; then
			task4
		elif [ "$isPrevMemoryValid" = true ]; then
			task3
		else
			badMemory
		fi
	elif [ $mark -eq 8 ]; then
		task4
		rm baseutils.py
		rm levelCodes
	elif [ $mark -eq 10 ]; then
		checkWord 4
		if [ "$isMemoryValid" = true ]; then
			task5
		else
			pause 1
			echo "Something is wrong with your memories."
			pause 1
			echo "Have you resolved your conflicts ?"
			pause 1
		fi
	elif [ $mark -eq 11 ]; then
		task5
		rm baseutils.py
		rm levelCodes
	else
		badMemory
		rm baseutils.py
		rm levelCodes
	fi
kimon-satan's avatar
kimon-satan committed
311
fi