summaryrefslogtreecommitdiffstats
path: root/provisioning-model.lua
diff options
context:
space:
mode:
Diffstat (limited to 'provisioning-model.lua')
-rw-r--r--provisioning-model.lua44
1 files changed, 21 insertions, 23 deletions
diff --git a/provisioning-model.lua b/provisioning-model.lua
index 521273c..ca04d36 100644
--- a/provisioning-model.lua
+++ b/provisioning-model.lua
@@ -14,7 +14,6 @@ local DatabaseName = "provisioning"
local DatabaseUser = "postgres"
local DatabasePassword
-local path = "PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin "
local baseurl = "/etc/provisioning/templates/"
local updatedevicescriptfile = "/etc/provisioning/update_device.lua"
local updatedeviceparamsscriptfile = "/etc/provisioning/update_device_params.lua"
@@ -53,28 +52,27 @@ end
local createdatabase = function()
local result = {}
+ local cmdresult, errtxt
-- First, create the user
if DatabaseUser ~= "postgres" then
- local cmd = path..'psql -U postgres -c "CREATE USER '..DatabaseUser..''
+ local cmd = "CREATE USER "..DatabaseUser
if DatabasePassword then
- cmd = cmd .. ' WITH PASSWORD \''..DatabasePassword..'\''
+ cmd = cmd .. " WITH PASSWORD '"..DatabasePassword.."'"
end
- cmd = cmd .. '" 2>&1'
- local f = io.popen(cmd)
- table.insert(result, f:read("*a"))
- f:close()
+ cmdresult, errtxt = modelfunctions.run_executable({"psql", "-U", "postgres", "-c", cmd}, true)
+ table.insert(result, errtxt)
+ table.insert(result, cmdresult)
end
-- Create the database
- local cmd = path..'psql -U postgres -c "CREATE DATABASE '..DatabaseName..' WITH OWNER '..DatabaseUser..'" 2>&1'
- local f = io.popen(cmd)
- table.insert(result, f:read("*a"))
- f:close()
+ local cmd = "CREATE DATABASE "..DatabaseName.." WITH OWNER "..DatabaseUser
+ cmdresult, errtxt = modelfunctions.run_executable({"psql", "-U", "postgres", "-c", cmd}, true)
+ table.insert(result, errtxt)
+ table.insert(result, cmdresult)
- cmd = path..'createlang -U postgres plpgsql '..DatabaseName
- f = io.popen(cmd)
- table.insert(result, f:read("*a"))
- f:close()
+ cmdresult, errtxt = modelfunctions.run_executable({"createlang", "-U", "postgres", "plpgsql", DatabaseName}, true)
+ table.insert(result, errtxt)
+ table.insert(result, cmdresult)
logevent(table.concat(result, "\n"))
@@ -85,16 +83,16 @@ end
local deletedatabase = function()
local result = {}
- local cmd = path..'psql -U postgres -c "DROP DATABASE '..DatabaseName..'" 2>&1'
- local f = io.popen(cmd)
- table.insert(result, f:read("*a"))
- f:close()
+ local cmd = "DROP DATABASE "..DatabaseName
+ local cmdresult, errtxt = modelfunctions.run_executable({"psql", "-U", "postgres", "-c", cmd}, true)
+ table.insert(result, errtxt)
+ table.insert(result, cmdresult)
if DatabaseUser ~= "postgres" then
- cmd = path..'psql -U postgres -c "DROP ROLE '..DatabaseUser..'" 2>&1'
- f = io.popen(cmd)
- table.insert(result, f:read("*a"))
- f:close()
+ cmd = "DROP ROLE "..DatabaseUser
+ local cmdresult, errtxt = modelfunctions.run_executable({"psql", "-U", "postgres", "-c", cmd}, true)
+ table.insert(result, errtxt)
+ table.insert(result, cmdresult)
end
logevent(table.concat(result, "\n"))