scripts / flightgear / mount.terrafs /
Newer Older
87 lines | 2.044kb
montage et démontage des scè...
Sébastien MARQUE authored on 2023-08-01
1
#!/bin/zsh
2

            
3
terrafs_d=${1:-$HOME/.fgfs/terrafs.d}
4

            
5
osm2city_dirs=(
6
        Buildings
7
        Details
8
        Pylons
9
        Roads
10
        Trees
11
    )
12

            
13
ws20_dirs=(
14
        Airports
15
        Models
16
        Objects
17
        Terrain
18
    )
19

            
montage des scènes plus adap...
Sébastien MARQUE authored on 2023-08-01
20
for k in ${(koM)parameters}; do
21
    if [[ $k =~ .+_dirs && ${(M)parameters[$k]} == array ]]; then
22
        sceneries+=(${k%_dirs})
23
        typeset -A ${k%_dirs}_urls
24
    fi
25
done
26

            
27
if test -r $0.conf; then
28
    source $0.conf
29
else
30
    echo pas de $0.conf trouvé
31
    exit 1
32
fi
33

            
34
for scenery in ${sceneries[@]}; do
35
    if ! eval "test \${#${scenery}_urls[@]} -gt 0"; then
36
        echo $scenery erreur
37
        exit 1
38
    fi
39
done
40

            
montage et démontage des scè...
Sébastien MARQUE authored on 2023-08-01
41
get_url () {
42
    eval "local hosts=(\${(k)${1}_urls[@]})"
43
    echo ${hosts[$(( $RANDOM % ${#hosts[@]} + 1 ))]}
44
}
45

            
46
remove_url () {
47
    eval "unset \"${1}_urls[$2]\""
48
}
49

            
50
get_largest () {
51
    eval "local _1=\${#${1}_urls[@]}"
52
    eval "local _2=\${#${2}_urls[@]}"
53
    if test $_1 -gt $_2; then
54
        echo largest=$1
55
        echo smallest=$2
56
    else
montage des scènes plus adap...
Sébastien MARQUE authored on 2023-08-01
57
        echo largest=$2
58
        echo smallest=$1
montage et démontage des scè...
Sébastien MARQUE authored on 2023-08-01
59
    fi
60
}
61

            
62
mount_dirs () {
63
    local dir=
64
    eval "local oserver=https://\${${1}_url}/\${${1}_urls[\${${1}_url}]}"
65
    eval "local dirs=(\${${1}_dirs[@]})"
66
    for dir in ${dirs[@]}; do
67
        mkdir -p $HOME/.fgfs/terrafs.d/$dir
68
        printf "- %-10s " $dir && $HOME/.fgfs/terrafs -oserver=$oserver/$dir $terrafs_d/$dir && echo "ok" || echo "ERROR"
69
    done
70
}
71

            
72
if test $(grep -Ec "^terrafs +$terrafs_d" /proc/mounts) -ne $(( ${#ws20_dirs[@]} + ${#osm2city_dirs[@]} )); then
montage des scènes plus adap...
Sébastien MARQUE authored on 2023-08-01
73
    eval $(get_largest ${sceneries[@]})
montage et démontage des scè...
Sébastien MARQUE authored on 2023-08-01
74
    eval "${largest}_url=$(get_url $largest)"
75
    eval "remove_url $smallest \$${largest}_url"
76
    eval "${smallest}_url=$(get_url $smallest)"
77

            
montage des scènes plus adap...
Sébastien MARQUE authored on 2023-08-01
78
    for m in ${sceneries[@]}; do
montage et démontage des scè...
Sébastien MARQUE authored on 2023-08-01
79
        eval "printf 'montage %s depuis %s\n' ${(U)m} \$${m}_url"
80
        mount_dirs $m
81
    done
82
else
83
    echo "démontage $terrafs_d"
84
    for dir in ${osm2city_dirs[@]} ${ws20_dirs[@]}; do
85
        printf "- %-10s " $dir && fusermount -u $terrafs_d/$dir && echo "ok" || echo "ERROR"
86
    done
87
fi