code:
--for surface lovers who are also tech lovers
-- URANIUM.................................11
-- CHROMIUM...............................218
-- ZINC...................................425
-- LEAD...................................632
-- SULFUR.................................839
-- GRANITE................................915
-- MARBLE................................1000

if(minetest.get_modpath("technic_worldgen")) ~= nil then
-- URANIUM
--craft
minetest.register_craft({
	output = '"orewood:uraniumwood_fake"',
	recipe = {
		{'technic:uranium_block', 'technic:uranium_block','technic:uranium_block'},
		{'technic:uranium_block', 'group:orewood_technic','technic:uranium_block'},
		{'technic:uranium_block', 'technic:uranium_block','technic:uranium_block'},
	}
})

minetest.register_craft({
	output = '"orewood:uraniumwood"',
	recipe = {
		{'group:stone', 'group:wood','group:stone'},
		{'group:wood', 'technic:uranium_block','group:wood'},
		{'group:stone', 'group:wood','group:stone'},
	}
})
--cook
minetest.register_craft({
	type = "cooking",
	output = "orewood:uraniumwood_hot",
	recipe = "group:orew_uranium",
})
--wooden nodes
minetest.register_node(":orewood:uraniumwood", {
	description = "Uraniumwood",
	tiles = {"default_tree_top.png", "default_tree_top.png", "default_tree.png^technic_mineral_uranium.png"},
	paramtype2 = "facedir",
	is_ground_content = false,
	groups = {orewood_technic=1,orew_uranium=1,tree=1,choppy=2,oddly_breakable_by_hand=1,flammable=2},
	sounds = default.node_sound_wood_defaults(),

	on_place = minetest.rotate_node
})
--hot
minetest.register_node(":orewood:uraniumwood_hot", {
	description = "Hot Uraniumwood",
	tiles = {"default_furnace_top.png", "default_furnace_top.png", "default_coal_block.png^technic_uranium_ingot.png"},
	paramtype2 = "facedir",
	is_ground_content = false,
	groups = {orewood_technic=1,orew_hot=1,choppy=2,oddly_breakable_by_hand=1},
	sounds = default.node_sound_wood_defaults(),

	on_place = minetest.rotate_node
})
--fake nodes
minetest.register_node(":orewood:uraniumwood_fake", {
	description = "Fake Uraniumwood",
	tiles = {"default_jungletree_top.png", "default_jungletree_top.png", "default_tree.png^technic_mineral_uranium.png"},
	paramtype2 = "facedir",
	is_ground_content = false,
	groups = {orewood_technic=1,orew_fake=1,tree=1,choppy=2,oddly_breakable_by_hand=1,flammable=2},
	sounds = default.node_sound_wood_defaults(),

	on_place = minetest.rotate_node
})
--papy nodes
minetest.register_node(":orewood:uraniumpapy", {
	description = "Uraniumpapy",
	drop = "technic:uranium_lump",
	drawtype = "plantlike",
	stack_max = 999,
	tiles = {"technic_uranium_block.png^orewood_cover_mp.png^[makealpha:255,0,255"},
	inventory_image = "technic_uranium_block.png^orewood_cover_mp.png^[makealpha:255,0,255",
	wield_image = "technic_uranium_block.png^orewood_cover_mp.png^[makealpha:255,0,255",
	paramtype = "light",
	walkable = false,
	is_ground_content = true,
	selection_box = {
		type = "fixed",
		fixed = {-0.3, -0.5, -0.3, 0.3, 0.5, 0.3}
	},
	groups = {snappy=3,flammable=2},
	sounds = default.node_sound_leaves_defaults(),

	after_dig_node = function(pos, node, metadata, digger)
		default.dig_up(pos, node, digger)
	end,
})

minetest.register_node(":orewood:uraniumpapy_ingot", {
	description = "Uraniumingotpapy",
	drop = "technic:uranium_ingot",
	drawtype = "plantlike",
	stack_max = 999,
	tiles = {"technic_uranium_block.png^orewood_cover_mf.png^[makealpha:255,0,255"},
	inventory_image = "technic_uranium_block.png^orewood_cover_mf.png^[makealpha:255,0,255",
	wield_image = "technic_uranium_block.png^orewood_cover_mf.png^[makealpha:255,0,255",
	paramtype = "light",
	walkable = false,
	is_ground_content = true,
	selection_box = {
		type = "fixed",
		fixed = {-0.3, -0.5, -0.3, 0.3, 0.5, 0.3}
	},
	groups = {snappy=3},
	sounds = default.node_sound_leaves_defaults(),

	after_dig_node = function(pos, node, metadata, digger)
		default.dig_up(pos, node, digger)
	end,
})
--ABMs srpout
minetest.register_abm({
	nodenames = {"orewood:uraniumwood"},
	neighbors = {"default:water_source"},
	interval = 40,
	chance = 10,
	action = function(pos, node)
	local height = 0
	while node.name == "orewood:uraniumwood" and height < 4 do
		height = height+1
		pos.y = pos.y+1
		node = minetest.get_node(pos)
	end
	if height == 4
	or node.name ~= "air" then
		return
	end
	minetest.set_node(pos, {name="orewood:uraniumpapy"})
	end,
})

minetest.register_abm({
	nodenames = {"orewood:uraniumwood_hot"},
	neighbors = {"default:lava_source"},
	interval = 40,
	chance = 10,
	action = function(pos, node)
	local height = 0
	while node.name == "orewood:uraniumwood_hot" and height < 4 do
		height = height+1
		pos.y = pos.y+1
		node = minetest.get_node(pos)
	end
	if height == 4
	or node.name ~= "air" then
		return
	end
	minetest.set_node(pos, {name="orewood:uraniumpapy_ingot"})
	end,
})
--ABMs grow
minetest.register_abm({
	nodenames = {"orewood:uraniumpapy"},
	neighbors = {"orewood:uraniumwood"},
	interval = 50,
	chance = 20,
	action = function(pos, node)
	pos.y = pos.y-1
	local name = minetest.get_node(pos).name
	if name ~= "orewood:uraniumwood"
	and name ~= "orewood:uraniumwood" then
		return
	end
	if not minetest.find_node_near(pos, 3, {"group:water"}) then
		return
	end
	pos.y = pos.y+1
	local height = 0
	while node.name == "orewood:uraniumpapy" and height < 4 do
		height = height+1
		pos.y = pos.y+1
		node = minetest.get_node(pos)
	end
	if height == 4
	or node.name ~= "air" then
		return
	end
	minetest.set_node(pos, {name="orewood:uraniumpapy"})
	return true
end,
})

minetest.register_abm({
	nodenames = {"orewood:uraniumpapy_ingot"},
	neighbors = {"orewood:uraniumwood_hot"},
	interval = 50,
	chance = 20,
	action = function(pos, node)
	pos.y = pos.y-1
	local name = minetest.get_node(pos).name
	if name ~= "orewood:uraniumwood_hot"
	and name ~= "orewood:uraniumwood_hot" then
		return
	end
	if not minetest.find_node_near(pos, 3, {"group:lava"}) then
		return
	end
	pos.y = pos.y+1
	local height = 0
	while node.name == "orewood:uraniumpapy_ingot" and height < 4 do
		height = height+1
		pos.y = pos.y+1
		node = minetest.get_node(pos)
	end
	if height == 4
	or node.name ~= "air" then
		return
	end
	minetest.set_node(pos, {name="orewood:uraniumpapy_ingot"})
	return true
end,
})

-- CHROMIUM
--craft
minetest.register_craft({
	output = '"orewood:chromiumwood_fake"',
	recipe = {
		{'technic:chromium_block', 'technic:chromium_block','technic:chromium_block'},
		{'technic:chromium_block', 'group:orewood_technic','technic:chromium_block'},
		{'technic:chromium_block', 'technic:chromium_block','technic:chromium_block'},
	}
})

minetest.register_craft({
	output = '"orewood:chromiumwood"',
	recipe = {
		{'group:stone', 'group:wood','group:stone'},
		{'group:wood', 'technic:chromium_block','group:wood'},
		{'group:stone', 'group:wood','group:stone'},
	}
})
--cook
minetest.register_craft({
	type = "cooking",
	output = "orewood:chromiumwood_hot",
	recipe = "group:orew_chromium",
})
--wooden nodes
minetest.register_node(":orewood:chromiumwood", {
	description = "Chromiumwood",
	tiles = {"default_tree_top.png", "default_tree_top.png", "default_tree.png^technic_mineral_chromium.png"},
	paramtype2 = "facedir",
	is_ground_content = false,
	groups = {orewood_technic=1,orew_chromium=1,tree=1,choppy=2,oddly_breakable_by_hand=1,flammable=2},
	sounds = default.node_sound_wood_defaults(),

	on_place = minetest.rotate_node
})
--hot
minetest.register_node(":orewood:chromiumwood_hot", {
	description = "Hot Chromiumwood",
	tiles = {"default_furnace_top.png", "default_furnace_top.png", "default_coal_block.png^technic_chromium_ingot.png"},
	paramtype2 = "facedir",
	is_ground_content = false,
	groups = {orewood_technic=1,orew_hot=1,choppy=2,oddly_breakable_by_hand=1},
	sounds = default.node_sound_wood_defaults(),

	on_place = minetest.rotate_node
})
--fake nodes
minetest.register_node(":orewood:chromiumwood_fake", {
	description = "Fake Chromiumwood",
	tiles = {"default_jungletree_top.png", "default_jungletree_top.png", "default_tree.png^technic_mineral_chromium.png"},
	paramtype2 = "facedir",
	is_ground_content = false,
	groups = {orewood_technic=1,orew_fake=1,tree=1,choppy=2,oddly_breakable_by_hand=1,flammable=2},
	sounds = default.node_sound_wood_defaults(),

	on_place = minetest.rotate_node
})
--papy nodes
minetest.register_node(":orewood:chromiumpapy", {
	description = "Chromiumpapy",
	drop = "technic:chromium_lump",
	drawtype = "plantlike",
	stack_max = 999,
	tiles = {"technic_chromium_block.png^orewood_cover_mp.png^[makealpha:255,0,255"},
	inventory_image = "technic_chromium_block.png^orewood_cover_mp.png^[makealpha:255,0,255",
	wield_image = "technic_chromium_block.png^orewood_cover_mp.png^[makealpha:255,0,255",
	paramtype = "light",
	walkable = false,
	is_ground_content = true,
	selection_box = {
		type = "fixed",
		fixed = {-0.3, -0.5, -0.3, 0.3, 0.5, 0.3}
	},
	groups = {snappy=3,flammable=2},
	sounds = default.node_sound_leaves_defaults(),

	after_dig_node = function(pos, node, metadata, digger)
		default.dig_up(pos, node, digger)
	end,
})

minetest.register_node(":orewood:chromiumpapy_ingot", {
	description = "Chromiumingotpapy",
	drop = "technic:chromium_ingot",
	drawtype = "plantlike",
	stack_max = 999,
	tiles = {"technic_chromium_block.png^orewood_cover_mf.png^[makealpha:255,0,255"},
	inventory_image = "technic_chromium_block.png^orewood_cover_mf.png^[makealpha:255,0,255",
	wield_image = "technic_chromium_block.png^orewood_cover_mf.png^[makealpha:255,0,255",
	paramtype = "light",
	walkable = false,
	is_ground_content = true,
	selection_box = {
		type = "fixed",
		fixed = {-0.3, -0.5, -0.3, 0.3, 0.5, 0.3}
	},
	groups = {snappy=3},
	sounds = default.node_sound_leaves_defaults(),

	after_dig_node = function(pos, node, metadata, digger)
		default.dig_up(pos, node, digger)
	end,
})
--ABMs srpout
minetest.register_abm({
	nodenames = {"orewood:chromiumwood"},
	neighbors = {"default:water_source"},
	interval = 40,
	chance = 10,
	action = function(pos, node)
	local height = 0
	while node.name == "orewood:chromiumwood" and height < 4 do
		height = height+1
		pos.y = pos.y+1
		node = minetest.get_node(pos)
	end
	if height == 4
	or node.name ~= "air" then
		return
	end
	minetest.set_node(pos, {name="orewood:chromiumpapy"})
	end,
})

minetest.register_abm({
	nodenames = {"orewood:chromiumwood_hot"},
	neighbors = {"default:lava_source"},
	interval = 40,
	chance = 10,
	action = function(pos, node)
	local height = 0
	while node.name == "orewood:chromiumwood_hot" and height < 4 do
		height = height+1
		pos.y = pos.y+1
		node = minetest.get_node(pos)
	end
	if height == 4
	or node.name ~= "air" then
		return
	end
	minetest.set_node(pos, {name="orewood:chromiumpapy_ingot"})
	end,
})
--ABMs grow
minetest.register_abm({
	nodenames = {"orewood:chromiumpapy"},
	neighbors = {"orewood:chromiumwood"},
	interval = 50,
	chance = 20,
	action = function(pos, node)
	pos.y = pos.y-1
	local name = minetest.get_node(pos).name
	if name ~= "orewood:chromiumwood"
	and name ~= "orewood:chromiumwood" then
		return
	end
	if not minetest.find_node_near(pos, 3, {"group:water"}) then
		return
	end
	pos.y = pos.y+1
	local height = 0
	while node.name == "orewood:chromiumpapy" and height < 4 do
		height = height+1
		pos.y = pos.y+1
		node = minetest.get_node(pos)
	end
	if height == 4
	or node.name ~= "air" then
		return
	end
	minetest.set_node(pos, {name="orewood:chromiumpapy"})
	return true
end,
})

