Skip to content
Snippets Groups Projects
Commit 216c9ce3 authored by Matthias Schiffer's avatar Matthias Schiffer
Browse files

Merge gluon packages

The gluon packages will be maintained in the gluon main repository in the
future.
parents 750d9587 c4f7a526
No related branches found
No related tags found
No related merge requests found
Showing
with 410 additions and 0 deletions
include $(TOPDIR)/rules.mk
PKG_NAME:=gluon-core
PKG_VERSION:=3
PKG_RELEASE:=$(GLUON_VERSION)
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
include $(GLUONDIR)/include/package.mk
define Package/gluon-core
SECTION:=gluon
CATEGORY:=Gluon
TITLE:=Base files of Gluon
DEPENDS:=+gluon-site +lua-platform-info +luci-lib-nixio +odhcp6c +firewall
endef
define LangConfig
config GLUON_LANG_$(1)
bool "$(GLUON_LANG_$(1)) language support"
depends on PACKAGE_gluon-core
default n
endef
define Package/gluon-core/config
$(foreach lang,$(GLUON_SUPPORTED_LANGS),$(call LangConfig,$(lang)))
endef
define Package/gluon-core/description
Gluon community wifi mesh firmware framework: core
endef
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
endef
define Build/Configure
endef
define Build/Compile
endef
define Package/gluon-core/install
$(CP) ./files/* $(1)/
$(INSTALL_DIR) $(1)/lib/gluon
echo "$(GLUON_VERSION)" > $(1)/lib/gluon/gluon-version
endef
define Package/gluon-core/postinst
#!/bin/sh
$(call GluonCheckSite,check_site.lua)
endef
$(eval $(call BuildPackage,gluon-core))
need_string 'site_code'
need_string 'site_name'
need_string('hostname_prefix', false)
need_string 'timezone'
need_string_array('ntp_servers', false)
need_string_match('prefix4', '^%d+.%d+.%d+.%d+/%d+$')
need_string_match('prefix6', '^[%x:]+/%d+$')
#!/bin/sh
for script in /lib/gluon/upgrade/*; do
"$script"
done
#!/usr/bin/lua
local fs = require 'luci.fs'
local sysconfig = require 'gluon.sysconfig'
if fs.isfile('/lib/gluon/version/core') and not sysconfig.gluon_version then
-- This isn't an initial upgrade, so set gluon_version
sysconfig.gluon_version = ''
end
#!/usr/bin/lua
local sysconfig = require 'gluon.sysconfig'
if sysconfig.primary_mac then
os.exit(0)
end
local platform = require 'gluon.platform'
local fs = require 'luci.fs'
local util = require 'luci.util'
local try_files = {
'/sys/class/ieee80211/phy0/macaddress',
'/sys/class/net/eth0/address',
}
if platform.match('ar71xx', 'generic', {'tl-wdr3600', 'tl-wdr4300'}) then
table.insert(try_files, 1, '/sys/class/ieee80211/phy1/macaddress')
end
if platform.match('ar71xx', 'generic', {'unifi-outdoor-plus'}) then
table.insert(try_files, 1, '/sys/class/net/eth0/address')
end
if platform.match('ar71xx', 'generic', {'archer-c5', 'archer-c7'}) then
table.insert(try_files, 1, '/sys/class/net/eth1/address')
end
for _, file in ipairs(try_files) do
local addr = fs.readfile(file)
if addr then
sysconfig.primary_mac = util.trim(addr)
break
end
end
#!/usr/bin/lua
local sysconfig = require 'gluon.sysconfig'
local gluon_util = require 'gluon.util'
local platform = require 'gluon.platform'
local uci = require('luci.model.uci').cursor()
if not (sysconfig.lan_ifname or sysconfig.wan_ifname) then
local function iface_exists(name)
return (gluon_util.exec('ip', 'link', 'show', 'dev', (name:gsub('%..*$', ''))) == 0)
end
local lan_ifname = uci:get('network', 'lan', 'ifname')
local wan_ifname = uci:get('network', 'wan', 'ifname')
if platform.match('ar71xx', 'generic', {'cpe510', 'nanostation-m', 'nanostation-m-xw', 'unifi-outdoor-plus'}) then
lan_ifname, wan_ifname = wan_ifname, lan_ifname
end
if wan_ifname and iface_exists(wan_ifname) then
sysconfig.wan_ifname = wan_ifname
sysconfig.lan_ifname = lan_ifname
else
sysconfig.wan_ifname = lan_ifname
end
uci:delete('network', 'lan')
uci:delete('network', 'wan')
uci:save('network')
uci:commit('network')
end
#!/usr/bin/lua
local sysconfig = require 'gluon.sysconfig'
-- Initial
if not sysconfig.gluon_version then
local site = require 'gluon.site_config'
local util = require 'gluon.util'
local uci = require('luci.model.uci').cursor()
local system = uci:get_first('system', 'system')
uci:set('system', system, 'hostname', (site.hostname_prefix or '') .. util.node_id())
uci:set('system', system, 'timezone', site.timezone)
uci:save('system')
uci:commit('system')
end
#!/bin/sh
if [ -e /etc/dnsmasq.conf ]; then
sed -i -e '/^conf-dir=\/lib\/gluon\/dnsmasq\.d$/d' -e '/^conf-dir=\/var\/gluon\/dnsmasq\.d$/d' /etc/dnsmasq.conf
fi
#!/usr/bin/lua
local uci = require('luci.model.uci').cursor()
local sysctl = require 'gluon.sysctl'
local sysconfig = require 'gluon.sysconfig'
uci:section('network', 'interface', 'wan',
{
ifname = sysconfig.wan_ifname,
type = 'bridge',
peerdns = 0,
auto = 1,
}
)
if not uci:get('network', 'wan', 'proto') then
uci:set('network', 'wan', 'proto', 'dhcp')
end
uci:section('network', 'interface', 'wan6',
{
ifname = 'br-wan',
peerdns = 0,
ip6table = 1,
}
)
if not uci:get('network', 'wan6', 'proto') then
uci:set('network', 'wan6', 'proto', 'dhcpv6')
end
uci:section('network', 'rule6', 'wan6_lookup',
{
mark = '0x01/0x01',
lookup = 1,
}
)
uci:section('network', 'route6', 'wan6_unreachable',
{
type = 'unreachable',
interface = 'loopback',
target = '::/0',
gateway = '::',
table = 1,
metric = 65535,
}
)
uci:save('network')
uci:commit('network')
sysctl.set('net.ipv6.conf.all.accept_ra', 0)
sysctl.set('net.ipv6.conf.default.accept_ra', 0)
#!/usr/bin/lua
local site = require 'gluon.site_config'
local uci = require 'luci.model.uci'
if not site.ntp_servers or #site.ntp_servers == 0 then
os.exit(0)
end
local c = uci.cursor()
c:delete('system', 'ntp', 'server')
c:set_list('system', 'ntp', 'server', site.ntp_servers)
c:save('system')
c:commit('system')
#!/usr/bin/lua
local sysctl = require 'gluon.sysctl'
sysctl.set('vm.panic_on_oom', 1)
#!/usr/bin/lua
local site = require 'gluon.site_config'
local uci = require 'luci.model.uci'
local c = uci.cursor()
local function reject_input_on_wan(zone)
if zone.name == 'wan' then
c:set('firewall', zone['.name'], 'input', 'REJECT')
c:set('firewall', zone['.name'], 'conntrack', '1')
end
return true
end
c:foreach('firewall', 'zone', reject_input_on_wan)
c:section('firewall', 'rule', 'wan_ssh',
{
name = 'wan_ssh',
src = 'wan',
dest_port = '22',
proto = 'tcp',
target = 'ACCEPT',
}
)
c:save('firewall')
c:commit('firewall')
#!/usr/bin/lua
local sysconfig = require 'gluon.sysconfig'
-- Initial
if not sysconfig.gluon_version then
local uci = require('luci.model.uci').cursor()
uci:delete_all('wireless', 'wifi-iface')
uci:save('wireless')
uci:commit('wireless')
end
#!/usr/bin/lua
local sysconfig = require 'gluon.sysconfig'
local fs = require 'luci.fs'
local util = require 'luci.util'
-- Save the Gluon version in the sysconfig so we know which version we
-- upgraded from after the next upgrade
sysconfig.gluon_version = util.trim(fs.readfile('/lib/gluon/gluon-version'))
/lib/gluon/core/sysconfig/
local platform_info = require 'platform_info'
local util = require 'luci.util'
local setmetatable = setmetatable
module 'gluon.platform'
setmetatable(_M,
{
__index = platform_info,
}
)
function match(target, subtarget, boards)
if get_target() ~= target then
return false
end
if get_subtarget() ~= subtarget then
return false
end
if not util.contains(boards, get_board_name()) then
return false
end
return true
end
local config = os.getenv('GLUON_SITE_CONFIG') or '/lib/gluon/site.conf'
local function loader()
coroutine.yield('return ')
coroutine.yield(io.open(config):read('*a'))
end
-- setfenv doesn't work with Lua 5.2 anymore, but we're using 5.1
local site_config = setfenv(assert(load(coroutine.wrap(loader), 'site.conf')), {})()
local setmetatable = setmetatable
module 'gluon.site_config'
setmetatable(_M,
{
__index = site_config,
}
)
return _M
local sysconfigdir = '/lib/gluon/core/sysconfig/'
local function get(_, name)
local f = io.open(sysconfigdir .. name)
if f then
local ret = f:read('*line')
f:close()
return (ret or '')
end
return nil
end
local function set(_, name, val)
if val then
local f = io.open(sysconfigdir .. name, 'w+')
f:write(val)
f:close()
else
os.remove(sysconfigdir .. name)
end
end
local setmetatable = setmetatable
module 'gluon.sysconfig'
setmetatable(_M,
{
__index = get,
__newindex = set,
}
)
return _M
local util = require 'gluon.util'
module 'gluon.sysctl'
function set(name, value)
util.replace_prefix('/etc/sysctl.conf', name .. '=', name .. '=' .. value .. '\n')
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment