#!/bin/zsh terrafs_d=${1:-$HOME/.fgfs/terrafs.d} typeset -A osm2city_urls=( cdn.merspieler.tk o2c ukmirror.flightgear.org osm2city ) typeset -A ws20_urls=( cdn.merspieler.tk ts ukmirror.flightgear.org fgscenery flightgear.sourceforge.net scenery ) osm2city_dirs=( Buildings Details Pylons Roads Trees ) ws20_dirs=( Airports Models Objects Terrain ) get_url () { eval "local hosts=(\${(k)${1}_urls[@]})" echo ${hosts[$(( $RANDOM % ${#hosts[@]} + 1 ))]} } remove_url () { eval "unset \"${1}_urls[$2]\"" } get_largest () { eval "local _1=\${#${1}_urls[@]}" eval "local _2=\${#${2}_urls[@]}" if test $_1 -gt $_2; then echo largest=$1 echo smallest=$2 else echo largest=$1 echo smallest=$2 fi } mount_dirs () { local dir= eval "local oserver=https://\${${1}_url}/\${${1}_urls[\${${1}_url}]}" eval "local dirs=(\${${1}_dirs[@]})" for dir in ${dirs[@]}; do mkdir -p $HOME/.fgfs/terrafs.d/$dir printf "- %-10s " $dir && $HOME/.fgfs/terrafs -oserver=$oserver/$dir $terrafs_d/$dir && echo "ok" || echo "ERROR" done } eval $(get_largest ws20 osm2city) if test $(grep -Ec "^terrafs +$terrafs_d" /proc/mounts) -ne $(( ${#ws20_dirs[@]} + ${#osm2city_dirs[@]} )); then eval "${largest}_url=$(get_url $largest)" eval "remove_url $smallest \$${largest}_url" eval "${smallest}_url=$(get_url $smallest)" for m in ws20 osm2city; do eval "printf 'montage %s depuis %s\n' ${(U)m} \$${m}_url" mount_dirs $m done else echo "démontage $terrafs_d" for dir in ${osm2city_dirs[@]} ${ws20_dirs[@]}; do printf "- %-10s " $dir && fusermount -u $terrafs_d/$dir && echo "ok" || echo "ERROR" done fi