minetest.register_abm({
	nodenames = {"orewood:chromiumpapy_ingot"},
	neighbors = {"orewood:chromiumwood_hot"},
	interval = 50,
	chance = 20,
	action = function(pos, node)
	pos.y = pos.y-1
	local name = minetest.get_node(pos).name
	if name ~= "orewood:chromiumwood_hot"
	and name ~= "orewood:chromiumwood_hot" then
		return
	end
	if not minetest.find_node_near(pos, 3, {"group:lava"}) then
		return
	end
	pos.y = pos.y+1
	local height = 0
	while node.name == "orewood:chromiumpapy_ingot" and height < 4 do
		height = height+1
		pos.y = pos.y+1
		node = minetest.get_node(pos)
	end
	if height == 4
	or node.name ~= "air" then
		return
	end
	minetest.set_node(pos, {name="orewood:chromiumpapy_ingot"})
	return true
end,
})

-- ZINC
--craft
minetest.register_craft({
	output = '"orewood:zincwood_fake"',
	recipe = {
		{'technic:zinc_block', 'technic:zinc_block','technic:zinc_block'},
		{'technic:zinc_block', 'group:orewood_technic','technic:zinc_block'},
		{'technic:zinc_block', 'technic:zinc_block','technic:zinc_block'},
	}
})

minetest.register_craft({
	output = '"orewood:zincwood"',
	recipe = {
		{'group:stone', 'group:wood','group:stone'},
		{'group:wood', 'technic:zinc_block','group:wood'},
		{'group:stone', 'group:wood','group:stone'},
	}
})
--cook
minetest.register_craft({
	type = "cooking",
	output = "orewood:zincwood_hot",
	recipe = "group:orew_zinc",
})
--wooden nodes
minetest.register_node(":orewood:zincwood", {
	description = "Zincwood",
	tiles = {"default_tree_top.png", "default_tree_top.png", "default_tree.png^technic_mineral_zinc.png"},
	paramtype2 = "facedir",
	is_ground_content = false,
	groups = {orewood_technic=1,orew_zinc=1,tree=1,choppy=2,oddly_breakable_by_hand=1,flammable=2},
	sounds = default.node_sound_wood_defaults(),

	on_place = minetest.rotate_node
})
--hot
minetest.register_node(":orewood:zincwood_hot", {
	description = "Hot Zincwood",
	tiles = {"default_furnace_top.png", "default_furnace_top.png", "default_coal_block.png^technic_zinc_ingot.png"},
	paramtype2 = "facedir",
	is_ground_content = false,
	groups = {orewood_technic=1,orew_hot=1,choppy=2,oddly_breakable_by_hand=1},
	sounds = default.node_sound_wood_defaults(),

	on_place = minetest.rotate_node
})
--fake nodes
minetest.register_node(":orewood:zincwood_fake", {
	description = "Fake Zincwood",
	tiles = {"default_jungletree_top.png", "default_jungletree_top.png", "default_tree.png^technic_mineral_zinc.png"},
	paramtype2 = "facedir",
	is_ground_content = false,
	groups = {orewood_technic=1,orew_fake=1,tree=1,choppy=2,oddly_breakable_by_hand=1,flammable=2},
	sounds = default.node_sound_wood_defaults(),

	on_place = minetest.rotate_node
})
--papy nodes
minetest.register_node(":orewood:zincpapy", {
	description = "Zincpapy",
	drop = "technic:zinc_lump",
	drawtype = "plantlike",
	stack_max = 999,
	tiles = {"technic_zinc_block.png^orewood_cover_mp.png^[makealpha:255,0,255"},
	inventory_image = "technic_zinc_block.png^orewood_cover_mp.png^[makealpha:255,0,255",
	wield_image = "technic_zinc_block.png^orewood_cover_mp.png^[makealpha:255,0,255",
	paramtype = "light",
	walkable = false,
	is_ground_content = true,
	selection_box = {
		type = "fixed",
		fixed = {-0.3, -0.5, -0.3, 0.3, 0.5, 0.3}
	},
	groups = {snappy=3,flammable=2},
	sounds = default.node_sound_leaves_defaults(),

	after_dig_node = function(pos, node, metadata, digger)
		default.dig_up(pos, node, digger)
	end,
})

minetest.register_node(":orewood:zincpapy_ingot", {
	description = "Zincingotpapy",
	drop = "technic:zinc_ingot",
	drawtype = "plantlike",
	stack_max = 999,
	tiles = {"technic_zinc_block.png^orewood_cover_mf.png^[makealpha:255,0,255"},
	inventory_image = "technic_zinc_block.png^orewood_cover_mf.png^[makealpha:255,0,255",
	wield_image = "technic_zinc_block.png^orewood_cover_mf.png^[makealpha:255,0,255",
	paramtype = "light",
	walkable = false,
	is_ground_content = true,
	selection_box = {
		type = "fixed",
		fixed = {-0.3, -0.5, -0.3, 0.3, 0.5, 0.3}
	},
	groups = {snappy=3},
	sounds = default.node_sound_leaves_defaults(),

	after_dig_node = function(pos, node, metadata, digger)
		default.dig_up(pos, node, digger)
	end,
})
--ABMs srpout
minetest.register_abm({
	nodenames = {"orewood:zincwood"},
	neighbors = {"default:water_source"},
	interval = 40,
	chance = 10,
	action = function(pos, node)
	local height = 0
	while node.name == "orewood:zincwood" and height < 4 do
		height = height+1
		pos.y = pos.y+1
		node = minetest.get_node(pos)
	end
	if height == 4
	or node.name ~= "air" then
		return
	end
	minetest.set_node(pos, {name="orewood:zincpapy"})
	end,
})

minetest.register_abm({
	nodenames = {"orewood:zincwood_hot"},
	neighbors = {"default:lava_source"},
	interval = 40,
	chance = 10,
	action = function(pos, node)
	local height = 0
	while node.name == "orewood:zincwood_hot" and height < 4 do
		height = height+1
		pos.y = pos.y+1
		node = minetest.get_node(pos)
	end
	if height == 4
	or node.name ~= "air" then
		return
	end
	minetest.set_node(pos, {name="orewood:zincpapy_ingot"})
	end,
})
--ABMs grow
minetest.register_abm({
	nodenames = {"orewood:zincpapy"},
	neighbors = {"orewood:zincwood"},
	interval = 50,
	chance = 20,
	action = function(pos, node)
	pos.y = pos.y-1
	local name = minetest.get_node(pos).name
	if name ~= "orewood:zincwood"
	and name ~= "orewood:zincwood" then
		return
	end
	if not minetest.find_node_near(pos, 3, {"group:water"}) then
		return
	end
	pos.y = pos.y+1
	local height = 0
	while node.name == "orewood:zincpapy" and height < 4 do
		height = height+1
		pos.y = pos.y+1
		node = minetest.get_node(pos)
	end
	if height == 4
	or node.name ~= "air" then
		return
	end
	minetest.set_node(pos, {name="orewood:zincpapy"})
	return true
end,
})

minetest.register_abm({
	nodenames = {"orewood:zincpapy_ingot"},
	neighbors = {"orewood:zincwood_hot"},
	interval = 50,
	chance = 20,
	action = function(pos, node)
	pos.y = pos.y-1
	local name = minetest.get_node(pos).name
	if name ~= "orewood:zincwood_hot"
	and name ~= "orewood:zincwood_hot" then
		return
	end
	if not minetest.find_node_near(pos, 3, {"group:lava"}) then
		return
	end
	pos.y = pos.y+1
	local height = 0
	while node.name == "orewood:zincpapy_ingot" and height < 4 do
		height = height+1
		pos.y = pos.y+1
		node = minetest.get_node(pos)
	end
	if height == 4
	or node.name ~= "air" then
		return
	end
	minetest.set_node(pos, {name="orewood:zincpapy_ingot"})
	return true
end,
})

-- LEAD
--craft
minetest.register_craft({
	output = '"orewood:leadwood_fake"',
	recipe = {
		{'technic:lead_block', 'technic:lead_block','technic:lead_block'},
		{'technic:lead_block', 'group:orewood_technic','technic:lead_block'},
		{'technic:lead_block', 'technic:lead_block','technic:lead_block'},
	}
})

minetest.register_craft({
	output = '"orewood:leadwood"',
	recipe = {
		{'group:stone', 'group:wood','group:stone'},
		{'group:wood', 'technic:lead_block','group:wood'},
		{'group:stone', 'group:wood','group:stone'},
	}
})
--cook
minetest.register_craft({
	type = "cooking",
	output = "orewood:leadwood_hot",
	recipe = "group:orew_lead",
})
--wooden nodes
minetest.register_node(":orewood:leadwood", {
	description = "Leadwood",
	tiles = {"default_tree_top.png", "default_tree_top.png", "default_tree.png^technic_mineral_lead.png"},
	paramtype2 = "facedir",
	is_ground_content = false,
	groups = {orewood_technic=1,orew_lead=1,tree=1,choppy=2,oddly_breakable_by_hand=1,flammable=2},
	sounds = default.node_sound_wood_defaults(),

	on_place = minetest.rotate_node
})
--hot
minetest.register_node(":orewood:leadwood_hot", {
	description = "Hot Leadwood",
	tiles = {"default_furnace_top.png", "default_furnace_top.png", "default_coal_block.png^technic_lead_ingot.png"},
	paramtype2 = "facedir",
	is_ground_content = false,
	groups = {orewood_technic=1,orew_hot=1,choppy=2,oddly_breakable_by_hand=1},
	sounds = default.node_sound_wood_defaults(),

	on_place = minetest.rotate_node
})
--fake nodes
minetest.register_node(":orewood:leadwood_fake", {
	description = "Fake Leadwood",
	tiles = {"default_jungletree_top.png", "default_jungletree_top.png", "default_tree.png^technic_mineral_lead.png"},
	paramtype2 = "facedir",
	is_ground_content = false,
	groups = {orewood_technic=1,orew_fake=1,tree=1,choppy=2,oddly_breakable_by_hand=1,flammable=2},
	sounds = default.node_sound_wood_defaults(),

	on_place = minetest.rotate_node
})
--papy nodes
minetest.register_node(":orewood:leadpapy", {
	description = "Leadpapy",
	drop = "technic:lead_lump",
	drawtype = "plantlike",
	stack_max = 999,
	tiles = {"technic_lead_block.png^orewood_cover_mp.png^[makealpha:255,0,255"},
	inventory_image = "technic_lead_block.png^orewood_cover_mp.png^[makealpha:255,0,255",
	wield_image = "technic_lead_block.png^orewood_cover_mp.png^[makealpha:255,0,255",
	paramtype = "light",
	walkable = false,
	is_ground_content = true,
	selection_box = {
		type = "fixed",
		fixed = {-0.3, -0.5, -0.3, 0.3, 0.5, 0.3}
	},
	groups = {snappy=3,flammable=2},
	sounds = default.node_sound_leaves_defaults(),

	after_dig_node = function(pos, node, metadata, digger)
		default.dig_up(pos, node, digger)
	end,
})

minetest.register_node(":orewood:leadpapy_ingot", {
	description = "Leadingotpapy",
	drop = "technic:lead_ingot",
	drawtype = "plantlike",
	stack_max = 999,
	tiles = {"technic_lead_block.png^orewood_cover_mf.png^[makealpha:255,0,255"},
	inventory_image = "technic_lead_block.png^orewood_cover_mf.png^[makealpha:255,0,255",
	wield_image = "technic_lead_block.png^orewood_cover_mf.png^[makealpha:255,0,255",
	paramtype = "light",
	walkable = false,
	is_ground_content = true,
	selection_box = {
		type = "fixed",
		fixed = {-0.3, -0.5, -0.3, 0.3, 0.5, 0.3}
	},
	groups = {snappy=3},
	sounds = default.node_sound_leaves_defaults(),

	after_dig_node = function(pos, node, metadata, digger)
		default.dig_up(pos, node, digger)
	end,
})
--ABMs srpout
minetest.register_abm({
	nodenames = {"orewood:leadwood"},
	neighbors = {"default:water_source"},
	interval = 40,
	chance = 10,
	action = function(pos, node)
	local height = 0
	while node.name == "orewood:leadwood" and height < 4 do
		height = height+1
		pos.y = pos.y+1
		node = minetest.get_node(pos)
	end
	if height == 4
	or node.name ~= "air" then
		return
	end
	minetest.set_node(pos, {name="orewood:leadpapy"})
	end,
})

minetest.register_abm({
	nodenames = {"orewood:leadwood_hot"},
	neighbors = {"default:lava_source"},
	interval = 40,
	chance = 10,
	action = function(pos, node)
	local height = 0
	while node.name == "orewood:leadwood_hot" and height < 4 do
		height = height+1
		pos.y = pos.y+1
		node = minetest.get_node(pos)
	end
	if height == 4
	or node.name ~= "air" then
		return
	end
	minetest.set_node(pos, {name="orewood:leadpapy_ingot"})
	end,
})
--ABMs grow
minetest.register_abm({
	nodenames = {"orewood:leadpapy"},
	neighbors = {"orewood:leadwood"},
	interval = 50,
	chance = 20,
	action = function(pos, node)
	pos.y = pos.y-1
	local name = minetest.get_node(pos).name
	if name ~= "orewood:leadwood"
	and name ~= "orewood:leadwood" then
		return
	end
	if not minetest.find_node_near(pos, 3, {"group:water"}) then
		return
	end
	pos.y = pos.y+1
	local height = 0
	while node.name == "orewood:leadpapy" and height < 4 do
		height = height+1
		pos.y = pos.y+1
		node = minetest.get_node(pos)
	end
	if height == 4
	or node.name ~= "air" then
		return
	end
	minetest.set_node(pos, {name="orewood:leadpapy"})
	return true
end,
})

