summaryrefslogtreecommitdiffstats
path: root/docker/assemble_blocks.sh
blob: 852064de28c26a3dd457bf49fa12e03d7287961d (plain)
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
#!/bin/bash

blocks_dir=blocks
docker_dir=docker
template_dir=templates

docker_file=Dockerfile

gogs_config_file=conf.tmp
gogs_config=config
gogs_init_file=$docker_dir/init_gogs.sh

fig_file=fig.yml
fig_config=fig

gogs_init_template=$template_dir/init_gogs.sh.tpl

if [ "$#" == 0 ]; then
    blocks=`ls $blocks_dir`
    if [ -z "$blocks" ]; then
        echo "No Blocks available in $blocks_dir"
    else
        echo "Available Blocks:"
        for block in $blocks; do
            echo "    $block"
        done
    fi
    exit 0
fi

for file in $gogs_config_file $fig_file; do
    if [ -e $file ]; then
        echo "Deleting $file"
        rm $file
    fi
done

for dir in $@; do
    current_dir=$blocks_dir/$dir
    if [ ! -d "$current_dir" ]; then
        echo "$current_dir is not a directory"
        exit 1
    fi

    if [ -e $current_dir/$docker_file ]; then
        echo "Copying $current_dir/$docker_file to $docker_dir/$docker_file"
        cp $current_dir/$docker_file $docker_dir/$docker_file
    fi

    if [ -e $current_dir/$gogs_config ]; then
        echo "Adding $current_dir/$gogs_config to $gogs_config_file"
        cat $current_dir/$gogs_config >> $gogs_config_file
        echo "" >> $gogs_config_file
    fi

    if [ -e $current_dir/$fig_config ]; then
        echo "Adding $current_dir/$fig_config to $fig_file"
        cat $current_dir/fig >> $fig_file
        echo "" >> $fig_file
    fi
done

echo "Creating $gogs_init_file"
sed "/{{ CONFIG }}/{
r $gogs_config_file
d
}" $gogs_init_template > $gogs_init_file

if [ -e $gogs_config_file ]; then
    echo "Removing temporary GoGS config"
    rm $gogs_config_file
fi