mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-10-29 20:15:13 +08:00
🌴 Sync 2026-03-05 23:51:42
This commit is contained in:
1 parent
97c049ed0a
commit
0acff03804
14253 files changed
+3893239
No files matched your search
+76
@@ -0,0 +1,76 @@
|
||||
#!/bin/sh
|
||||
# Author Xiaobao(xiaobao@linkease.com)
|
||||
|
||||
ACTION=${1}
|
||||
shift 1
|
||||
|
||||
do_install() {
|
||||
local config=`uci get penpot.@main[0].config_path 2>/dev/null`
|
||||
if [ -z "$config" ]; then
|
||||
echo "config path is empty!"
|
||||
exit 1
|
||||
fi
|
||||
mkdir -p $config
|
||||
|
||||
lua /usr/libexec/istorec/penpot_template.lua penpot /usr/share/penpot/config.template.env $config/config.env
|
||||
RET=$?
|
||||
if [ ! "$RET" = "0" ]; then
|
||||
echo "convert config.env failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
lua /usr/libexec/istorec/penpot_template.lua penpot /usr/share/penpot/docker-compose.template.yaml $config/docker-compose.yaml
|
||||
RET=$?
|
||||
if [ ! "$RET" = "0" ]; then
|
||||
echo "convert config.env failed"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd $config
|
||||
docker-compose down || true
|
||||
docker-compose up -d
|
||||
echo "Wait 120 to intialize"
|
||||
sleep 120
|
||||
echo "Now you should create a user manually"
|
||||
}
|
||||
|
||||
usage() {
|
||||
echo "usage: $0 sub-command"
|
||||
echo "where sub-command is one of:"
|
||||
echo " install Install the penpot"
|
||||
echo " upgrade Upgrade the penpot"
|
||||
echo " rm/start/stop/restart Remove/Start/Stop/Restart the penpot"
|
||||
echo " status Penpot status"
|
||||
echo " port Penpot port"
|
||||
}
|
||||
|
||||
case ${ACTION} in
|
||||
"install")
|
||||
do_install
|
||||
;;
|
||||
"upgrade")
|
||||
do_install
|
||||
;;
|
||||
"rm")
|
||||
config=`uci get penpot.@main[0].config_path 2>/dev/null`
|
||||
cd $config && docker-compose down
|
||||
;;
|
||||
"start" | "stop" | "restart")
|
||||
config=`uci get penpot.@main[0].config_path 2>/dev/null`
|
||||
cd $config && docker-compose ${ACTION}
|
||||
;;
|
||||
"status")
|
||||
docker ps --all -f 'name=^/penpot_penpot-frontend_1$' --format '{{.State}}'
|
||||
;;
|
||||
"port")
|
||||
uci get -q penpot.@main[0].http_port 2>/dev/null
|
||||
;;
|
||||
"create-user")
|
||||
echo docker exec -ti penpot_penpot-backend_1 ./manage.sh create-profile -u "${1}" -p "${2}" -n "${3}"
|
||||
docker exec -ti penpot_penpot-backend_1 ./manage.sh create-profile -u "${1}" -p "${2}" -n "${3}"
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
@@ -0,0 +1,96 @@
|
||||
local util = require "luci.util"
|
||||
local tparser = require "luci.template.parser"
|
||||
local uci = require "luci.model.uci"
|
||||
local nixio = require "nixio"
|
||||
|
||||
local tostring, pairs, loadstring = tostring, pairs, loadstring
|
||||
local setmetatable, loadfile = setmetatable, loadfile
|
||||
local getfenv, setfenv, rawget = getfenv, setfenv, rawget
|
||||
local assert, type, error = assert, type, error
|
||||
|
||||
local default_ctx = {tostring = tostring}
|
||||
|
||||
local from_string = function(template)
|
||||
return Template(default_ctx, nil, template)
|
||||
end
|
||||
|
||||
local from_file = function(template_file)
|
||||
return Template(default_ctx, template_file)
|
||||
end
|
||||
|
||||
-- Template class
|
||||
Template = util.class()
|
||||
|
||||
-- Constructor - Reads and compiles the template on-demand
|
||||
function Template.__init__(self, viewns, name, template)
|
||||
if name then
|
||||
self.name = name
|
||||
else
|
||||
self.name = "[string]"
|
||||
end
|
||||
|
||||
-- Create a new namespace for this template
|
||||
self.viewns = viewns
|
||||
|
||||
-- Compile template
|
||||
local err
|
||||
local sourcefile
|
||||
|
||||
if name then
|
||||
sourcefile = name
|
||||
self.template, _, err = tparser.parse(sourcefile)
|
||||
else
|
||||
sourcefile = "[string]"
|
||||
self.template, _, err = tparser.parse_string(template)
|
||||
end
|
||||
|
||||
-- If we have no valid template throw error, otherwise cache the template
|
||||
if not self.template then
|
||||
error("Failed to load template '" .. self.name .. "'.\n" ..
|
||||
"Error while parsing template '" .. sourcefile .. "':\n" ..
|
||||
(err or "Unknown syntax error"))
|
||||
end
|
||||
end
|
||||
|
||||
-- Renders a template
|
||||
function Template.render(self, scope)
|
||||
|
||||
-- Put our predefined objects in the scope of the template
|
||||
setfenv(self.template, setmetatable({}, {__index =
|
||||
function(tbl, key)
|
||||
return rawget(tbl, key) or self.viewns[key] or scope[key]
|
||||
end}))
|
||||
|
||||
-- Now finally render the thing
|
||||
local stat, err = util.copcall(self.template)
|
||||
if not stat then
|
||||
error("Failed to execute template '" .. self.name .. "'.\n" ..
|
||||
"A runtime error occurred: " .. tostring(err or "(nil)"))
|
||||
end
|
||||
end
|
||||
|
||||
if #arg == 3 then
|
||||
local cur = uci.cursor()
|
||||
local configs = {}
|
||||
cur:foreach(arg[1], "main", function(s)
|
||||
for k, v in pairs(s) do
|
||||
configs[k] = v
|
||||
end
|
||||
end)
|
||||
if not nixio.fs.access(arg[2]) then
|
||||
print(arg[2] .. " not found")
|
||||
os.exit(10)
|
||||
end
|
||||
local target = io.open(arg[3], "w")
|
||||
if not target then
|
||||
print(arg[3] .. " can not write")
|
||||
end
|
||||
configs.write = function(data)
|
||||
target:write(data)
|
||||
end
|
||||
from_file(arg[2]):render(configs)
|
||||
target:close()
|
||||
else
|
||||
print("penpot_template.lua [appname] [template-in] [template-out]")
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user