minetest.register_abm({
	nodenames = {"orewood:leadpapy_ingot"},
	neighbors = {"orewood:leadwood_hot"},
	interval = 50,
	chance = 20,
	action = function(pos, node)
	pos.y = pos.y-1
	local name = minetest.get_node(pos).name
	if name ~= "orewood:leadwood_hot"
	and name ~= "orewood:leadwood_hot" then
		return
	end
	if not minetest.find_node_near(pos, 3, {"group:lava"}) then
		return
	end
	pos.y = pos.y+1
	local height = 0
	while node.name == "orewood:leadpapy_ingot" and height < 4 do
		height = height+1
		pos.y = pos.y+1
		node = minetest.get_node(pos)
	end
	if height == 4
	or node.name ~= "air" then
		return
	end
	minetest.set_node(pos, {name="orewood:leadpapy_ingot"})
	return true
end,
})

-- SULFUR
--papy nodes
minetest.register_node(":orewood:sulfurpapy", {
	description = "Sulfurpapy",
	drop = "technic:sulfur_lump",
	drawtype = "plantlike",
	stack_max = 999,
	tiles = {"orewood_dust_yellow.png^orewood_cover_mf.png^[makealpha:255,0,255"},
	inventory_image = "orewood_dust_yellow.png^orewood_cover_mf.png^[makealpha:255,0,255",
	wield_image = "orewood_dust_yellow.png^orewood_cover_mf.png^[makealpha:255,0,255",
	paramtype = "light",
	walkable = false,
	is_ground_content = true,
	selection_box = {
		type = "fixed",
		fixed = {-0.3, -0.5, -0.3, 0.3, 0.5, 0.3}
	},
	groups = {snappy=3},
	sounds = default.node_sound_leaves_defaults(),

	after_dig_node = function(pos, node, metadata, digger)
		default.dig_up(pos, node, digger)
	end,
})
--srpout
minetest.register_abm({
	nodenames = {"orewood:fluidwood"},
	neighbors = {"default:lava_source"},
	interval = 40,
	chance = 10,
	action = function(pos, node)
	local height = 0
	while node.name == "orewood:fluidwood" and height < 4 do
		height = height+1
		pos.y = pos.y+1
		node = minetest.get_node(pos)
	end
	if height == 4
	or node.name ~= "air" then
		return
	end
	minetest.set_node(pos, {name="orewood:sulfurpapy"})
	end,
})
--grow
minetest.register_abm({
	nodenames = {"orewood:sulfurpapy"},
	neighbors = {"orewood:fluidwood"},
	interval = 50,
	chance = 20,
	action = function(pos, node)
	pos.y = pos.y-1
	local name = minetest.get_node(pos).name
	if name ~= "orewood:fluidwood"
	and name ~= "orewood:fluidwood" then
		return
	end
	if not minetest.find_node_near(pos, 3, {"group:lava"}) then
		return
	end
	pos.y = pos.y+1
	local height = 0
	while node.name == "orewood:sulfurpapy" and height < 4 do
		height = height+1
		pos.y = pos.y+1
		node = minetest.get_node(pos)
	end
	if height == 4
	or node.name ~= "air" then
		return
	end
	minetest.set_node(pos, {name="orewood:sulfurpapy"})
	return true
end,
})

-- GRANITE
--craft
minetest.register_craft({
	output = '"technic:granite"',
	recipe = {
		{'orewood:granitepapy', 'orewood:granitepapy','orewood:granitepapy'},
		{'orewood:granitepapy', '','orewood:granitepapy'},
		{'orewood:granitepapy', 'orewood:granitepapy','orewood:granitepapy'},
	}
})
--papy nodes
minetest.register_node(":orewood:granitepapy", {
	description = "Granitepapy",
	drop = "orewood:granitepapy",
	drawtype = "plantlike",
	stack_max = 99,
	tiles = {"technic_granite.png^orewood_cover_mf.png^[makealpha:255,0,255"},
	inventory_image = "technic_granite.png^orewood_cover_mf.png^[makealpha:255,0,255",
	wield_image = "technic_granite.png^orewood_cover_mf.png^[makealpha:255,0,255",
	paramtype = "light",
	walkable = false,
	is_ground_content = true,
	selection_box = {
		type = "fixed",
		fixed = {-0.3, -0.5, -0.3, 0.3, 0.5, 0.3}
	},
	groups = {snappy=3},
	sounds = default.node_sound_leaves_defaults(),

	after_dig_node = function(pos, node, metadata, digger)
		default.dig_up(pos, node, digger)
	end,
})
--srpout
minetest.register_abm({
	nodenames = {"orewood:fluidwood"},
	neighbors = {"default:lava_source"},
	interval = 40,
	chance = 10,
	action = function(pos, node)
	local height = 0
	while node.name == "orewood:fluidwood" and height < 4 do
		height = height+1
		pos.y = pos.y+1
		node = minetest.get_node(pos)
	end
	if height == 4
	or node.name ~= "air" then
		return
	end
	minetest.set_node(pos, {name="orewood:granitepapy"})
	end,
})
--grow
minetest.register_abm({
	nodenames = {"orewood:granitepapy"},
	neighbors = {"orewood:fluidwood"},
	interval = 50,
	chance = 20,
	action = function(pos, node)
	pos.y = pos.y-1
	local name = minetest.get_node(pos).name
	if name ~= "orewood:fluidwood"
	and name ~= "orewood:fluidwood" then
		return
	end
	if not minetest.find_node_near(pos, 3, {"group:lava"}) then
		return
	end
	pos.y = pos.y+1
	local height = 0
	while node.name == "orewood:granitepapy" and height < 4 do
		height = height+1
		pos.y = pos.y+1
		node = minetest.get_node(pos)
	end
	if height == 4
	or node.name ~= "air" then
		return
	end
	minetest.set_node(pos, {name="orewood:granitepapy"})
	return true
end,
})

-- MARBLE
--craft
minetest.register_craft({
	output = '"technic:marble"',
	recipe = {
		{'orewood:marblepapy', 'orewood:marblepapy','orewood:marblepapy'},
		{'orewood:marblepapy', '','orewood:marblepapy'},
		{'orewood:marblepapy', 'orewood:marblepapy','orewood:marblepapy'},
	}
})
--papy nodes
minetest.register_node(":orewood:marblepapy", {
	description = "Marblepapy",
	drop = "orewood:marblepapy",
	drawtype = "plantlike",
	stack_max = 99,
	tiles = {"technic_marble.png^orewood_cover_mf.png^[makealpha:255,0,255"},
	inventory_image = "technic_marble.png^orewood_cover_mf.png^[makealpha:255,0,255",
	wield_image = "technic_marble.png^orewood_cover_mf.png^[makealpha:255,0,255",
	paramtype = "light",
	walkable = false,
	is_ground_content = true,
	selection_box = {
		type = "fixed",
		fixed = {-0.3, -0.5, -0.3, 0.3, 0.5, 0.3}
	},
	groups = {snappy=3},
	sounds = default.node_sound_leaves_defaults(),

	after_dig_node = function(pos, node, metadata, digger)
		default.dig_up(pos, node, digger)
	end,
})
--srpout
minetest.register_abm({
	nodenames = {"orewood:fluidwood"},
	neighbors = {"default:lava_source"},
	interval = 40,
	chance = 10,
	action = function(pos, node)
	local height = 0
	while node.name == "orewood:fluidwood" and height < 4 do
		height = height+1
		pos.y = pos.y+1
		node = minetest.get_node(pos)
	end
	if height == 4
	or node.name ~= "air" then
		return
	end
	minetest.set_node(pos, {name="orewood:marblepapy"})
	end,
})
--grow
minetest.register_abm({
	nodenames = {"orewood:marblepapy"},
	neighbors = {"orewood:fluidwood"},
	interval = 50,
	chance = 20,
	action = function(pos, node)
	pos.y = pos.y-1
	local name = minetest.get_node(pos).name
	if name ~= "orewood:fluidwood"
	and name ~= "orewood:fluidwood" then
		return
	end
	if not minetest.find_node_near(pos, 3, {"group:lava"}) then
		return
	end
	pos.y = pos.y+1
	local height = 0
	while node.name == "orewood:marblepapy" and height < 4 do
		height = height+1
		pos.y = pos.y+1
		node = minetest.get_node(pos)
	end
	if height == 4
	or node.name ~= "air" then
		return
	end
	minetest.set_node(pos, {name="orewood:marblepapy"})
	return true
end,
})

end


code:
all: install

install:
	mkdir -p $(DESTDIR)/usr/share/lider-server
	@cp -rf lider-server/* $(DESTDIR)/usr/share/lider-server
	mkdir -p $(DESTDIR)/usr/share/lider-server/records
	@cp -rf records/* $(DESTDIR)/usr/share/lider-server/records/
	mkdir -p $(DESTDIR)/usr/share/lider-server/etc
	@cp tr.org.liderahenk.example.registration.cfg $(DESTDIR)/usr/share/lider-server/etc/
	mkdir -p $(DESTDIR)/usr/bin
	@cp lider-client $(DESTDIR)/usr/bin/
	@cp lider-sunucu $(DESTDIR)/usr/bin/

uninstall:
	@rm -rf /usr/share/lider-server
	@rm -rf /usr/bin/lider-client
	@rm -rf /usr/bin/lider-sunucu

.PHONY: install uninstall

repo_name: milisarge/lider

path: Makefile

license: unknown


code:
## Milis Linux için Lider-Ahenk Uygulama Çalışması.
https://github.com/farukomercakmak/lider-server adresinden çatallanmıştır.


code:
#!/bin/bash
#ack="guncelleme"
ack=$1
git add .
git commit -a -m "$ack"
git push origin master

path: git-guncelle


code:
#! /bin/bash
case "$1" in
  start)
    echo "Starting server"
    # Start the daemon

    systemctl start lider.service
    ;;
  stop)
    echo "Stopping server"
    systemctl stop lider.service
    ;;
  restart)
    echo "Restarting server"
    systemctl restart lider.service
    ;;
  status)
    echo "Server Status"
    # Status of the daemon
    systemctl status lider.service
    ;;
  *)
    # Refuse to do other stuff
    echo "Usage: /etc/init.d/lider-server {start|stop|restart|status}"
    exit 1
    ;;
esac

exit 0

path: lider


code:
#!/bin/bash
echo "Lider-Server Açılıyor.."
/bin/sh /usr/share/lider-server/bin/client

path: lider-client


code:
#!/bin/sh
#
#    Licensed to the Apache Software Foundation (ASF) under one or more
#    contributor license agreements.  See the NOTICE file distributed with
#    this work for additional information regarding copyright ownership.
#    The ASF licenses this file to You under the Apache License, Version 2.0
#    (the "License"); you may not use this file except in compliance with
#    the License.  You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.
#

realpath() {
  OURPWD=${PWD}
  cd "$(dirname "${1}")" || exit 2
  LINK=$(ls -l "$(basename "${1}")" | awk -F"-> " '{print $2}')
  while [ "${LINK}" ]; do
    cd "$(dirname "${LINK}")" || exit 2
    LINK=$(ls -l "$(basename "${1}")" | awk -F"-> " '{print $2}')
  done
  REALPATH="${PWD}/$(basename "${1}")"
  cd "${OURPWD}" || exit 2
  echo "${REALPATH}"
}

REALNAME=$(realpath "$0")
DIRNAME=$(dirname "${REALNAME}")
PROGNAME=$(basename "${REALNAME}")

#
# Sourcing environment settings for karaf similar to tomcats setenv
#
KARAF_SCRIPT="client"
export KARAF_SCRIPT
if [ -f "$DIRNAME/setenv" ]; then
  . "$DIRNAME/setenv"
fi

#
# Check/Set up some easily accessible MIN/MAX params for JVM mem usage
#
if [ "x$JAVA_MIN_MEM" = "x" ]; then
    JAVA_MIN_MEM=128M
    export JAVA_MIN_MEM
fi
if [ "x$JAVA_MAX_MEM" = "x" ]; then
    JAVA_MAX_MEM=512M
    export JAVA_MAX_MEM
fi

warn() {
    echo "${PROGNAME}: $*"
}

die() {
    warn "$*"
    exit 1
}

detectOS() {
    # OS specific support (must be 'true' or 'false').
    cygwin=false;
    darwin=false;
    aix=false;
    os400=false;
    case "`uname`" in
        CYGWIN*)
            cygwin=true
            ;;
        Darwin*)
            darwin=true
            ;;
        AIX*)
            aix=true
            ;;
        OS400*)
            os400=true
            ;;
    esac
    # For AIX, set an environment variable
    if $aix; then
         export LDR_CNTRL=MAXDATA=0xB0000000@DSA
         echo $LDR_CNTRL
    fi
}

unlimitFD() {
    # Use the maximum available, or set MAX_FD != -1 to use that
    if [ "x$MAX_FD" = "x" ]; then
        MAX_FD="maximum"
    fi

    # Increase the maximum file descriptors if we can
    if [ "$os400" = "false" ] && [ "$cygwin" = "false" ]; then
        MAX_FD_LIMIT=`ulimit -H -n`
        if [ "$MAX_FD_LIMIT" != 'unlimited' ]; then
            if [ $? -eq 0 ]; then
                if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ]; then
                    # use the system max
                    MAX_FD="$MAX_FD_LIMIT"
                fi

                ulimit -n $MAX_FD > /dev/null
                # echo "ulimit -n" `ulimit -n`
                if [ $? -ne 0 ]; then
                    warn "Could not set maximum file descriptor limit: $MAX_FD"
                fi
            else
                warn "Could not query system maximum file descriptor limit: $MAX_FD_LIMIT"
            fi
        fi
    fi
}

locateHome() {
    if [ "x$KARAF_HOME" != "x" ]; then
        warn "Ignoring predefined value for KARAF_HOME"
    fi

    # In POSIX shells, CDPATH may cause cd to write to stdout
    (unset CDPATH) >/dev/null 2>&1 && unset CDPATH

    KARAF_HOME=`cd "$DIRNAME/.."; pwd`
    if [ ! -d "$KARAF_HOME" ]; then
        die "KARAF_HOME is not valid: $KARAF_HOME"
    fi
}

locateBase() {
    if [ "x$KARAF_BASE" != "x" ]; then
        if [ ! -d "$KARAF_BASE" ]; then
            die "KARAF_BASE is not valid: $KARAF_BASE"
        fi
    else
        KARAF_BASE=$KARAF_HOME
    fi
}

locateData() {
    if [ "x$KARAF_DATA" != "x" ]; then
        if [ ! -d "$KARAF_DATA" ]; then
            die "KARAF_DATA is not valid: $KARAF_DATA"
        fi
    else
        KARAF_DATA=$KARAF_BASE/data
    fi
}

locateEtc() {
    if [ "x$KARAF_ETC" != "x" ]; then
        if [ ! -d "$KARAF_ETC" ]; then
            die "KARAF_ETC is not valid: $KARAF_ETC"
        fi
    else
        KARAF_ETC=$KARAF_BASE/etc
    fi
}

setupNativePath() {
    # Support for loading native libraries
    LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:$KARAF_BASE/lib:$KARAF_HOME/lib"

    # For Cygwin, set PATH from LD_LIBRARY_PATH
    if $cygwin; then
        LD_LIBRARY_PATH=`cygpath --path --windows "$LD_LIBRARY_PATH"`
        PATH="$PATH;$LD_LIBRARY_PATH"
        export PATH
    fi
    export LD_LIBRARY_PATH
}

pathCanonical() {
    dst="${1}"
    while [ -h "${dst}" ] ; do
        ls=`ls -ld "${dst}"`
        link=`expr "$ls" : '.*-> \(.*\)$'`
        if expr "$link" : '/.*' > /dev/null; then
            dst="$link"
        else
            dst="`dirname "${dst}"`/$link"
        fi
    done
    bas=`basename "${dst}"`
    dir=`dirname "${dst}"`
    if [ "$bas" != "$dir" ]; then
        dst="`pathCanonical "$dir"`/$bas"
    fi
    echo "${dst}" | sed -e 's#//#/#g' -e 's#/./#/#g' -e 's#/[^/]*/../#/#g'
}

