summary refs log tree commit diff
path: root/nixos/modules/system/etc/make-etc.sh
blob: 7cf68db9ddce546089777f47fc56b5a4a318765e (plain) (blame)
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
source $stdenv/setup

mkdir -p $out/etc

set -f
sources_=($sources)
targets_=($targets)
modes_=($modes)
set +f

for ((i = 0; i < ${#targets_[@]}; i++)); do
    source="${sources_[$i]}"
    target="${targets_[$i]}"

    if [[ "$source" =~ '*' ]]; then

        # If the source name contains '*', perform globbing.
        mkdir -p $out/etc/$target
        for fn in $source; do
            ln -s "$fn" $out/etc/$target/
        done

    else
        
        mkdir -p $out/etc/$(dirname $target)
        if ! [ -e $out/etc/$target ]; then
            ln -s $source $out/etc/$target
        else
            echo "duplicate entry $target -> $source"
            if test "$(readlink $out/etc/$target)" != "$source"; then
                echo "mismatched duplicate entry $(readlink $out/etc/$target) <-> $source"
                exit 1
            fi
        fi
        
        if test "${modes_[$i]}" != symlink; then
            echo "${modes_[$i]}" > $out/etc/$target.mode
        fi
        
    fi
done