[WeVO 11AC NAS] UCI를 사용한 OpenWRT 일괄 설정

#!/bin/sh
######################################################################
#
# OpenWRT 설정 스크립트
#
######################################################################
TRUST_HOST="211.196.252.73"

function check_board_name() {
  echo "###########################################################"
  echo "#"
  echo "# Check board name"
  echo "#"
  echo "###########################################################"

  grep "11AC" /etc/os-release > /dev/null
  if [ $? -eq 0 ]
  then
    echo "This board is WeVO 11AC NAS Router"
    export DEVICE_NAME="WeVO 11AC NAS Router"
    export DEVICE_HOSTNAME="11ac_nas"
    return
  else
    echo "This board is netis WF2881 Router"
    export DEVICE_NAME="netis WF2881 Router"
    export DEVICE_HOSTNAME="wf2881"
    return
  fi
}

func_set_vsftpd() {
  echo "###########################################################"
  echo "#"
  echo "# useradd openwrt"
  echo "#"
  echo "###########################################################"
  echo ""
  echo "chroot_local_user=YES" >> /etc/vsftpd.conf
  echo "allow_writeable_chroot=YES" >> /etc/vsftpd.conf
  echo "openwrt:x:500:65534:openwrt:/mnt:/bin/false" >> /etc/passwd
  echo "openwrt:x:0:0:99999:7:::" >> /etc/shadow
  chown -R openwrt:nogroup /mnt
}

func_set_system() {
  echo "###########################################################"
  echo "#"
  echo "# set system"
  echo "#"
  echo "###########################################################"
  echo ""
  uci set system.@system[0].timezone='KST-9'
  uci set system.@system[0].hostname="${DEVICE_HOSTNAME}"

  uci -q delete system.ntp.server
  uci add_list system.ntp.server='3.kr.pool.ntp.org'
  uci add_list system.ntp.server='3.asia.pool.ntp.org'
  uci add_list system.ntp.server='1.asia.pool.ntp.org'
  uci commit system
}

func_set_ntpclient() {
  uci delete ntpclient.@ntpserver[0]
  uci delete ntpclient.@ntpserver[0]
  uci delete ntpclient.@ntpserver[0]
  uci delete ntpclient.@ntpserver[0]
  uci add ntpclient ntpserver
  uci set ntpclient.@ntpserver[-1].port='123'
  uci set ntpclient.@ntpserver[-1].hostname='3.kr.pool.ntp.org'
  uci add ntpclient ntpserver
  uci set ntpclient.@ntpserver[-1].port='123'
  uci set ntpclient.@ntpserver[-1].hostname='3.asia.pool.ntp.org'
  uci add ntpclient ntpserver
  uci set ntpclient.@ntpserver[-1].port='123'
  uci set ntpclient.@ntpserver[-1].hostname='1.asia.pool.ntp.org'
  uci commit ntpclient
}