locateJava() {
    # Setup the Java Virtual Machine
    if $cygwin ; then
        [ -n "$JAVA" ] && JAVA=`cygpath --unix "$JAVA"`
        [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
    fi

    if [ "x$JAVA_HOME" = "x" ] && [ "$darwin" = "true" ]; then
        JAVA_HOME="$(/usr/libexec/java_home -v 1.7)"
    fi
    if [ "x$JAVA" = "x" ] && [ -r /etc/gentoo-release ] ; then
        JAVA_HOME=`java-config --jre-home`
    fi
    if [ "x$JAVA" = "x" ]; then
        if [ "x$JAVA_HOME" != "x" ]; then
            if [ ! -d "$JAVA_HOME" ]; then
                die "JAVA_HOME is not valid: $JAVA_HOME"
            fi
            JAVA="$JAVA_HOME/bin/java"
        else
            warn "JAVA_HOME not set; results may vary"
            JAVA=`type java`
            JAVA=`expr "$JAVA" : '.* \(/.*\)$'`
            if [ "x$JAVA" = "x" ]; then
                die "java command not found"
            fi
        fi
    fi
    if [ "x$JAVA_HOME" = "x" ]; then
        JAVA_HOME="$(dirname $(dirname $(pathCanonical "$JAVA")))"
    fi
}

detectJVM() {
   #echo "`$JAVA -version`"
   # This service should call `java -version`,
   # read stdout, and look for hints
   if $JAVA -version 2>&1 | grep "^IBM" ; then
       JVM_VENDOR="IBM"
   # on OS/400, java -version does not contain IBM explicitly
   elif $os400; then
       JVM_VENDOR="IBM"
   else
       JVM_VENDOR="SUN"
   fi
   # echo "JVM vendor is $JVM_VENDOR"
}

setupDefaults() {
    DEFAULT_JAVA_OPTS="-Xms$JAVA_MIN_MEM -Xmx$JAVA_MAX_MEM "

    #Set the JVM_VENDOR specific JVM flags
    if [ "$JVM_VENDOR" = "SUN" ]; then
        # permgen was removed in Java 8
        VERSION=`$JAVA -version 2>&1 | egrep '"([0-9].[0-9]\..*[0-9]).*"' | awk '{print substr($3,2,length($3)-2)}' | awk '{print substr($1, 3, 3)}' | sed -e 's;\.;;g'`
        if [ "$VERSION" -lt "80" ]; then
            # Check some easily accessible MIN/MAX params for JVM mem usage
            if [ "x$JAVA_PERM_MEM" != "x" ]; then
                DEFAULT_JAVA_OPTS="$DEFAULT_JAVA_OPTS -XX:PermSize=$JAVA_PERM_MEM"
            fi
            if [ "x$JAVA_MAX_PERM_MEM" != "x" ]; then
                DEFAULT_JAVA_OPTS="$DEFAULT_JAVA_OPTS -XX:MaxPermSize=$JAVA_MAX_PERM_MEM"
            fi
        fi
        DEFAULT_JAVA_OPTS="-server $DEFAULT_JAVA_OPTS -Dcom.sun.management.jmxremote"
    elif [ "$JVM_VENDOR" = "IBM" ]; then
        if $os400; then
            DEFAULT_JAVA_OPTS="$DEFAULT_JAVA_OPTS"
        elif $aix; then
            DEFAULT_JAVA_OPTS="-Xverify:none -Xdump:heap -Xlp $DEFAULT_JAVA_OPTS"
        else
            DEFAULT_JAVA_OPTS="-Xverify:none $DEFAULT_JAVA_OPTS"
        fi
    fi

    # Add the jars in the lib dir
    CLASSPATH="$KARAF_HOME/system/org/apache/karaf/org.apache.karaf.client/4.0.9/org.apache.karaf.client-4.0.9.jar"
    CLASSPATH="$CLASSPATH:$KARAF_HOME/system/org/apache/sshd/sshd-core/0.14.0/sshd-core-0.14.0.jar"
    CLASSPATH="$CLASSPATH:$KARAF_HOME/system/jline/jline/2.14.1/jline-2.14.1.jar"
    CLASSPATH="$CLASSPATH:$KARAF_HOME/system/org/slf4j/slf4j-api/1.7.12/slf4j-api-1.7.12.jar"

}

init() {
    # Determine if there is special OS handling we must perform
    detectOS

    # Unlimit the number of file descriptors if possible
    unlimitFD

    # Locate the Karaf home directory
    locateHome

    # Locate the Karaf base directory
    locateBase

    # Locate the Karaf data directory
    locateData

    # Locate the Karaf etc directory
    locateEtc

    # Setup the native library path
    setupNativePath

    # Locate the Java VM to execute
    locateJava

    # Determine the JVM vendor
    detectJVM

    # Setup default options
    setupDefaults

}

run() {

    if $cygwin; then
        KARAF_HOME=`cygpath --path --windows "$KARAF_HOME"`
        KARAF_BASE=`cygpath --path --windows "$KARAF_BASE"`
        KARAF_DATA=`cygpath --path --windows "$KARAF_DATA"`
        KARAF_ETC=`cygpath --path --windows "$KARAF_ETC"`
        if [ ! -z "$CLASSPATH" ]; then
            CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
        fi
    fi

    exec "$JAVA" $JAVA_OPTS -Dkaraf.instances="${KARAF_HOME}/instances" -Dkaraf.home="$KARAF_HOME" -Dkaraf.base="$KARAF_BASE" -Dkaraf.etc="$KARAF_ETC" -Djava.io.tmpdir="$KARAF_DATA/tmp" -Djava.util.logging.config.file="$KARAF_BASE/etc/java.util.logging.properties" $KARAF_OPTS $OPTS -classpath "$CLASSPATH" org.apache.karaf.client.Main "$@"
}

main() {
    init
    run "$@"
}

main "$@"

path: lider-server/bin/client


code:
@echo off
rem
rem
rem    Licensed to the Apache Software Foundation (ASF) under one or more
rem    contributor license agreements.  See the NOTICE file distributed with
rem    this work for additional information regarding copyright ownership.
rem    The ASF licenses this file to You under the Apache License, Version 2.0
rem    (the "License"); you may not use this file except in compliance with
rem    the License.  You may obtain a copy of the License at
rem
rem       http://www.apache.org/licenses/LICENSE-2.0
rem
rem    Unless required by applicable law or agreed to in writing, software
rem    distributed under the License is distributed on an "AS IS" BASIS,
rem    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rem    See the License for the specific language governing permissions and
rem    limitations under the License.
rem

if not "%ECHO%" == "" echo %ECHO%

setlocal
set DIRNAME=%~dp0%
set PROGNAME=%~nx0%
set ARGS=%*

rem Sourcing environment settings for karaf similar to tomcats setenv
SET KARAF_SCRIPT="client.bat"
if exist "%DIRNAME%setenv.bat" (
  call "%DIRNAME%setenv.bat"
)

rem Check console window title. Set to Karaf by default
if not "%KARAF_TITLE%" == "" (
    title %KARAF_TITLE%
) else (
    title Karaf
)

rem Check/Set up some easily accessible MIN/MAX params for JVM mem usage
if "%JAVA_MIN_MEM%" == "" (
    set JAVA_MIN_MEM=128M
)
if "%JAVA_MAX_MEM%" == "" (
    set JAVA_MAX_MEM=512M
)

goto BEGIN

:warn
    echo %PROGNAME%: %*
goto :EOF

:BEGIN

rem # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

if not "%KARAF_HOME%" == "" (
    call :warn Ignoring predefined value for KARAF_HOME
)
set KARAF_HOME=%DIRNAME%..
if not exist "%KARAF_HOME%" (
    call :warn KARAF_HOME is not valid: "%KARAF_HOME%"
    goto END
)

if not "%KARAF_BASE%" == "" (
    if not exist "%KARAF_BASE%" (
       call :warn KARAF_BASE is not valid: "%KARAF_BASE%"
       goto END
    )
)
if "%KARAF_BASE%" == "" (
  set "KARAF_BASE=%KARAF_HOME%"
)

if not "%KARAF_DATA%" == "" (
    if not exist "%KARAF_DATA%" (
        call :warn KARAF_DATA is not valid: "%KARAF_DATA%"
        goto END
    )
)
if "%KARAF_DATA%" == "" (
    set "KARAF_DATA=%KARAF_BASE%\data"
)

if not "%KARAF_ETC%" == "" (
    if not exist "%KARAF_ETC%" (
        call :warn KARAF_ETC is not valid: "%KARAF_ETC%"
        goto END
    )
)
if "%KARAF_ETC%" == "" (
    set "KARAF_ETC=%KARAF_BASE%\etc"
)

rem Support for loading native libraries
set PATH=%PATH%;%KARAF_BASE%\lib;%KARAF_HOME%\lib

rem Setup the Java Virtual Machine
if not "%JAVA%" == "" goto :Check_JAVA_END
    set JAVA=java
    if "%JAVA_HOME%" == "" call :warn JAVA_HOME not set; results may vary
    if not "%JAVA_HOME%" == "" set JAVA=%JAVA_HOME%\bin\java
    if not exist "%JAVA_HOME%" (
        call :warn JAVA_HOME is not valid: "%JAVA_HOME%"
        goto END
    )
:Check_JAVA_END

if "%JAVA_OPTS%" == "" set JAVA_OPTS=%DEFAULT_JAVA_OPTS%

if "%EXTRA_JAVA_OPTS%" == "" goto :KARAF_EXTRA_JAVA_OPTS_END
    set JAVA_OPTS=%JAVA_OPTS% %EXTRA_JAVA_OPTS%
:KARAF_EXTRA_JAVA_OPTS_END

set CLASSPATH=%KARAF_HOME%\system\org\apache\karaf\org.apache.karaf.client\4.0.9\org.apache.karaf.client-4.0.9.jar
set CLASSPATH=%CLASSPATH%;%KARAF_HOME%\system\org\apache\sshd\sshd-core\0.14.0\sshd-core-0.14.0.jar
set CLASSPATH=%CLASSPATH%;%KARAF_HOME%\system\jline\jline\2.14.1\jline-2.14.1.jar
set CLASSPATH=%CLASSPATH%;%KARAF_HOME%\system\org\slf4j\slf4j-api\1.7.12\slf4j-api-1.7.12.jar

:EXECUTE
    if "%SHIFT%" == "true" SET ARGS=%2 %3 %4 %5 %6 %7 %8 %9
    if not "%SHIFT%" == "true" SET ARGS=%1 %2 %3 %4 %5 %6 %7 %8 %9
    rem Execute the Java Virtual Machine
    "%JAVA%" %JAVA_OPTS% %OPTS% -classpath "%CLASSPATH%" -Dkaraf.instances="%KARAF_HOME%\instances" -Dkaraf.home="%KARAF_HOME%" -Dkaraf.base="%KARAF_BASE%" -Dkaraf.etc="%KARAF_ETC%" -Djava.io.tmpdir="%KARAF_DATA%\tmp" -Djava.util.logging.config.file="%KARAF_BASE%\etc\java.util.logging.properties" %KARAF_OPTS% org.apache.karaf.client.Main %ARGS%

rem # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

:END

endlocal


code:
#    Licensed to the Apache Software Foundation (ASF) under one or more
#    contributor license agreements.  See the NOTICE file distributed with
#    this work for additional information regarding copyright ownership.
#    The ASF licenses this file to You under the Apache License, Version 2.0
#    (the "License"); you may not use this file except in compliance with
#    the License.  You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.

#
# Karaf Service
#
KARAF_SERVICE_PATH="${KARAF_SERVICE_PATH}"
KARAF_SERVICE_NAME="${KARAF_SERVICE_NAME}"
KARAF_SERVICE_LOG="${KARAF_SERVICE_LOG}"
KARAF_SERVICE_USER="${KARAF_SERVICE_USER}"
KARAF_SERVICE_GROUP="${KARAF_SERVICE_GROUP}"
KARAF_LOCKFILE="/var/lock/subsys/$KARAF_SERVICE_NAME"
KARAF_SERVICE_PIDFILE="${KARAF_SERVICE_PIDFILE}"
KARAF_SERVICE_EXECUTABLE="${KARAF_SERVICE_EXECUTABLE}"
#
# Karaf
#

#
# User
#


code:
#!/bin/sh
#    Licensed to the Apache Software Foundation (ASF) under one or more
#    contributor license agreements.  See the NOTICE file distributed with
#    this work for additional information regarding copyright ownership.
#    The ASF licenses this file to You under the Apache License, Version 2.0
#    (the "License"); you may not use this file except in compliance with
#    the License.  You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.
#
# Karaf control script
# description: Karaf startup script
# processname: ${KARAF_SERVICE_NAME}
# pidfile: ${KARAF_SERVICE_PIDFILE}
# config: ${KARAF_SERVICE_CONF}
#

if [ -r "${KARAF_SERVICE_CONF}" ]; then
    . "${KARAF_SERVICE_CONF}"
else
    echo "Error KARAF_SERVICE_CONF not defined"
    exit -1
fi

# Location of JDK
if [ -n "$JAVA_HOME" ]; then
    export JAVA_HOME
fi

# Setup the JVM
if [ -z "$JAVA" ]; then
    if [ -n "$JAVA_HOME" ]; then
        JAVA="$JAVA_HOME/bin/java"
    else
        JAVA="java"
    fi
fi

if [ -z "$STARTUP_WAIT" ]; then
    STARTUP_WAIT=30
fi

if [ -z "$SHUTDOWN_WAIT" ]; then
    SHUTDOWN_WAIT=30
fi

prog=${KARAF_SERVICE_NAME}

do_start() {
    echo "Starting $prog: "
    if [ -f "$KARAF_SERVICE_PIDFILE" ]; then
        read ppid < "$KARAF_SERVICE_PIDFILE"
        if [ `ps -p $ppid 2> /dev/null | grep -c $ppid 2> /dev/null` -eq '1' ]; then
            echo "$prog is already running"
            return 1
        else
            rm -f "$KARAF_SERVICE_PIDFILE"
        fi
    fi

    LOG_PATH=`dirname "$KARAF_SERVICE_LOG"`
    mkdir -p "$LOG_PATH"
    cat /dev/null > "$KARAF_SERVICE_LOG"
    chown $KARAF_SERVICE_USER:$KARAF_SERVICE_GROUP  "$KARAF_SERVICE_LOG"

    PID_PATH=`dirname "$KARAF_SERVICE_PIDFILE"`
    mkdir -p "$PID_PATH"
    chown $KARAF_SERVICE_USER:$KARAF_SERVICE_GROUP "$PID_PATH" || true

    if [ ! -z "$KARAF_SERVICE_USER" ]; then
        if [ "$KARAF_SERVICE_USER" = "root" ]; then
            KARAF_EXEC=exec
            export KARAF_EXEC

            JAVA_HOME=$JAVA_HOME
            export JAVA_HOME

            "$KARAF_SERVICE_PATH/bin/$KARAF_SERVICE_EXECUTABLE" daemon >> "$KARAF_SERVICE_LOG" 2>&1 &

            echo $! > "$KARAF_SERVICE_PIDFILE"
        else
            su - $KARAF_SERVICE_USER \
                -c " { export KARAF_EXEC=exec; export JAVA_HOME=$JAVA_HOME; \"$KARAF_SERVICE_PATH/bin/$KARAF_SERVICE_EXECUTABLE\" daemon >> \"$KARAF_SERVICE_LOG\" 2>&1 & } ; echo \$! >| \"$KARAF_SERVICE_PIDFILE\" "
        fi

        sleep 1
        if [ -f "$KARAF_SERVICE_PIDFILE" ]; then
            chown $KARAF_SERVICE_USER:$KARAF_SERVICE_GROUP "$KARAF_SERVICE_PIDFILE"
        fi
    fi

    RETVAL=$?
    return $RETVAL
}

do_stop() {
    echo $"Stopping $prog: "
    count=0;

    if [ -f "$KARAF_SERVICE_PIDFILE" ]; then
        read kpid < "$KARAF_SERVICE_PIDFILE"
        kwait=$SHUTDOWN_WAIT

        if [ "$KARAF_SERVICE_USER" = "root" ]; then
            JAVA_HOME=$JAVA_HOME
            export JAVA_HOME

            "$KARAF_SERVICE_PATH/bin/$KARAF_SERVICE_EXECUTABLE" stop >> "$KARAF_SERVICE_LOG" 2>&1
        else
            su - $KARAF_SERVICE_USER \
                -c "export JAVA_HOME=$JAVA_HOME; \"$KARAF_SERVICE_PATH/bin/$KARAF_SERVICE_EXECUTABLE\" stop >> \"$KARAF_SERVICE_LOG\" 2>&1"
        fi

        until [ `ps -p $kpid 2> /dev/null | grep -c $kpid 2> /dev/null` -eq '0' ] || [ $count -gt $kwait ]
        do
            sleep 1
            count=`expr $count + 1`
        done

        if [ $count -gt $kwait ]; then
            if [ `ps -p $kpid 2> /dev/null | grep -c $kpid 2> /dev/null` -eq '1' ]; then
                kill -9 $kpid
            fi
        fi
    fi

    rm -f "$KARAF_SERVICE_PIDFILE"
    rm -f $KARAF_LOCKFILE
}

do_status() {
    if [ -f "$KARAF_SERVICE_PIDFILE" ]; then
        read ppid < "$KARAF_SERVICE_PIDFILE"
        if [ `ps -p $ppid 2> /dev/null | grep -c $ppid 2> /dev/null` -eq '1' ]; then
            echo "$prog is running (pid $ppid)"
            return 0
        else
            echo "$prog dead but pid file exists"
            return 1
        fi
    fi
    echo "$prog is not running"
    return 3
}

case "$1" in
    start)
        do_start
        ;;
    stop)
        do_stop
        ;;
    restart)
        do_stop
        do_start
        ;;
    status)
        do_status
        ;;
    *)
        ## If no parameters are given, print which are avaiable.
        echo "Usage: $0 {start|stop|status|restart}"
        exit 1
        ;;
