Skip to content
Snippets Groups Projects
Select Git revision
  • ac84ddf10135b62d32504f2035e1c7f06b0593e6
  • experimental default protected
  • v2023.2.5-ffs
  • nrb/ex400-remove-wps
  • nrb/airmax-test
  • v2023.2.4-ffs
  • nrb/ar9344-reset-sequence
  • autinerd/experimental-openwrt-24.10
  • v2023.2.3-ffs
  • v2023.2.2-ffs
  • v2023.2-ffs
  • v2023.1-ffs
  • v2022.1.4-ffs
  • feature/addMikrotikwAP
  • v2022.1.3-ffs
  • v2021.1.2-ffs
  • v2022.1.1-ffs
  • master protected
  • v2021.1.1-ffs
  • nrb/gluon-master-cpe510
  • v2021.1-ffs
  • experimental-2025-07-04
  • experimental-2025-07-04-base
  • experimental-2025-07-01
  • experimental-2025-07-01-base
  • experimental-2025-06-25
  • experimental-2025-06-25-base
  • experimental-2025-06-24
  • experimental-2025-06-24-base
  • experimental-2025-06-22
  • experimental-2025-06-22-base
  • v2023.2.5-ffs0.1
  • experimental-2025-06-08
  • experimental-2025-06-08-base
  • experimental-2025-06-06
  • experimental-2025-06-06-base
  • experimental-2025-05-27
  • experimental-2025-05-27-base
  • experimental-2025-05-18
  • experimental-2025-05-18-base
  • experimental-2025-05-15
41 results

image_customization_lib.lua

Blame
    • Matthias Schiffer's avatar
      70b4e729
      scripts: image_customization_lib: add include() function · 70b4e729
      Matthias Schiffer authored
      Add a simple way to include image customization Lua snippets.
      Can be used to split long files, to include the same options multiple
      times in different conditional branches, or even to pass values back to
      the including file using return.
      
      Relative paths are interpreted relative to the site root (where
      image-customization.lua is located). Relative includes would become
      confusing when subdirectories are involved (as they are still interpreted
      relative to the site root, and proper tracking of current directory for
      each include seems fairly complex for a very niche use case), so we simply
      reject this case for now; this way, we can implement this however we
      want in the future if deemed necessary, without a breaking change.
      scripts: image_customization_lib: add include() function
      Matthias Schiffer authored
      Add a simple way to include image customization Lua snippets.
      Can be used to split long files, to include the same options multiple
      times in different conditional branches, or even to pass values back to
      the including file using return.
      
      Relative paths are interpreted relative to the site root (where
      image-customization.lua is located). Relative includes would become
      confusing when subdirectories are involved (as they are still interpreted
      relative to the site root, and proper tracking of current directory for
      each include seems fairly complex for a very niche use case), so we simply
      reject this case for now; this way, we can implement this however we
      want in the future if deemed necessary, without a breaking change.
    image_customization_lib.lua 3.24 KiB
    local M = {
    	customization_file = nil,
    }
    
    local function evaluate_device(env, dev)
    	local selections = {
    		features = {},
    		packages = {},
    	}
    	local funcs = {}
    	local device_overrides = {}
    
    	local function add_elements(element_type, element_list)
    		local error_msg = string.format(
    			'incorrect use of %s(): list of %s expected as argument',
    			element_type, element_type)
    		assert(type(element_list) == 'table', error_msg)
    
    		-- We depend on the fact both feature and package
    		-- are already initialized as empty tables
    		for _, element in ipairs(element_list) do
    			assert(type(element) == 'string', error_msg)
    			table.insert(selections[element_type], element)
    		end
    	end
    
    	local function add_override(ovr_key, ovr_value)
    		device_overrides[ovr_key] = ovr_value
    	end
    
    	function funcs.features(features)
    		add_elements('features', features)
    	end
    
    	function funcs.packages(packages)
    		add_elements('packages', packages)
    	end
    
    	function funcs.broken(broken)
    		assert(
    			type(broken) == 'boolean',
    			'incorrect use of broken(): boolean argument expected')
    		add_override('broken', broken)
    	end
    
    	function funcs.disable()
    		add_override('disabled', true)
    	end
    
    	function funcs.disable_factory()
    		add_override('disable_factory', true)
    	end
    
    	function funcs.device(device_names)
    		assert(
    			type(device_names) == 'table',
    			'incorrect use of device(): list of device names expected as argument')
    
    		for _, device_name in ipairs(device_names) do
    			assert(
    				type(device_name) == 'string',
    				'incorrect use of device(): list of device names expected as argument')
    
    			if device_name == dev.image then
    				return true
    			end
    		end
    
    		return false
    	end