func_make_mount_script() {
  echo "###########################################################"
  echo "#"
  echo "# /etc/hotplug.d/block/10-mount"
  echo "#"
  echo "###########################################################"
  echo ""
  echo "#!/bin/sh" > /etc/hotplug.d/block/10-mount
  echo "" >> /etc/hotplug.d/block/10-mount
  echo "# Copyright (C) 2020 OpenWrt.org" >> /etc/hotplug.d/block/10-mount
  echo "" >> /etc/hotplug.d/block/10-mount
  echo "# more apps installed, need more time to load kernel modules!" >> /etc/hotplug.d/block/10-mount
  echo "sleep 5" >> /etc/hotplug.d/block/10-mount
  echo "blkdev=\`dirname \$DEVPATH\`" >> /etc/hotplug.d/block/10-mount
  echo "if [ \`basename \$blkdev\` != \"block\" ]; then" >> /etc/hotplug.d/block/10-mount
  echo "  device=\`basename \$DEVPATH\`" >> /etc/hotplug.d/block/10-mount
  echo "  case \"\$ACTION\" in" >> /etc/hotplug.d/block/10-mount
  echo "    add)" >> /etc/hotplug.d/block/10-mount
  echo "      mkdir -p /mnt" >> /etc/hotplug.d/block/10-mount
  echo "      # vfat & ntfs-3g check" >> /etc/hotplug.d/block/10-mount
  echo "      if [ \`which fdisk\` ]; then" >> /etc/hotplug.d/block/10-mount
  echo "        isntfs=\`fdisk -l | grep \$device | grep NTFS\`" >> /etc/hotplug.d/block/10-mount
  echo "        isvfat=\`fdisk -l | grep \$device | grep FAT\`" >> /etc/hotplug.d/block/10-mount
  echo "        isfuse=\`lsmod | grep fuse\`" >> /etc/hotplug.d/block/10-mount
  echo "        isntfs3g=\`which ntfs-3g\`" >> /etc/hotplug.d/block/10-mount
  echo "      else" >> /etc/hotplug.d/block/10-mount
  echo "        isntfs=\"\"" >> /etc/hotplug.d/block/10-mount
  echo "        isvfat=\"\"" >> /etc/hotplug.d/block/10-mount
  echo "      fi" >> /etc/hotplug.d/block/10-mount
  echo "" >> /etc/hotplug.d/block/10-mount
  echo "      # mount with ntfs-3g if possible, else with default mount" >> /etc/hotplug.d/block/10-mount
  echo "      if [ \"\$isntfs\" -a \"\$isfuse\" -a \"\$isntfs3g\" ]; then" >> /etc/hotplug.d/block/10-mount
  echo "        ntfs-3g -o rw,sync,uid=500,gid=65534 /dev/\$device /mnt" >> /etc/hotplug.d/block/10-mount
  echo "      elif [ \"\$isvfat\" ]; then" >> /etc/hotplug.d/block/10-mount
  echo "        mount -o rw,uid=500,gid=65534,codepage=949,iocharset=utf8 /dev/\$device /mnt" >> /etc/hotplug.d/block/10-mount
  echo "      else" >> /etc/hotplug.d/block/10-mount
  echo "        mount -o rw,sync,uid=500,gid=65534 /dev/\$device /mnt" >> /etc/hotplug.d/block/10-mount
  echo "      fi" >> /etc/hotplug.d/block/10-mount
  echo "      ;;" >> /etc/hotplug.d/block/10-mount
  echo "    remove)" >> /etc/hotplug.d/block/10-mount
  echo "      umount -l /dev/\$device" >> /etc/hotplug.d/block/10-mount
  echo "      ;;" >> /etc/hotplug.d/block/10-mount
  echo "  esac" >> /etc/hotplug.d/block/10-mount
  echo "fi" >> /etc/hotplug.d/block/10-mount
  chmod 755 /etc/hotplug.d/block/10-mount
}

func_echo_reboot_now() {
  echo ""
  echo "###########################################################"
  echo "#"
  echo "# PLEASE, REBOOT NOW"
  echo "#"
  echo "###########################################################"
  echo ""
}

func_set_ddns() {
  echo "###########################################################"
  echo "#"
  echo "# set_ddns"
  echo "#"
  echo "###########################################################"
  echo ""
  uci set ddns.global=ddns
  uci set ddns.global.ddns_dateformat='%F %R'
  uci set ddns.global.ddns_loglines='250'
  uci set ddns.global.upd_privateip='0'
  uci set ddns.duckdns=service
  uci set ddns.duckdns.enabled='1'
  uci set ddns.duckdns.password='f63a82fe-e69b-4df7-a0fa-bda0d58e6714'
  uci set ddns.duckdns.ip_source='network'
  uci set ddns.duckdns.ip_network='wan'
  uci set ddns.duckdns.lookup_host='hasu0707.duckdns.org'
  uci set ddns.duckdns.service_name='duckdns.org'
  uci set ddns.duckdns.domain='hasu0707.duckdns.org'
  uci commit ddns

  uci delete ddns.myddns_ipv4
  uci delete ddns.myddns_ipv6
  uci commit ddns
}