esac


code:
#!/bin/sh
#    Licensed to the Apache Software Foundation (ASF) under one or more
#    contributor license agreements.  See the NOTICE file distributed with
#    this work for additional information regarding copyright ownership.
#    The ASF licenses this file to You under the Apache License, Version 2.0
#    (the "License"); you may not use this file except in compliance with
#    the License.  You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.
#
# /etc/init.d/${KARAF_SERVICE_NAME} -- startup script for Karaf
#
#
### BEGIN INIT INFO
# Provides:             ${KARAF_SERVICE_NAME}
# Required-Start:       $remote_fs $network
# Required-Stop:        $remote_fs $network
# Should-Start:         $named
# Should-Stop:          $named
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    Karaf
# Description:          Provide Karaf startup/shutdown script
### END INIT INFO

NAME=${KARAF_SERVICE_NAME}
DESC=${KARAF_SERVICE_NAME}
DEFAULT="/etc/default/$NAME"

# Check privileges
if [ `id -u` -ne 0 ]; then
    echo "You need root privileges to run this script"
    exit 1
fi

# Make sure karaf is started with system locale
if [ -r /etc/default/locale ]; then
    . /etc/default/locale
    export LANG
fi

. /lib/lsb/init-functions

if [ -r /etc/default/rcS ]; then
    . /etc/default/rcS
fi

# Overwrite settings from default file
if [ -f "$DEFAULT" ]; then
    . "$DEFAULT"
fi

if [ -r "${KARAF_SERVICE_CONF}" ]; then
    . "${KARAF_SERVICE_CONF}"
else
    echo "Error KARAF_SERVICE_CONF not defined"
    exit -1
fi

# Location of JDK
if [ -n "$JAVA_HOME" ]; then
    export JAVA_HOME
fi

# Setup the JVM
if [ -z "$JAVA" ]; then
    if [ -n "$JAVA_HOME" ]; then
        JAVA="$JAVA_HOME/bin/java"
    else
        JAVA="java"
    fi
fi

# Check karaf user
id $KARAF_SERVICE_USER > /dev/null 2>&1
if [ $? -ne 0 -o -z "$KARAF_SERVICE_USER" ]; then
    echo "User \"$KARAF_SERVICE_USER\" does not exist..." >&2
    exit 1
fi

# Check owner of KARAF_SERVICE_PATH
if [ ! $(stat -L -c "%U" "$KARAF_SERVICE_PATH") = $KARAF_SERVICE_USER ]; then
    echo "The user \"$KARAF_SERVICE_USER\" is not owner of \"$KARAF_SERVICE_PATH\"" >&2
    exit 1
fi

# The amount of time to wait for startup
if [ -z "$STARTUP_WAIT" ]; then
    STARTUP_WAIT=30
fi

# The amount of time to wait for shutdown
if [ -z "$SHUTDOWN_WAIT" ]; then
    SHUTDOWN_WAIT=30
fi

# Helper function to check status of karaf service
check_status() {
    pidofproc -p "$KARAF_SERVICE_PIDFILE" "$JAVA" >/dev/null 2>&1
}

case "$1" in
 start)
    echo "Starting $DESC" "$NAME"

    # PID file
    PID_PATH=$(dirname "$KARAF_SERVICE_PIDFILE")
    if [ ! -d "$PID_PATH" ]; then
        mkdir -p "$PID_PATH"
    fi

    chown $KARAF_SERVICE_USER:$KARAF_SERVICE_GROUP "$PID_PATH" || true

    # Console log
    LOG_PATH=$(dirname "$KARAF_SERVICE_LOG")

    if [ ! -d "$LOG_PATH" ]; then
        mkdir -p "$LOG_PATH"
    fi

    cat /dev/null > "$KARAF_SERVICE_LOG"
    chown $KARAF_SERVICE_USER:$KARAF_SERVICE_GROUP "$LOG_PATH"
    chown $KARAF_SERVICE_USER:$KARAF_SERVICE_GROUP "$KARAF_SERVICE_LOG"

    start-stop-daemon \
        --start \
        --user "$KARAF_SERVICE_USER" \
        --chuid "$KARAF_SERVICE_USER" \
        --chdir "$KARAF_SERVICE_PATH" \
        --pidfile "$KARAF_SERVICE_PIDFILE" \
        --make-pidfile \
        --exec "$KARAF_SERVICE_PATH/bin/$KARAF_SERVICE_EXECUTABLE" -- "daemon" \
    >> "$KARAF_SERVICE_LOG" 2>&1 &

    count=0
    launched=0
    until [ $count -gt $STARTUP_WAIT ]
    do
        sleep 1
        count=$((count + 1));
        if check_status; then
            launched=1
            break
        fi
    done

    if check_status; then
        log_end_msg 0
    else
        log_end_msg 1
    fi

    if [ $launched -eq 0 ]; then
        log_warning_msg "$DESC hasn't started within the timeout allowed"
        log_warning_msg "please review file \"$KARAF_SERVICE_LOG\" to see the status of the service"
    fi
 ;;
 stop)
    check_status
    status_stop=$?
    if [ $status_stop -eq 0 ]; then
        kwait=$SHUTDOWN_WAIT
        read kpid < "$KARAF_SERVICE_PIDFILE"
        log_daemon_msg "Stopping $DESC" "$NAME"

        children_pids=$(pgrep -P $kpid)

        su - $KARAF_SERVICE_USER \
            -c "export JAVA_HOME=$JAVA_HOME; \"$KARAF_SERVICE_PATH/bin/$KARAF_SERVICE_EXECUTABLE\" stop"

        count=0
        until [ `ps --pid $kpid 2> /dev/null | grep -c $kpid 2> /dev/null` -eq '0' ] || [ $count -gt $kwait ]
        do
            sleep 1
            count=$((count + 1));
        done

        if check_status; then
            start-stop-daemon \
                --stop \
                --quiet \
                --pidfile "$KARAF_SERVICE_PIDFILE" \
                --user "$KARAF_SERVICE_USER" \
                --retry=TERM/$SHUTDOWN_WAIT/KILL/5 \
            > /dev/null 2>&1

            if [ $? -eq 2 ]; then
                log_failure_msg "$DESC can't be stopped"
                exit 1
            fi
        fi

        for child in $children_pids; do
            /bin/kill -9 $child >/dev/null 2>&1
        done

        log_end_msg 0

        rm -rf "$KARAF_SERVICE_PIDFILE"
    elif [ $status_stop -eq 1 ]; then
        log_action_msg "$DESC is not running but the pid file exists, cleaning up"
        rm -f "$KARAF_SERVICE_PIDFILE"
    elif [ $status_stop -eq 3 ]; then
        log_action_msg "$DESC is not running"
    fi
 ;;
 restart)
    check_status
    status_restart=$?
    if [ $status_restart -eq 0 ]; then
        $0 stop
    fi
    $0 start
 ;;
 status)
    check_status
    status=$?
    if [ $status -eq 0 ]; then
        read pid < $KARAF_SERVICE_PIDFILE
        log_action_msg "$DESC is running with pid $pid"
        exit 0
    elif [ $status -eq 1 ]; then
        log_action_msg "$DESC is not running and the pid file exists"
        exit 1
    elif [ $status -eq 3 ]; then
        log_action_msg "$DESC is not running"
        exit 3
    else
        log_action_msg "Unable to determine $DESC status"
        exit 4
    fi
 ;;
 *)
 log_action_msg "Usage: $0 {start|stop|restart|status}"
 exit 2
 ;;
