Socialify

Folder ..

Viewing frodo.sh
60 lines (53 loc) • 1.6 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
#!/bin/bash
#
#    "How do you pick up the threads of an old life?
#     How do you go on, when in your heart you begin
#       to understand... there is no going back?
#      There are some things that time cannot mend.
#    Some hurts that go too deep, that have taken hold."
#             Frodo, The Return of the King
#
#
# This script shall repair the patches for the little
# broken programs using the old patches in this directory
# first, to heal them and then create new and better
# patches, with Gollum's help.
#
set -e

# We check ourselves before we wreck ourselves.
if [ ! -f patches/frodo.sh ]
then
    echo "But I must be run from the project root directory."
    exit 1
fi

# Create directory of answers if it doesn't already exist.
mkdir -p answers

# Cycle through all the little broken Zig applications.
i=0
for broken in exercises/*.zig
do
	((i=i+1))

    # Remove the dir and extension, rendering the True Name.
    true_name=$(basename "$broken" .zig)
    patch_name="patches/patches/$true_name.patch"
    healed_name="answers/$true_name.zig"
    cp "$broken" "$healed_name"
	# echo "$patch_name"

    if [ -f "$patch_name" ]
    then
        # Apply the bandages to the wounds, grow new limbs, let
        # new life spring into the broken bodies of the fallen.
        echo Healing "$true_name"...
		patch -i "$patch_name" "$healed_name"

		# Create new prescriptions...
		echo Repairing "$patch_name"...
		if [ "$true_name.patch" = "999_the_end.patch" ]
		then
			i=999
		fi
		# with gollum's help!
		./patches/gollum.sh $i
    else
        echo Cannot repair "$true_name". No patch found.
    fi
done