sh digitalocean-synchronize.sh

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh digitalocean-synchronize.sh相关的知识,希望对你有一定的参考价值。

process_interface() {
    local url=$1
    local attrs=$2
    local mac=$(curl -Ssf ${url}mac)
    local type=$(curl -Ssf ${url}type)
    local interface=
    local cand path
    for cand in $(ls /sys/class/net); do
        path=/sys/class/net/${cand}/address
        if [ -e ${path} ] && [ "$(<${path})" = "${mac}" ]; then
            interface=${cand}
            break
        fi
    done
    [ -n "${interface}" ] || return 0
    mkdir -p /run/systemd/network
    {
        cat <<-EOF
            # Generated by digitalocean-synchronize
            [Match]
            Name=${interface}
            [Network]
        EOF
        if [[ " ${attrs} " =~ " ipv4/ " ]]; then
            local address=$(curl -sf ${url}ipv4/address)
            local prefix=$(netmask_to_prefix $(curl -sf ${url}ipv4/netmask))
            echo "Address=${address}/${prefix}"
            if [ "${type}" != "private" ]; then
                echo "Gateway=$(curl -sf ${url}ipv4/gateway)"

                if [[ ${interface} = "eth0" ]]; then
                    echo "Tunnel=he-ipv6"
                fi
            fi
            log "Added IPv4 address ${address}/${prefix} on ${interface}."
        fi
        if [[ " ${attrs} " =~ " ipv6/ " ]]; then
            local address=$(curl -sf ${url}ipv6/address)
            local prefix=$(curl -sf ${url}ipv6/cidr)
            echo "Address=${address}/${prefix}"
            if [ "${type}" != "private" ]; then
                echo "Gateway=$(curl -sf ${url}ipv6/gateway)"
            fi
            log "Added IPv6 address ${address}/${prefix} on ${interface}."
        fi
    } > /run/systemd/network/dosync-${interface}.network
}

以上是关于sh digitalocean-synchronize.sh的主要内容,如果未能解决你的问题,请参考以下文章

sh sh_template.sh

sh sh.sh

Linux下面如何运行 SH文件

配置告警系统主脚本main.sh mon.sh load.sh 502.sh disk.sh

shell 脚本各种执行方式(source ./*.sh, . ./*.sh, ./*.sh)的区别

linux下sh文件的运行