esac

exit 0


code:
#!/bin/sh
#    Licensed to the Apache Software Foundation (ASF) under one or more
#    contributor license agreements.  See the NOTICE file distributed with
#    this work for additional information regarding copyright ownership.
#    The ASF licenses this file to You under the Apache License, Version 2.0
#    (the "License"); you may not use this file except in compliance with
#    the License.  You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.
#
# Karaf control script
#
# chkconfig: - 80 20
# description: Karaf startup script
# processname: ${KARAF_SERVICE_NAME}
# pidfile: ${KARAF_SERVICE_PIDFILE}
# config: ${KARAF_SERVICE_CONF}
#

# Source function library.
. /etc/init.d/functions

# Load Java configuration.
[ -r /etc/java/java.conf ] && . /etc/java/java.conf
export JAVA_HOME

if [ -r "${KARAF_SERVICE_CONF}" ]; then
    . "${KARAF_SERVICE_CONF}"
else
    echo "Error KARAF_SERVICE_CONF not defined"
    exit -1
fi

if [ -z "$STARTUP_WAIT" ]; then
    STARTUP_WAIT=30
fi

if [ -z "$SHUTDOWN_WAIT" ]; then
    SHUTDOWN_WAIT=30
fi

prog=${KARAF_SERVICE_NAME}
currenttime=$(date +%s%N | cut -b1-13)

start() {
    echo -n "Starting $prog: "
    if [ -f "$KARAF_SERVICE_PIDFILE" ]; then
        read ppid < "$KARAF_SERVICE_PIDFILE"
        if [ `ps --pid $ppid 2> /dev/null | grep -c $ppid 2> /dev/null` -eq '1' ]; then
            echo -n "$prog is already running"
            failure
            echo
            return 1
        else
            rm -f "$KARAF_SERVICE_PIDFILE"
        fi
    fi

    LOG_PATH=`dirname "$KARAF_SERVICE_LOG"`
    mkdir -p "$LOG_PATH"
    cat /dev/null > "$KARAF_SERVICE_LOG"
    chown $KARAF_SERVICE_USER:$KARAF_SERVICE_GROUP  "$KARAF_SERVICE_LOG"

    PID_PATH=`dirname "$KARAF_SERVICE_PIDFILE"`
    mkdir -p "$PID_PATH"
    chown $KARAF_SERVICE_USER:$KARAF_SERVICE_GROUP "$PID_PATH" || true

    if [ ! -z "$KARAF_SERVICE_USER" ]; then
        if [ -r /etc/rc.d/init.d/functions ]; then
            daemon \
                --user="$KARAF_SERVICE_USER" \
                --pidfile="$KARAF_SERVICE_PIDFILE" \
                " { \"$KARAF_SERVICE_PATH/bin/$KARAF_SERVICE_EXECUTABLE\" daemon >> \"$KARAF_SERVICE_LOG\" 2>&1 & } ; echo \$! >| \"$KARAF_SERVICE_PIDFILE\" "
        else
            su - $KARAF_SERVICE_USER \
                -c " { \"$KARAF_SERVICE_PATH/bin/$KARAF_SERVICE_EXECUTABLE\" daemon >> \"$KARAF_SERVICE_LOG\" 2>&1 & } ; echo \$! >| \"$KARAF_SERVICE_PIDFILE\" "
        fi

        if [ -f "$KARAF_SERVICE_PIDFILE" ]; then
            chown $KARAF_SERVICE_USER:$KARAF_SERVICE_GROUP "$KARAF_SERVICE_PIDFILE"
        fi
    fi

    RETVAL=$?
    echo

    if [ $RETVAL -eq 0 ]; then
        touch $KARAF_LOCKFILE
    fi

    return $RETVAL
}

stop() {
    echo -n $"Stopping $prog: "
    count=0;

    if [ -f "$KARAF_SERVICE_PIDFILE" ]; then
        read kpid < "$KARAF_SERVICE_PIDFILE"
        let kwait=$SHUTDOWN_WAIT

        # Try issuing SIGTERM
        su - $KARAF_SERVICE_USER \
            -c "export JAVA_HOME=$JAVA_HOME; \"$KARAF_SERVICE_PATH/bin/$KARAF_SERVICE_EXECUTABLE\" stop"

        until [ `ps --pid $kpid 2> /dev/null | grep -c $kpid 2> /dev/null` -eq '0' ] || [ $count -gt $kwait ]
        do
            sleep 1
            let count=$count+1;
        done

        if [ $count -gt $kwait ]; then
            kill -9 $kpid
        fi
    fi

    rm -f "$KARAF_SERVICE_PIDFILE"
    rm -f "$KARAF_LOCKFILE"

    success
    echo
}

status() {
    if [ -f "$KARAF_SERVICE_PIDFILE" ]; then
        read ppid < "$KARAF_SERVICE_PIDFILE"
        if [ `ps --pid $ppid 2> /dev/null | grep -c $ppid 2> /dev/null` -eq '1' ]; then
            echo "$prog is running (pid $ppid)"
            return 0
        else
            echo "$prog dead but pid file exists"
            return 1
        fi
    fi
    echo "$prog is not running"
    return 3
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        $0 stop
        $0 start
        ;;
    status)
        status
        ;;
    *)
        ## If no parameters are given, print which are avaiable.
        echo "Usage: $0 {start|stop|status|restart}"
        exit 1
        ;;
esac


code:
<?xml version="1.0" ?>
<!--

    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
    The ASF licenses this file to You under the Apache License, Version 2.0
    (the "License"); you may not use this file except in compliance with
    the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->

<!DOCTYPE service_bundle
  SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'>

<service_bundle type="manifest" name="application/${KARAF_SERVICE_NAME}">
    <service version="1" type="service" name="application/${KARAF_SERVICE_NAME}">

        <create_default_instance enabled='false' />
        <single_instance />

        <dependency
            restart_on="none"
            type="service"
            name="multi_user_dependency"
            grouping="require_all">

            <service_fmri value="svc:/milestone/multi-user"/>
        </dependency>

        <method_context>
            <method_credential user='${KARAF_SERVICE_USER}' group='${KARAF_SERVICE_GROUP}'/>
            <method_environment>
                <envvar name="JAVA_HOME" value="${JAVA_HOME}"/>
            </method_environment>
        </method_context>

        <!-- *************************************************************** -->
        <!-- STOP/START                                                      -->
        <!-- *************************************************************** -->

        <exec_method
            timeout_seconds="60"
            type="method"
            name="start"
            exec="${KARAF_SERVICE_PATH}/bin/${KARAF_SERVICE_EXECUTABLE} daemon &">
        </exec_method>

        <exec_method
            timeout_seconds="60"
            type="method"
            name="stop"
            exec="${KARAF_SERVICE_PATH}/bin/${KARAF_SERVICE_EXECUTABLE} stop">
        </exec_method>

        <!-- *************************************************************** -->
        <!--                                                                 -->
        <!-- *************************************************************** -->

        <!-- do not restart the service in case of errors -->
        <property_group name='startd' type='framework'>
            <propval name='duration'
                     type='astring'
                     value='transient'/>
            <propval name='ignore_error'
                     type='astring'
                     value='core,signal'/>
        </property_group>

        <stability value='Evolving' />

        <template>
            <common_name>
                <loctext xml:lang="C">
                    ${KARAF_SERVICE_NAME}
                </loctext>
            </common_name>
            <description>
                <loctext xml:lang="C">
                    ${KARAF_SERVICE_NAME}
                </loctext>
            </description>
        </template>

    </service>
</service_bundle>


code:
#
#    Licensed to the Apache Software Foundation (ASF) under one or more
#    contributor license agreements.  See the NOTICE file distributed with
#    this work for additional information regarding copyright ownership.
#    The ASF licenses this file to You under the Apache License, Version 2.0
#    (the "License"); you may not use this file except in compliance with
#    the License.  You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.
#

[Unit]
Description=Karaf - ${KARAF_SERVICE_NAME}
After=syslog.target network.target

[Service]
EnvironmentFile=${KARAF_SERVICE_CONF}

ExecStart=${KARAF_SERVICE_PATH}/bin/${KARAF_SERVICE_EXECUTABLE} daemon
ExecStop=${KARAF_SERVICE_PATH}/bin/${KARAF_SERVICE_EXECUTABLE} stop

User=${KARAF_SERVICE_USER}
Group=${KARAF_SERVICE_GROUP}

SuccessExitStatus=0 143
RestartSec=15
Restart=on-failure

LimitNOFILE=102642

[Install]
WantedBy=multi-user.target


code:
#
#    Licensed to the Apache Software Foundation (ASF) under one or more
#    contributor license agreements.  See the NOTICE file distributed with
#    this work for additional information regarding copyright ownership.
#    The ASF licenses this file to You under the Apache License, Version 2.0
#    (the "License"); you may not use this file except in compliance with
#    the License.  You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.
#

[Unit]
Description=Karaf - ${KARAF_SERVICE_NAME} - %i
After=syslog.target network.target
Requires=${KARAF_SERVICE_NAME}.service

[Service]
EnvironmentFile=-${KARAF_SERVICE_PATH}/etc/${KARAF_SERVICE_NAME}-%i.conf
EnvironmentFile=-${KARAF_SERVICE_PATH}/instances/%i/etc/${KARAF_SERVICE_NAME}.conf
Environment=KARAF_HOME=${KARAF_SERVICE_PATH}
Environment=KARAF_BASE=${KARAF_SERVICE_PATH}/instances/%i

ExecStart=${KARAF_SERVICE_PATH}/bin/${KARAF_SERVICE_EXECUTABLE} daemon
ExecStop=${KARAF_SERVICE_PATH}/bin/${KARAF_SERVICE_EXECUTABLE} stop

User=${KARAF_SERVICE_USER}
Group=${KARAF_SERVICE_GROUP}

SuccessExitStatus=0 1 143
RestartSec=15
Restart=on-failure

LimitNOFILE=102642

[Install]
WantedBy=multi-user.target


code:
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<service>

  <!--
    This script is provided as a template you can quckly customize by replacing
    the following variables:

      KARAF_SERVICE_NAME
      KARAF_SERVICE_PATH
      KARAF_SERVICE_EXECUTABLE

    For a detailed overview of the confguration options, please visit winsw home
    page (https://github.com/kohsuke/winsw)
  -->

  <id>%KARAF_SERVICE_NAME%</id>
  <name>%KARAF_SERVICE_NAME%</name>
  <description>Apache Karaf %KARAF_SERVICE_NAME%</description>

  <!-- start -->
  <executable>%KARAF_SERVICE_PATH%\bin\%KARAF_SERVICE_EXECUTABLE%</executable>
  <startargument>daemon</startargument>

  <!-- stop -->
  <stopexecutable>%KARAF_SERVICE_PATH%\bin\%KARAF_SERVICE_EXECUTABLE%</stopexecutable>
  <stopargument>stop</stopargument>
  <stoptimeout>10sec</stoptimeout>

  <!-- logging -->
  <logpath>%KARAF_SERVICE_PATH%\data\log</logpath>
  <log mode="roll-by-time">
    <pattern>yyyyMMdd</pattern>
  </log>

</service>


code:
#!/usr/bin/env bash
#
#    Licensed to the Apache Software Foundation (ASF) under one or more
#    contributor license agreements.  See the NOTICE file distributed with
#    this work for additional information regarding copyright ownership.
#    The ASF licenses this file to You under the Apache License, Version 2.0
#    (the "License"); you may not use this file except in compliance with
#    the License.  You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.
#

function usage {
    cat <<-END >&2
    USAGE: $0
        -k KARAF_SERVICE_PATH       # Karaf installation path
        -d KARAF_SERVICE_DATA       # Karaf data path (default to \${KARAF_SERVICE_PATH}/data)
        -c KARAF_SERVICE_CONF       # Karaf configuration file (default to \${KARAF_SERVICE_PATH/etc/\${KARAF_SERVICE_NAME}.conf
        -t KARAF_SERVICE_ETC        # Karaf etc path (default to \${KARAF_SERVICE_PATH/etc}
        -p KARAF_SERVICE_PIDFILE    # Karaf pid path (default to \${KARAF_SERVICE_DATA}/\${KARAF_SERVICE_NAME}.pid)
        -n KARAF_SERVICE_NAME       # Karaf service name (default karaf)
        -e KARAF_ENV                # Karaf environment variable (can be repeated)
        -u KARAF_SERVICE_USER       # Karaf user
        -g KARAF_SERVICE_GROUP      # Karaf group (default \${KARAF_SERVICE_USER)
        -l KARAF_SERVICE_LOG        # Karaf console log (default to \${KARAF_SERVICE_DATA}/log/\${KARAF_SERVICE_NAME}-console.log)
        -f KARAF_SERVICE_TEMPLATE   # Template file to use
        -x KARAF_SERVICE_EXECUTABLE # Karaf executable name (defaul karaf, should support daemon and stop commands)
        -h                          # this usage message
END
    exit
}

CONF_TEMPLATE="karaf-service-template.conf"
SYSTEMD_TEMPLATE="karaf-service-template.systemd"
SYSTEMD_TEMPLATE_INSTANCES="karaf-service-template.systemd-instances"
INIT_TEMPLATE="karaf-service-template.init"
INIT_REDHAT_TEMPLATE="karaf-service-template.init-redhat"
INIT_DEBIAN_TEMPLATE="karaf-service-template.init-debian"
SOLARIS_SMF_TEMPLATE="karaf-service-template.solaris-smf"

################################################################################
#
################################################################################

KARAF_ENV=()

while getopts k:d:c:p:n:u:g:l:t:e:f:x:h opt
do
    case $opt in
    k)  export KARAF_SERVICE_PATH="$OPTARG" ;;
    d)  export KARAF_SERVICE_DATA="$OPTARG" ;;
    c)  export KARAF_SERVICE_CONF="$OPTARG" ;;
    p)  export KARAF_SERVICE_PIDFILE="$OPTARG" ;;
    n)  export KARAF_SERVICE_NAME="$OPTARG" ;;
    u)  export KARAF_SERVICE_USER="$OPTARG" ;;
    g)  export KARAF_SERVICE_GROUP="$OPTARG" ;;
    l)  export KARAF_SERVICE_LOG="$OPTARG" ;;
    t)  export KARAF_SERVICE_ETC="$OPTARG" ;;
    f)  export KARAF_SERVICE_TEMPLATE="$OPTARG" ;;
    x)  export KARAF_SERVICE_EXECUTABLE="$OPTARG" ;;
    e)  KARAF_ENV+=("$OPTARG") ;;
    h|?) usage ;;
    esac
