Skip to content

Commit

Permalink
Fix escaping for the uninstall shell script.
Browse files Browse the repository at this point in the history
  • Loading branch information
Francois Gouget committed Sep 16, 2010
1 parent 4f9180f commit 75e0656
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions scripts/mojosetup_mainline.lua
Expand Up @@ -997,23 +997,27 @@ local function install_control_app(desc, key)
-- okay, we're written out.
end

local function shquote_string(str)
-- Quote the string so it can safely be passed to the shell
str = string.gsub(str, "\\", "\\\\")
str = string.gsub(str, "[$]", "\\$")
str = string.gsub(str, "\"", "\\\"")
str = string.gsub(str, "`", "\\`")
return "\"" ..str.. "\""
end

local function install_unix_uninstaller(desc, key)
-- Write a script out that calls the uninstaller.
local fname = MojoSetup.destination .. "/" ..
"uninstall-" .. MojoSetup.install.id .. ".sh"

-- Man, I hate escaping shell strings...
local bin = "\"`dirname \"$0\"`\"'/" .. MojoSetup.metadatadirname .. "/" ..
MojoSetup.controlappname .. "'"
string.gsub(bin, "'", "'\\''") -- !!! FIXME: no-op!-- Escape single quotes for shell.

local id = MojoSetup.install.id
string.gsub(id, "'", "'\\''") -- !!! FIXME: no-op!
local bin = "\"`dirname \\\"$0\\\"`\"/" ..
shquote_string(MojoSetup.metadatadirname .. "/" .. MojoSetup.controlappname)

local script =
"#!/bin/sh\n" ..
"exec " .. bin .. " uninstall '" .. id .. "' \"$@\"\n\n"
"exec " .. bin .. " uninstall " .. shquote_string(MojoSetup.install.id) .. " \"$@\"\n"

install_parent_dirs(fname, key)
install_file_from_string(fname, script, "0755", desc, key)
Expand Down

0 comments on commit 75e0656

Please sign in to comment.