func_set_dhcp() {
  echo "###########################################################"
  echo "#"
  echo "# set dhcp"
  echo "#"
  echo "###########################################################"
  echo ""
  uci set dhcp.lan.start='101'
  uci set dhcp.lan.limit='98'
  #uci set dhcp.lan.dhcp_option='6,8.8.8.8,8.8.4.4'

  uci add dhcp host
  uci set dhcp.@host[-1].name="ODROID-HC2"
  uci set dhcp.@host[-1].mac="00:1E:06:36:F6:02"
  uci set dhcp.@host[-1].ip="192.168.1.10"

  uci add dhcp host
  uci set dhcp.@host[-1].name="OPIPC2"
  uci set dhcp.@host[-1].mac="02:01:3D:51:DC:63"
  uci set dhcp.@host[-1].ip="192.168.1.20"

  uci add dhcp host
  uci set dhcp.@host[-1].name="OPIPC2_WIFI"
  uci set dhcp.@host[-1].mac="00:26:66:42:DC:DF"
  uci set dhcp.@host[-1].ip="192.168.1.21"

  uci add dhcp host
  uci set dhcp.@host[-1].name="OPIZERO"
  uci set dhcp.@host[-1].mac="02:42:E3:78:DA:7B"
  uci set dhcp.@host[-1].ip="192.168.1.22"

  uci add dhcp host
  uci set dhcp.@host[-1].name="OPIZERO_WIFI"
  uci set dhcp.@host[-1].mac="12:42:E3:78:DA:7B"
  uci set dhcp.@host[-1].ip="192.168.1.23"

  uci add dhcp host
  uci set dhcp.@host[-1].name="PROBOOK_4330S"
  uci set dhcp.@host[-1].mac="E4:11:5B:43:B7:53"
  uci set dhcp.@host[-1].ip="192.168.1.30"

  uci add dhcp host
  uci set dhcp.@host[-1].name="PROBOOK_4330S_WIFI"
  uci set dhcp.@host[-1].mac="9C:B7:0D:60:EF:6D"
  uci set dhcp.@host[-1].ip="192.168.1.31"

  uci add dhcp host
  uci set dhcp.@host[-1].name="LM-V500N"
  uci set dhcp.@host[-1].mac="98:B8:BA:11:09:DF"
  uci set dhcp.@host[-1].ip="192.168.1.40"

  uci add dhcp host
  uci set dhcp.@host[-1].name="SM-A520K"
  uci set dhcp.@host[-1].mac="BC:54:51:8A:62:54"
  uci set dhcp.@host[-1].ip="192.168.1.41"

  uci add dhcp host
  uci set dhcp.@host[-1].name="IPHONE_6"
  uci set dhcp.@host[-1].mac="48:43:7C:F1:2D:B2"
  uci set dhcp.@host[-1].ip="192.168.1.42"

  uci add dhcp host
  uci set dhcp.@host[-1].name="VNS-L62"
  uci set dhcp.@host[-1].mac="D0:65:CA:CA:0A:B0"
  uci set dhcp.@host[-1].ip="192.168.1.43"

  uci add dhcp host
  uci set dhcp.@host[-1].name="EASYN_ES200K"
  uci set dhcp.@host[-1].mac="00:AF:87:7E:38:29"
  uci set dhcp.@host[-1].ip="192.168.1.50"

  uci add dhcp host
  uci set dhcp.@host[-1].name="EASYN_ES200K_WIFI"
  uci set dhcp.@host[-1].mac="1C:BF:CE:3D:93:4F"
  uci set dhcp.@host[-1].ip="192.168.1.51"

  uci add dhcp host
  uci set dhcp.@host[-1].name="XIAOWA_C10"
  uci set dhcp.@host[-1].mac="78:11:DC:52:6D:3D"
  uci set dhcp.@host[-1].ip="192.168.1.60"

  rm -f /tmp/dhcp.leases
  uci commit dhcp
}

func_set_samba() {
  echo "###########################################################"
  echo "#"
  echo "# set samba"
  echo "#"
  echo "###########################################################"
  echo ""
  uci set samba.@samba[0]='samba'
  uci set samba.@samba[0].name='openwrt'
  uci set samba.@samba[0].workgroup='WORKGROUP'
  uci set samba.@samba[0].description="${DEVICE_NAME}"
  uci set samba.@samba[0].homes='0'
  uci add samba sambashare
  uci set samba.@sambashare[-1]='sambashare'
  uci set samba.@sambashare[-1].browseable='yes'
  uci set samba.@sambashare[-1].path='/mnt'
  uci set samba.@sambashare[-1].users='openwrt'
  uci set samba.@sambashare[-1].read_only='no'
  uci set samba.@sambashare[-1].guest_ok='no'
  uci set samba.@sambashare[-1].create_mask='600'
  uci set samba.@sambashare[-1].dir_mask='700'
  uci set samba.@sambashare[-1].name='STORAGE'

  uci commit samba
  /etc/init.d/samba stop
  uci commit samba
  umount /mnt
  chown openwrt:nogroup /mnt
  /etc/init.d/samba enable
  /etc/init.d/samba start
}