done

shift $(( $OPTIND - 1 ))

if [[ ! $KARAF_SERVICE_PATH ]]; then
    echo "Warning, KARAF_SERVICE_PATH is required"
    usage
fi

if [[ ! $KARAF_SERVICE_DATA ]]; then
    export KARAF_SERVICE_DATA="${KARAF_SERVICE_PATH}/data"
fi

if [[ ! $KARAF_SERVICE_ETC ]]; then
    export KARAF_SERVICE_ETC="${KARAF_SERVICE_PATH}/etc"
fi

if [[ ! $KARAF_SERVICE_NAME ]]; then
    export KARAF_SERVICE_NAME="karaf"
fi

if [[ ! $KARAF_SERVICE_CONF ]]; then
    export KARAF_SERVICE_CONF="${KARAF_SERVICE_PATH}/etc/${KARAF_SERVICE_NAME}.conf"
fi

if [[ ! $KARAF_SERVICE_PIDFILE ]]; then
    export KARAF_SERVICE_PIDFILE="${KARAF_SERVICE_DATA}/${KARAF_SERVICE_NAME}.pid"
fi

if [[ ! $KARAF_SERVICE_LOG ]]; then
    export KARAF_SERVICE_LOG="${KARAF_SERVICE_DATA}/log/${KARAF_SERVICE_NAME}-console.log"
fi

if [[ ! $KARAF_SERVICE_USER ]]; then
    export KARAF_SERVICE_USER="root"
fi

if [[ ! $KARAF_SERVICE_GROUP ]]; then
    export KARAF_SERVICE_GROUP="${KARAF_SERVICE_USER}"
fi

if [[ ! $KARAF_SERVICE_EXECUTABLE ]]; then
    export KARAF_SERVICE_EXECUTABLE="karaf"
fi

################################################################################
#
################################################################################

function generate_service_descriptor {
    echo "Writing service file \"$2\""
    perl -p -e 's/\$\{([^}]+)\}/defined $ENV{$1} ? $ENV{$1} : $&/eg' < "$1" > "$2"

    if [ $# -eq 4 ]; then
        echo "Writing service configuration file \"$4\""
        perl -p -e 's/\$\{([^}]+)\}/defined $ENV{$1} ? $ENV{$1} : $&/eg' < "$3" > "$4"

        for var in "${KARAF_ENV[@]}"; do
          echo "${var}" >> "$4"
        done
    fi
}

################################################################################
#
################################################################################

if [[ ! $KARAF_SERVICE_TEMPLATE ]]; then
    case $(uname | tr [:upper:] [:lower:]) in
        sunos)
            # add KARAF_ENV vars to envirioment
            for var in "${KARAF_ENV[@]}"; do
                export $var
            done

            # Default java path if not set
            if [[ ! $JAVA_HOME ]]; then
                export JAVA_HOME=/usr/java
            fi

            # escape spaces in path
            export KARAF_SERVICE_PATH="$(echo $KARAF_SERVICE_PATH | sed 's/ /\\ /g')"
            export KARAF_SERVICE_DATA="$(echo $KARAF_SERVICE_DATA | sed 's/ /\\ /g')"
            export KARAF_SERVICE_CONF="$(echo $KARAF_SERVICE_CONF | sed 's/ /\\ /g')"
            export KARAF_SERVICE_PIDFILE="$(echo $KARAF_SERVICE_PIDFILE | sed 's/ /\\ /g')"

            generate_service_descriptor \
                "$SOLARIS_SMF_TEMPLATE" \
                "${PWD}/${KARAF_SERVICE_NAME}.xml"
            ;;
        linux)
            if [ -d /run/systemd/system ]; then
                generate_service_descriptor \
                    "$SYSTEMD_TEMPLATE" \
                    "${PWD}/${KARAF_SERVICE_NAME}.service" \
                    "${CONF_TEMPLATE}" \
                    "${KARAF_SERVICE_CONF}"

                generate_service_descriptor \
                    "$SYSTEMD_TEMPLATE_INSTANCES" \
                    "${PWD}/${KARAF_SERVICE_NAME}@.service"

            elif [ -f /etc/redhat-release ]; then
                generate_service_descriptor \
                    "$INIT_REDHAT_TEMPLATE" \
                    "${PWD}/${KARAF_SERVICE_NAME}" \
                    "${CONF_TEMPLATE}" \
                    "${KARAF_SERVICE_CONF}"

                chmod 755 "${PWD}/${KARAF_SERVICE_NAME}"
            elif [ -f /etc/debian-release ] || [ -f /etc/debian_version ]; then
                generate_service_descriptor \
                    "$INIT_DEBIAN_TEMPLATE" \
                    "${PWD}/${KARAF_SERVICE_NAME}" \
                    "${CONF_TEMPLATE}" \
                    "${KARAF_SERVICE_CONF}"

                chmod 755 "${PWD}/${KARAF_SERVICE_NAME}"
            fi
            ;;
        *)
            generate_service_descriptor \
                "$INIT_TEMPLATE" \
                "${PWD}/${KARAF_SERVICE_NAME}" \
                "${CONF_TEMPLATE}" \
                "${KARAF_SERVICE_CONF}"

            chmod 755 "${PWD}/${KARAF_SERVICE_NAME}"
            ;;
    esac
else
    generate_service_descriptor \
        "$KARAF_SERVICE_TEMPLATE" \
        "${PWD}/${KARAF_SERVICE_NAME}" \
        "${CONF_TEMPLATE}" \
        "${KARAF_SERVICE_CONF}"
fi


code:
#!/bin/sh
#
#    Licensed to the Apache Software Foundation (ASF) under one or more
#    contributor license agreements.  See the NOTICE file distributed with
#    this work for additional information regarding copyright ownership.
#    The ASF licenses this file to You under the Apache License, Version 2.0
#    (the "License"); you may not use this file except in compliance with
#    the License.  You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.
#

realpath() {
  READLINK_EXISTS=$(command -v readlink &> /dev/null)
  if [ -z $READLINK_EXISTS ]; then
    OURPWD=${PWD}
    cd "$(dirname "${1}")" || exit 2
    LINK=$(ls -l "$(basename "${1}")" | awk -F"-> " '{print $2}')
    while [ "${LINK}" ]; do
        echo "link: ${LINK}" >&2
        cd "$(dirname "${LINK}")" || exit 2
        LINK=$(ls -l "$(basename "${1}")" | awk -F"-> " '{print $2}')
    done
    REALPATH="${PWD}/$(basename "${1}")"
    cd "${OURPWD}" || exit 2
    echo "${REALPATH}"
  else
    OURPWD=${PWD}
    cd "$(dirname "${1}")" || exit 2
    LINK=$(readlink "$(basename "${1}")")
    while [ "${LINK}" ]; do
	    echo "link: ${LINK}" >&2
        cd "$(dirname "${LINK}")" || exit 2
        LINK=$(readlink "$(basename "${1}")")
    done
    REALPATH="${PWD}/$(basename "${1}")"
    cd "${OURPWD}" || exit 2
    echo "${REALPATH}"
  fi
}

REALNAME=$(realpath "$0")
DIRNAME=$(dirname "${REALNAME}")
PROGNAME=$(basename "${REALNAME}")

#
# Sourcing environment settings for karaf similar to tomcats setenv
#
KARAF_SCRIPT="instance"
export KARAF_SCRIPT
if [ -f "$DIRNAME/setenv" ]; then
  . "$DIRNAME/setenv"
fi

#
# Check/Set up some easily accessible MIN/MAX params for JVM mem usage
#
if [ "x$JAVA_MIN_MEM" = "x" ]; then
    JAVA_MIN_MEM=128M
    export JAVA_MIN_MEM
fi
if [ "x$JAVA_MAX_MEM" = "x" ]; then
    JAVA_MAX_MEM=512M
    export JAVA_MAX_MEM
fi

warn() {
    echo "${PROGNAME}: $*"
}

die() {
    warn "$*"
    exit 1
}

detectOS() {
    # OS specific support (must be 'true' or 'false').
    cygwin=false;
    darwin=false;
    aix=false;
    os400=false;
    case "`uname`" in
        CYGWIN*)
            cygwin=true
            ;;
        Darwin*)
            darwin=true
            ;;
        AIX*)
            aix=true
            ;;
        OS400*)
            os400=true
            ;;
    esac
    # For AIX, set an environment variable
    if $aix; then
         export LDR_CNTRL=MAXDATA=0xB0000000@DSA
         echo $LDR_CNTRL
    fi
}

unlimitFD() {
    # Use the maximum available, or set MAX_FD != -1 to use that
    if [ "x$MAX_FD" = "x" ]; then
        MAX_FD="maximum"
    fi

    # Increase the maximum file descriptors if we can
    if [ "$os400" = "false" ] && [ "$cygwin" = "false" ]; then
        MAX_FD_LIMIT=`ulimit -H -n`
        if [ "$MAX_FD_LIMIT" != 'unlimited' ]; then
            if [ $? -eq 0 ]; then
                if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ]; then
                    # use the system max
                    MAX_FD="$MAX_FD_LIMIT"
                fi

                ulimit -n $MAX_FD > /dev/null
                # echo "ulimit -n" `ulimit -n`
                if [ $? -ne 0 ]; then
                    warn "Could not set maximum file descriptor limit: $MAX_FD"
                fi
            else
                warn "Could not query system maximum file descriptor limit: $MAX_FD_LIMIT"
            fi
        fi
    fi
}

locateHome() {
    if [ "x$KARAF_HOME" != "x" ]; then
        warn "Ignoring predefined value for KARAF_HOME"
    fi

    # In POSIX shells, CDPATH may cause cd to write to stdout
    (unset CDPATH) >/dev/null 2>&1 && unset CDPATH

    KARAF_HOME=`cd "$DIRNAME/.."; pwd`
    if [ ! -d "$KARAF_HOME" ]; then
        die "KARAF_HOME is not valid: $KARAF_HOME"
    fi
}

locateBase() {
    if [ "x$KARAF_BASE" != "x" ]; then
        if [ ! -d "$KARAF_BASE" ]; then
            die "KARAF_BASE is not valid: $KARAF_BASE"
        fi
    else
        KARAF_BASE=$KARAF_HOME
    fi
}

locateData() {
    if [ "x$KARAF_DATA" != "x" ]; then
        if [ ! -d "$KARAF_DATA" ]; then
            die "KARAF_DATA is not valid: $KARAF_DATA"
        fi
    else
        KARAF_DATA=$KARAF_BASE/data
    fi
}

locateEtc() {
    if [ "x$KARAF_ETC" != "x" ]; then
        if [ ! -d "$KARAF_ETC" ]; then
            die "KARAF_ETC is not valid: $KARAF_ETC"
        fi
    else
        KARAF_ETC=$KARAF_BASE/etc
    fi
}

setupNativePath() {
    # Support for loading native libraries
    LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:$KARAF_BASE/lib:$KARAF_HOME/lib"

    # For Cygwin, set PATH from LD_LIBRARY_PATH
    if $cygwin; then
        LD_LIBRARY_PATH=`cygpath --path --windows "$LD_LIBRARY_PATH"`
        PATH="$PATH;$LD_LIBRARY_PATH"
        export PATH
    fi
    export LD_LIBRARY_PATH
}

pathCanonical() {
    dst="${1}"
    while [ -h "${dst}" ] ; do
        ls=`ls -ld "${dst}"`
        link=`expr "$ls" : '.*-> \(.*\)$'`
        if expr "$link" : '/.*' > /dev/null; then
            dst="$link"
        else
            dst="`dirname "${dst}"`/$link"
        fi
    done
    bas=`basename "${dst}"`
    dir=`dirname "${dst}"`
    if [ "$bas" != "$dir" ]; then
        dst="`pathCanonical "$dir"`/$bas"
    fi
    echo "${dst}" | sed -e 's#//#/#g' -e 's#/./#/#g' -e 's#/[^/]*/../#/#g'
}

