Showing 1 changed files with 78 additions and 0 deletions
+78
flightgear/mount.terrafs
... ...
@@ -0,0 +1,78 @@
1
+#!/bin/zsh
2
+
3
+terrafs_d=${1:-$HOME/.fgfs/terrafs.d}
4
+
5
+typeset -A osm2city_urls=(
6
+        cdn.merspieler.tk       o2c
7
+        ukmirror.flightgear.org osm2city
8
+    )
9
+
10
+typeset -A ws20_urls=(
11
+        cdn.merspieler.tk          ts
12
+        ukmirror.flightgear.org    fgscenery
13
+        flightgear.sourceforge.net scenery
14
+    )
15
+
16
+osm2city_dirs=(
17
+        Buildings
18
+        Details
19
+        Pylons
20
+        Roads
21
+        Trees
22
+    )
23
+
24
+ws20_dirs=(
25
+        Airports
26
+        Models
27
+        Objects
28
+        Terrain
29
+    )
30
+
31
+get_url () {
32
+    eval "local hosts=(\${(k)${1}_urls[@]})"
33
+    echo ${hosts[$(( $RANDOM % ${#hosts[@]} + 1 ))]}
34
+}
35
+
36
+remove_url () {
37
+    eval "unset \"${1}_urls[$2]\""
38
+}
39
+
40
+get_largest () {
41
+    eval "local _1=\${#${1}_urls[@]}"
42
+    eval "local _2=\${#${2}_urls[@]}"
43
+    if test $_1 -gt $_2; then
44
+        echo largest=$1
45
+        echo smallest=$2
46
+    else
47
+        echo largest=$1
48
+        echo smallest=$2
49
+    fi
50
+}
51
+
52
+mount_dirs () {
53
+    local dir=
54
+    eval "local oserver=https://\${${1}_url}/\${${1}_urls[\${${1}_url}]}"
55
+    eval "local dirs=(\${${1}_dirs[@]})"
56
+    for dir in ${dirs[@]}; do
57
+        mkdir -p $HOME/.fgfs/terrafs.d/$dir
58
+        printf "- %-10s " $dir && $HOME/.fgfs/terrafs -oserver=$oserver/$dir $terrafs_d/$dir && echo "ok" || echo "ERROR"
59
+    done
60
+}
61
+
62
+eval $(get_largest ws20 osm2city)
63
+
64
+if test $(grep -Ec "^terrafs +$terrafs_d" /proc/mounts) -ne $(( ${#ws20_dirs[@]} + ${#osm2city_dirs[@]} )); then
65
+    eval "${largest}_url=$(get_url $largest)"
66
+    eval "remove_url $smallest \$${largest}_url"
67
+    eval "${smallest}_url=$(get_url $smallest)"
68
+
69
+    for m in ws20 osm2city; do
70
+        eval "printf 'montage %s depuis %s\n' ${(U)m} \$${m}_url"
71
+        mount_dirs $m
72
+    done
73
+else
74
+    echo "démontage $terrafs_d"
75
+    for dir in ${osm2city_dirs[@]} ${ws20_dirs[@]}; do
76
+        printf "- %-10s " $dir && fusermount -u $terrafs_d/$dir && echo "ok" || echo "ERROR"
77
+    done
78
+fi