func_set_firewall() {
  echo "###########################################################"
  echo "#"
  echo "# firewall defaults"
  echo "#"
  echo "###########################################################"
  echo ""
  uci set firewall.@defaults[0]=defaults
  uci set firewall.@defaults[0].syn_flood='1'
  uci set firewall.@defaults[0].input='DROP'
  uci set firewall.@defaults[0].forward='DROP'
  uci set firewall.@defaults[0].output='DROP'
  uci set firewall.@rule[0].enabled='1'
  uci set firewall.@rule[1].enabled='0'
  uci set firewall.@rule[2].enabled='1'
  uci set firewall.@rule[3].enabled='0'
  uci set firewall.@rule[4].enabled='0'
  uci set firewall.@rule[5].enabled='0'
  uci set firewall.@rule[6].enabled='0'
  uci set firewall.@rule[7].enabled='0'
  uci set firewall.@rule[8].enabled='0'
  uci set firewall.@rule[0].extra='-m geoip --src-cc KR'
  uci set firewall.@rule[1].extra='-m geoip --src-cc KR'
  uci set firewall.@rule[2].extra='-m geoip --src-cc KR'
  uci set firewall.@rule[3].extra='-m geoip --src-cc KR'
  uci set firewall.@rule[4].extra='-m geoip --src-cc KR'
  uci set firewall.@rule[5].extra='-m geoip --src-cc KR'
  uci set firewall.@rule[6].extra='-m geoip --src-cc KR'
  uci set firewall.@rule[7].extra='-m geoip --src-cc KR'
  uci set firewall.@rule[8].extra='-m geoip --src-cc KR'

  echo "###########################################################"
  echo "#"
  echo "# add firewall rule"
  echo "#"
  echo "###########################################################"
  echo ""
  uci add firewall rule
  uci set firewall.@rule[-1]=rule
  uci set firewall.@rule[-1].target='ACCEPT'
  uci set firewall.@rule[-1].name='allow-es200k lan to wan ntp'
  uci set firewall.@rule[-1].family='ipv4'
  uci set firewall.@rule[-1].src='lan'
  uci set firewall.@rule[-1].src_ip='192.168.1.50'
  uci set firewall.@rule[-1].dest_port='37 123'
  uci set firewall.@rule[-1].proto='tcp udp'
  uci set firewall.@rule[-1].dest='wan'
  uci set firewall.@rule[-1].enabled='1'

  uci add firewall rule
  uci set firewall.@rule[-1]=rule
  uci set firewall.@rule[-1].target='ACCEPT'
  uci set firewall.@rule[-1].name='allow-es200k wifi lan to wan ntp'
  uci set firewall.@rule[-1].family='ipv4'
  uci set firewall.@rule[-1].src='lan'
  uci set firewall.@rule[-1].src_ip='192.168.1.51'
  uci set firewall.@rule[-1].dest_port='37 123'
  uci set firewall.@rule[-1].proto='tcp udp'
  uci set firewall.@rule[-1].dest='wan'
  uci set firewall.@rule[-1].enabled='1'

  uci add firewall rule
  uci set firewall.@rule[-1]=rule
  uci set firewall.@rule[-1].name='reject-es200k lan to wan'
  uci set firewall.@rule[-1].src_ip='192.168.1.50'
  uci set firewall.@rule[-1].target='REJECT'
  uci set firewall.@rule[-1].family='ipv4'
  uci set firewall.@rule[-1].src='lan'
  uci set firewall.@rule[-1].proto='tcp udp'
  uci set firewall.@rule[-1].dest='wan'
  uci set firewall.@rule[-1].enabled='1'

  uci add firewall rule
  uci set firewall.@rule[-1]=rule
  uci set firewall.@rule[-1].name='reject-es200k wifi lan to wan'
  uci set firewall.@rule[-1].src_ip='192.168.1.51'
  uci set firewall.@rule[-1].target='REJECT'
  uci set firewall.@rule[-1].family='ipv4'
  uci set firewall.@rule[-1].src='lan'
  uci set firewall.@rule[-1].proto='tcp udp'
  uci set firewall.@rule[-1].dest='wan'
  uci set firewall.@rule[-1].enabled='1'

  echo "###########################################################"
  echo "#"
  echo "# add firewall redirect"
  echo "#"
  echo "###########################################################"
  echo ""
  uci add firewall redirect
  uci set firewall.@redirect[-1]=redirect
  uci set firewall.@redirect[-1].target='DNAT'
  uci set firewall.@redirect[-1].src='wan'
  uci set firewall.@redirect[-1].dest='lan'
  uci set firewall.@redirect[-1].proto='tcp'
  uci set firewall.@redirect[-1].src_dport='5005'
  uci set firewall.@redirect[-1].dest_ip='192.168.1.10'
  uci set firewall.@redirect[-1].dest_port='5005'
  uci set firewall.@redirect[-1].name='webdav'
  uci set firewall.@redirect[-1].enabled='1'
  uci set firewall.@redirect[-1].extra='-m geoip --src-cc KR'

  uci add firewall redirect
  uci set firewall.@redirect[-1]=redirect
  uci set firewall.@redirect[-1].target='DNAT'
  uci set firewall.@redirect[-1].src='wan'
  uci set firewall.@redirect[-1].src_ip="${TRUST_HOST}"
  uci set firewall.@redirect[-1].dest='lan'
  uci set firewall.@redirect[-1].proto='tcp'
  uci set firewall.@redirect[-1].src_dport='9091'
  uci set firewall.@redirect[-1].dest_ip='192.168.1.10'
  uci set firewall.@redirect[-1].dest_port='9091'
  uci set firewall.@redirect[-1].name='transmission-daemon'
  uci set firewall.@redirect[-1].enabled='1'
  uci set firewall.@redirect[-1].extra='-m geoip --src-cc KR'

  uci add firewall redirect
  uci set firewall.@redirect[-1]=redirect
  uci set firewall.@redirect[-1].target='DNAT'
  uci set firewall.@redirect[-1].src='wan'
  uci set firewall.@redirect[-1].dest='lan'
  uci set firewall.@redirect[-1].proto='tcp'
  uci set firewall.@redirect[-1].src_dport='443'
  uci set firewall.@redirect[-1].dest_ip='192.168.1.10'
  uci set firewall.@redirect[-1].dest_port='443'
  uci set firewall.@redirect[-1].name='https'
  uci set firewall.@redirect[-1].enabled='1'
  uci set firewall.@redirect[-1].extra='-m geoip --src-cc KR'

  uci add firewall redirect
  uci set firewall.@redirect[-1]=redirect
  uci set firewall.@redirect[-1].target='DNAT'
  uci set firewall.@redirect[-1].src='wan'
  uci set firewall.@redirect[-1].src_ip="${TRUST_HOST}"
  uci set firewall.@redirect[-1].dest='lan'
  uci set firewall.@redirect[-1].proto='tcp'
  uci set firewall.@redirect[-1].src_dport='5901'
  uci set firewall.@redirect[-1].dest_ip='192.168.1.20'
  uci set firewall.@redirect[-1].dest_port='5901'
  uci set firewall.@redirect[-1].name='vnc-192.168.1.20'
  uci set firewall.@redirect[-1].enabled='1'

  uci add firewall redirect
  uci set firewall.@redirect[-1]=redirect
  uci set firewall.@redirect[-1].target='DNAT'
  uci set firewall.@redirect[-1].src='wan'
  uci set firewall.@redirect[-1].src_ip="${TRUST_HOST}"
  uci set firewall.@redirect[-1].dest='lan'
  uci set firewall.@redirect[-1].proto='tcp'
  uci set firewall.@redirect[-1].src_dport='3389'
  uci set firewall.@redirect[-1].dest_ip='192.168.1.30'
  uci set firewall.@redirect[-1].dest_port='3389'
  uci set firewall.@redirect[-1].name='rdp-192.168.1.30'
  uci set firewall.@redirect[-1].enabled='1'

  uci add firewall redirect
  uci set firewall.@redirect[-1]=redirect
  uci set firewall.@redirect[-1].target='DNAT'
  uci set firewall.@redirect[-1].src='wan'
  uci set firewall.@redirect[-1].dest='lan'
  uci set firewall.@redirect[-1].proto='tcp udp'
  uci set firewall.@redirect[-1].src_dport='51413'
  uci set firewall.@redirect[-1].dest_ip='192.168.1.20'
  uci set firewall.@redirect[-1].dest_port='51413'
  uci set firewall.@redirect[-1].name='transmission-peer'
  uci set firewall.@redirect[-1].enabled='1'

  uci add firewall redirect
  uci set firewall.@redirect[-1]=redirect
  uci set firewall.@redirect[-1].src_ip="${TRUST_HOST}"
  uci set firewall.@redirect[-1].target='DNAT'
  uci set firewall.@redirect[-1].src='wan'
  uci set firewall.@redirect[-1].dest='lan'
  uci set firewall.@redirect[-1].proto='tcp'
  uci set firewall.@redirect[-1].src_dport='21'
  uci set firewall.@redirect[-1].dest_ip='192.168.1.10'
  uci set firewall.@redirect[-1].dest_port='21'
  uci set firewall.@redirect[-1].name='ftp'
  uci set firewall.@redirect[-1].enabled='1'

  uci add firewall redirect
  uci set firewall.@redirect[-1]=redirect
  uci set firewall.@redirect[-1].src_ip="${TRUST_HOST}"
  uci set firewall.@redirect[-1].target='DNAT'
  uci set firewall.@redirect[-1].src='wan'
  uci set firewall.@redirect[-1].dest='lan'
  uci set firewall.@redirect[-1].proto='tcp'
  uci set firewall.@redirect[-1].src_dport='5500-5532'
  uci set firewall.@redirect[-1].dest_ip='192.168.1.10'
  uci set firewall.@redirect[-1].name='ftp-passive'
  uci set firewall.@redirect[-1].enabled='1'

  uci add firewall redirect
  uci set firewall.@redirect[-1]=redirect
  uci set firewall.@redirect[-1].src_ip="${TRUST_HOST}"
  uci set firewall.@redirect[-1].target='DNAT'
  uci set firewall.@redirect[-1].src='wan'
  uci set firewall.@redirect[-1].dest='lan'
  uci set firewall.@redirect[-1].proto='tcp'
  uci set firewall.@redirect[-1].src_dport='22'
  uci set firewall.@redirect[-1].dest_ip='192.168.1.10'
  uci set firewall.@redirect[-1].dest_port='9910'
  uci set firewall.@redirect[-1].name='ssh-192.168.1.10'
  uci set firewall.@redirect[-1].enabled='1'

  uci add firewall redirect
  uci set firewall.@redirect[-1]=redirect
  uci set firewall.@redirect[-1].src_ip="${TRUST_HOST}"
  uci set firewall.@redirect[-1].target='DNAT'
  uci set firewall.@redirect[-1].src='wan'
  uci set firewall.@redirect[-1].dest='lan'
  uci set firewall.@redirect[-1].proto='tcp'
  uci set firewall.@redirect[-1].src_dport='22'
  uci set firewall.@redirect[-1].dest_ip='192.168.1.20'
  uci set firewall.@redirect[-1].dest_port='9920'
  uci set firewall.@redirect[-1].name='ssh-192.168.1.20'
  uci set firewall.@redirect[-1].enabled='1'

  uci add firewall redirect
  uci set firewall.@redirect[-1]=redirect
  uci set firewall.@redirect[-1].src_ip="${TRUST_HOST}"
  uci set firewall.@redirect[-1].target='DNAT'
  uci set firewall.@redirect[-1].src='wan'
  uci set firewall.@redirect[-1].dest='lan'
  uci set firewall.@redirect[-1].proto='tcp'
  uci set firewall.@redirect[-1].src_dport='32400'
  uci set firewall.@redirect[-1].dest_ip='192.168.1.20'
  uci set firewall.@redirect[-1].dest_port='32400'
  uci set firewall.@redirect[-1].name='plex_media_server'
  uci set firewall.@redirect[-1].enabled='1'

  echo "###########################################################"
  echo "#"
  echo "# add firewall NFS redirect"
  echo "#"
  echo "###########################################################"
  echo ""
  uci add firewall redirect
  uci set firewall.@redirect[-1]=redirect
  uci set firewall.@redirect[-1].target='DNAT'
  uci set firewall.@redirect[-1].src='wan'
  uci set firewall.@redirect[-1].src_ip="${TRUST_HOST}"
  uci set firewall.@redirect[-1].dest='lan'
  uci set firewall.@redirect[-1].proto='tcp udp'
  uci set firewall.@redirect[-1].src_dport='111'
  uci set firewall.@redirect[-1].dest_ip='192.168.1.10'
  uci set firewall.@redirect[-1].dest_port='111'
  uci set firewall.@redirect[-1].name='nfs_portmapper'
  uci set firewall.@redirect[-1].enabled='1'

  uci add firewall redirect
  uci set firewall.@redirect[-1]=redirect
  uci set firewall.@redirect[-1].target='DNAT'
  uci set firewall.@redirect[-1].src='wan'
  uci set firewall.@redirect[-1].src_ip="${TRUST_HOST}"
  uci set firewall.@redirect[-1].dest='lan'
  uci set firewall.@redirect[-1].proto='tcp udp'
  uci set firewall.@redirect[-1].src_dport='2049'
  uci set firewall.@redirect[-1].dest_ip='192.168.1.10'
  uci set firewall.@redirect[-1].dest_port='2049'
  uci set firewall.@redirect[-1].name='nfs'
  uci set firewall.@redirect[-1].enabled='1'

  uci add firewall redirect
  uci set firewall.@redirect[-1]=redirect
  uci set firewall.@redirect[-1].target='DNAT'
  uci set firewall.@redirect[-1].src='wan'
  uci set firewall.@redirect[-1].src_ip="${TRUST_HOST}"
  uci set firewall.@redirect[-1].dest='lan'
  uci set firewall.@redirect[-1].proto='tcp udp'
  uci set firewall.@redirect[-1].src_dport='4001'
  uci set firewall.@redirect[-1].dest_ip='192.168.1.10'
  uci set firewall.@redirect[-1].dest_port='4001'
  uci set firewall.@redirect[-1].name='nfs_nlockmgr'
  uci set firewall.@redirect[-1].enabled='1'

  uci add firewall redirect
  uci set firewall.@redirect[-1]=redirect
  uci set firewall.@redirect[-1].target='DNAT'
  uci set firewall.@redirect[-1].src='wan'
  uci set firewall.@redirect[-1].src_ip="${TRUST_HOST}"
  uci set firewall.@redirect[-1].dest='lan'
  uci set firewall.@redirect[-1].proto='tcp udp'
  uci set firewall.@redirect[-1].src_dport='4002'
  uci set firewall.@redirect[-1].dest_ip='192.168.1.10'
  uci set firewall.@redirect[-1].dest_port='4002'
  uci set firewall.@redirect[-1].name='nfs_mountd'
  uci set firewall.@redirect[-1].enabled='1'

  uci commit firewall
}