locateJava() {
    # Setup the Java Virtual Machine
    if $cygwin ; then
        [ -n "$JAVA" ] && JAVA=`cygpath --unix "$JAVA"`
        [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
    fi

    if [ "x$JAVA_HOME" = "x" ] && [ "$darwin" = "true" ]; then
        JAVA_HOME="$(/usr/libexec/java_home -v 1.7)"
    fi
    if [ "x$JAVA" = "x" ] && [ -r /etc/gentoo-release ] ; then
        JAVA_HOME=`java-config --jre-home`
    fi
    if [ "x$JAVA" = "x" ]; then
        if [ "x$JAVA_HOME" != "x" ]; then
            if [ ! -d "$JAVA_HOME" ]; then
                die "JAVA_HOME is not valid: $JAVA_HOME"
            fi
            JAVA="$JAVA_HOME/bin/java"
        else
            warn "JAVA_HOME not set; results may vary"
            JAVA=`type java`
            JAVA=`expr "$JAVA" : '.* \(/.*\)$'`
            if [ "x$JAVA" = "x" ]; then
                die "java command not found"
            fi
        fi
    fi
    if [ "x$JAVA_HOME" = "x" ]; then
        JAVA_HOME="$(dirname $(dirname $(pathCanonical "$JAVA")))"
    fi
}

detectJVM() {
   #echo "`$JAVA -version`"
   # This service should call `java -version`,
   # read stdout, and look for hints
   if $JAVA -version 2>&1 | grep "^IBM" ; then
       JVM_VENDOR="IBM"
   # on OS/400, java -version does not contain IBM explicitly
   elif $os400; then
       JVM_VENDOR="IBM"
   else
       JVM_VENDOR="SUN"
   fi
   # echo "JVM vendor is $JVM_VENDOR"
}

setupDebugOptions() {
    if [ "x$JAVA_OPTS" = "x" ]; then
        JAVA_OPTS="$DEFAULT_JAVA_OPTS"
    fi
    export JAVA_OPTS

    if [ "x$EXTRA_JAVA_OPTS" != "x" ]; then
        JAVA_OPTS="$JAVA_OPTS $EXTRA_JAVA_OPTS"
    fi

    # Set Debug options if enabled
    if [ "x$KARAF_DEBUG" != "x" ]; then
        # Use the defaults if JAVA_DEBUG_OPTS was not set
        if [ "x$JAVA_DEBUG_OPTS" = "x" ]; then
            JAVA_DEBUG_OPTS="$DEFAULT_JAVA_DEBUG_OPTS"
        fi

        JAVA_OPTS="$JAVA_DEBUG_OPTS $JAVA_OPTS"
        warn "Enabling Java debug options: $JAVA_DEBUG_OPTS"
    fi
}

setupDefaults() {
    DEFAULT_JAVA_OPTS="-Xms$JAVA_MIN_MEM -Xmx$JAVA_MAX_MEM "

    #Set the JVM_VENDOR specific JVM flags
    if [ "$JVM_VENDOR" = "SUN" ]; then
        # permgen was removed in Java 8
        VERSION=`$JAVA -version 2>&1 | egrep '"([0-9].[0-9]\..*[0-9]).*"' | awk '{print substr($3,2,length($3)-2)}' | awk '{print substr($1, 3, 3)}' | sed -e 's;\.;;g'`
        if [ "$VERSION" -lt "80" ]; then
            # Check some easily accessible MIN/MAX params for JVM mem usage
            if [ "x$JAVA_PERM_MEM" != "x" ]; then
                DEFAULT_JAVA_OPTS="$DEFAULT_JAVA_OPTS -XX:PermSize=$JAVA_PERM_MEM"
            fi
            if [ "x$JAVA_MAX_PERM_MEM" != "x" ]; then
                DEFAULT_JAVA_OPTS="$DEFAULT_JAVA_OPTS -XX:MaxPermSize=$JAVA_MAX_PERM_MEM"
            fi
        fi
        DEFAULT_JAVA_OPTS="-server $DEFAULT_JAVA_OPTS -Dcom.sun.management.jmxremote"
    elif [ "$JVM_VENDOR" = "IBM" ]; then
        if $os400; then
            DEFAULT_JAVA_OPTS="$DEFAULT_JAVA_OPTS"
        elif $aix; then
            DEFAULT_JAVA_OPTS="-Xverify:none -Xdump:heap -Xlp $DEFAULT_JAVA_OPTS"
        else
            DEFAULT_JAVA_OPTS="-Xverify:none $DEFAULT_JAVA_OPTS"
        fi
    fi

    # Setup classpath
    CLASSPATH="$KARAF_HOME/system/org/apache/karaf/instance/org.apache.karaf.instance.core/4.0.9/org.apache.karaf.instance.core-4.0.9.jar"
    CLASSPATH="$CLASSPATH:$KARAF_HOME/system/org/apache/karaf/shell/org.apache.karaf.shell.core/4.0.9/org.apache.karaf.shell.core-4.0.9.jar"
    CLASSPATH="$CLASSPATH:$KARAF_HOME/system/org/ops4j/pax/logging/pax-logging-api/1.8.5/pax-logging-api-1.8.5.jar"
    CLASSPATH="$CLASSPATH:$KARAF_HOME/system/jline/jline/2.14.1/jline-2.14.1.jar"

    DEFAULT_JAVA_DEBUG_PORT="5005"
    if [ "x$JAVA_DEBUG_PORT" = "x" ]; then
        JAVA_DEBUG_PORT="$DEFAULT_JAVA_DEBUG_PORT"
    fi
    DEFAULT_JAVA_DEBUG_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=$JAVA_DEBUG_PORT"

    ##
    ## TODO: Move to conf/profiler/yourkit.{sh|cmd}
    ##
    # Uncomment to enable YourKit profiling
    #DEFAULT_JAVA_DEBUG_OPTS="-Xrunyjpagent"
}

init() {
    # Determine if there is special OS handling we must perform
    detectOS

    # Unlimit the number of file descriptors if possible
    unlimitFD

    # Locate the Karaf home directory
    locateHome

    # Locate the Karaf base directory
    locateBase

    # Locate the Karaf data directory
    locateData

    # Locate the Karaf etc directory
    locateEtc

    # Setup the native library path
    setupNativePath

    # Locate the Java VM to execute
    locateJava

    # Determine the JVM vendor
    detectJVM

    # Setup default options
    setupDefaults

    # Install debug options
    setupDebugOptions

}

run() {

    if $cygwin; then
        KARAF_HOME=`cygpath --path --windows "$KARAF_HOME"`
        KARAF_BASE=`cygpath --path --windows "$KARAF_BASE"`
        KARAF_DATA=`cygpath --path --windows "$KARAF_DATA"`
        KARAF_ETC=`cygpath --path --windows "$KARAF_ETC"`
        if [ ! -z "$CLASSPATH" ]; then
            CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
        fi
    fi

    exec "$JAVA" $JAVA_OPTS -Dkaraf.instances="${KARAF_HOME}/instances" -Dkaraf.home="$KARAF_HOME" -Dkaraf.base="$KARAF_BASE" -Dkaraf.etc="$KARAF_ETC" -Djava.io.tmpdir="$KARAF_DATA/tmp" -Djava.util.logging.config.file="$KARAF_BASE/etc/java.util.logging.properties" $KARAF_OPTS $OPTS -classpath "$CLASSPATH" org.apache.karaf.instance.main.Execute "$@"
}

main() {
    init
    run "$@"
}

main "$@"

path: lider-server/bin/instance


code:
@echo off
rem
rem
rem    Licensed to the Apache Software Foundation (ASF) under one or more
rem    contributor license agreements.  See the NOTICE file distributed with
rem    this work for additional information regarding copyright ownership.
rem    The ASF licenses this file to You under the Apache License, Version 2.0
rem    (the "License"); you may not use this file except in compliance with
rem    the License.  You may obtain a copy of the License at
rem
rem       http://www.apache.org/licenses/LICENSE-2.0
rem
rem    Unless required by applicable law or agreed to in writing, software
rem    distributed under the License is distributed on an "AS IS" BASIS,
rem    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rem    See the License for the specific language governing permissions and
rem    limitations under the License.
rem

if not "%ECHO%" == "" echo %ECHO%

setlocal
set DIRNAME=%~dp0%
set PROGNAME=%~nx0%
set ARGS=%*

rem Sourcing environment settings for karaf similar to tomcats setenv
SET KARAF_SCRIPT="instance.bat"
if exist "%DIRNAME%setenv.bat" (
  call "%DIRNAME%setenv.bat"
)

rem Check console window title. Set to Karaf by default
if not "%KARAF_TITLE%" == "" (
    title %KARAF_TITLE%
) else (
    title Karaf
)

rem Check/Set up some easily accessible MIN/MAX params for JVM mem usage
if "%JAVA_MIN_MEM%" == "" (
    set JAVA_MIN_MEM=128M
)
if "%JAVA_MAX_MEM%" == "" (
    set JAVA_MAX_MEM=512M
)

goto BEGIN

:warn
    echo %PROGNAME%: %*
goto :EOF

:BEGIN

rem # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

if not "%KARAF_HOME%" == "" (
    call :warn Ignoring predefined value for KARAF_HOME
)
set KARAF_HOME=%DIRNAME%..
if not exist "%KARAF_HOME%" (
    call :warn KARAF_HOME is not valid: "%KARAF_HOME%"
    goto END
)

if not "%KARAF_BASE%" == "" (
    if not exist "%KARAF_BASE%" (
       call :warn KARAF_BASE is not valid: "%KARAF_BASE%"
       goto END
    )
)
if "%KARAF_BASE%" == "" (
  set "KARAF_BASE=%KARAF_HOME%"
)

if not "%KARAF_DATA%" == "" (
    if not exist "%KARAF_DATA%" (
        call :warn KARAF_DATA is not valid: "%KARAF_DATA%"
        goto END
    )
)
if "%KARAF_DATA%" == "" (
    set "KARAF_DATA=%KARAF_BASE%\data"
)

if not "%KARAF_ETC%" == "" (
    if not exist "%KARAF_ETC%" (
        call :warn KARAF_ETC is not valid: "%KARAF_ETC%"
        goto END
    )
)
if "%KARAF_ETC%" == "" (
    set "KARAF_ETC=%KARAF_BASE%\etc"
)

set DEFAULT_JAVA_OPTS=
set DEFAULT_JAVA_DEBUG_OPTS=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005

rem Support for loading native libraries
set PATH=%PATH%;%KARAF_BASE%\lib;%KARAF_HOME%\lib

rem Setup the Java Virtual Machine
if not "%JAVA%" == "" goto :Check_JAVA_END
    set JAVA=java
    if "%JAVA_HOME%" == "" call :warn JAVA_HOME not set; results may vary
    if not "%JAVA_HOME%" == "" set JAVA=%JAVA_HOME%\bin\java
    if not exist "%JAVA_HOME%" (
        call :warn JAVA_HOME is not valid: "%JAVA_HOME%"
        goto END
    )
:Check_JAVA_END

if "%JAVA_OPTS%" == "" set JAVA_OPTS=%DEFAULT_JAVA_OPTS%

if "%EXTRA_JAVA_OPTS%" == "" goto :KARAF_EXTRA_JAVA_OPTS_END
    set JAVA_OPTS="%JAVA_OPTS% %EXTRA_JAVA_OPTS%"
:KARAF_EXTRA_JAVA_OPTS_END

if "%KARAF_DEBUG%" == "" goto :KARAF_DEBUG_END
    rem Use the defaults if JAVA_DEBUG_OPTS was not set
    if "%JAVA_DEBUG_OPTS%" == "" set JAVA_DEBUG_OPTS=%DEFAULT_JAVA_DEBUG_OPTS%

    set JAVA_OPTS="%JAVA_DEBUG_OPTS% %JAVA_OPTS%"
    call :warn Enabling Java debug options: %JAVA_DEBUG_OPTS%
:KARAF_DEBUG_END

rem Setup the classpath
pushd "%KARAF_HOME%\lib"
for %%G in (*.jar) do call:APPEND_TO_CLASSPATH %%G
popd
goto CLASSPATH_END

: APPEND_TO_CLASSPATH
set filename=%~1
set suffix=%filename:~-4%
if %suffix% equ .jar set CLASSPATH=%CLASSPATH%;%KARAF_HOME%\lib\%filename%
goto :EOF

:CLASSPATH_END

set CLASSPATH=%KARAF_HOME%\system\org\apache\karaf\instance\org.apache.karaf.instance.core\4.0.9\org.apache.karaf.instance.core-4.0.9.jar
set CLASSPATH=%CLASSPATH%;%KARAF_HOME%\system\org\apache\karaf\shell\org.apache.karaf.shell.core\4.0.9\org.apache.karaf.shell.core-4.0.9.jar
set CLASSPATH=%CLASSPATH%;%KARAF_HOME%\system\org\ops4j\pax\logging\pax-logging-api\1.8.5\pax-logging-api-1.8.5.jar
set CLASSPATH=%CLASSPATH%;%KARAF_HOME%\system\jline\jline\2.14.1\jline-2.14.1.jar

:EXECUTE
    if "%SHIFT%" == "true" SET ARGS=%2 %3 %4 %5 %6 %7 %8
    if not "%SHIFT%" == "true" SET ARGS=%1 %2 %3 %4 %5 %6 %7 %8
    rem Execute the Java Virtual Machine
    "%JAVA%" %JAVA_OPTS% %OPTS% -classpath "%CLASSPATH%" -Dkaraf.instances="%KARAF_HOME%\instances" -Dkaraf.home="%KARAF_HOME%" -Dkaraf.base="%KARAF_BASE%" -Dkaraf.etc="%KARAF_ETC%" -Djava.io.tmpdir="%KARAF_DATA%\tmp" -Djava.util.logging.config.file="%KARAF_BASE%\etc\java.util.logging.properties" %KARAF_OPTS% org.apache.karaf.instance.main.Execute %ARGS%

rem # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

:END

endlocal