func_set_wireless() {
  echo "###########################################################"
  echo "#"
  echo "# set wifi"
  echo "#"
  echo "###########################################################"
  echo ""
  uci set wireless.default_radio0.mode='ap'
  uci set wireless.default_radio0.ssid='IEEE_802.11_BGN'
  uci set wireless.default_radio0.encryption='psk2'
  uci set wireless.default_radio0.key='01086023358'
  uci set wireless.default_radio0.disabled='0'

  uci set wireless.default_radio1.mode='ap'
  uci set wireless.default_radio1.ssid='IEEE_802.11_NAC'
  uci set wireless.default_radio1.encryption='psk2'
  uci set wireless.default_radio1.key='01086023358'
  uci set wireless.default_radio1.disabled='0'

  uci commit wireless
}

func_hd_idle() {
  echo "config hd-idle" > /etc/config/hd-idle
  echo "  option disk 'sda'" >> /etc/config/hd-idle
  echo "  option idle_time_unit 'minutes'" >> /etc/config/hd-idle
  echo "  option idle_time_interval '5'" >> /etc/config/hd-idle
  echo "  option enabled '1'" >> /etc/config/hd-idle

  uci commit hd-idle
}

func_passwd_openwrt() {
  echo "###########################################################"
  echo "#"
  echo "# passwd openwrt"
  echo "#"
  echo "###########################################################"
  echo ""
  passwd openwrt
}

func_smbpasswd_openwrt() {
  echo ""
  echo "###########################################################"
  echo "#"
  echo "# smbpasswd -a openwrt"
  echo "#"
  echo "###########################################################"
  echo ""
  smbpasswd -a openwrt
}

check_board_name
func_set_vsftpd
func_set_system
func_set_ntpclient
func_make_mount_script
func_set_ddns
func_set_dhcp
func_set_samba
func_set_firewall
func_set_wireless
func_hd_idle
luci-reload
func_passwd_openwrt
func_smbpasswd_openwrt
func_echo_reboot_now
rm -f $0
위로 스크롤