2014-04-04 01:22:37 +00:00
|
|
|
-- | Support for running propellor, as built outside a docker container,
|
|
|
|
-- inside the container.
|
|
|
|
--
|
|
|
|
-- Note: This is currently Debian specific, due to glibcLibs.
|
|
|
|
|
2014-04-04 06:06:19 +00:00
|
|
|
module Propellor.Property.Docker.Shim (setup, cleanEnv, file) where
|
2014-04-04 01:22:37 +00:00
|
|
|
|
|
|
|
import Propellor
|
|
|
|
import Utility.LinuxMkLibs
|
|
|
|
import Utility.SafeCommand
|
|
|
|
import Utility.Path
|
|
|
|
import Utility.FileMode
|
|
|
|
|
|
|
|
import Data.List
|
|
|
|
import System.Posix.Files
|
|
|
|
|
|
|
|
-- | Sets up a shimmed version of the program, in a directory, and
|
|
|
|
-- returns its path.
|
|
|
|
setup :: FilePath -> FilePath -> IO FilePath
|
|
|
|
setup propellorbin dest = do
|
|
|
|
createDirectoryIfMissing True dest
|
|
|
|
|
|
|
|
libs <- parseLdd <$> readProcess "ldd" [propellorbin]
|
|
|
|
glibclibs <- glibcLibs
|
|
|
|
let libs' = nub $ libs ++ glibclibs
|
|
|
|
libdirs <- map (dest ++) . nub . catMaybes
|
|
|
|
<$> mapM (installLib installFile dest) libs'
|
|
|
|
|
|
|
|
let linker = (dest ++) $
|
|
|
|
fromMaybe (error "cannot find ld-linux linker") $
|
|
|
|
headMaybe $ filter ("ld-linux" `isInfixOf`) libs'
|
2014-04-04 04:29:19 +00:00
|
|
|
let gconvdir = (dest ++) $ parentDir $
|
|
|
|
fromMaybe (error "cannot find gconv directory") $
|
|
|
|
headMaybe $ filter ("/gconv/" `isInfixOf`) glibclibs
|
2014-04-04 01:22:37 +00:00
|
|
|
let linkerparams = ["--library-path", intercalate ":" libdirs ]
|
|
|
|
let shim = file propellorbin dest
|
|
|
|
writeFile shim $ unlines
|
|
|
|
[ "#!/bin/sh"
|
2014-04-04 04:44:29 +00:00
|
|
|
, "GCONV_PATH=" ++ shellEscape gconvdir
|
2014-04-04 04:29:19 +00:00
|
|
|
, "export GCONV_PATH"
|
2014-04-04 01:22:37 +00:00
|
|
|
, "exec " ++ unwords (map shellEscape $ linker : linkerparams) ++
|
|
|
|
" " ++ shellEscape propellorbin ++ " \"$@\""
|
|
|
|
]
|
|
|
|
modifyFileMode shim (addModes executeModes)
|
|
|
|
return shim
|
|
|
|
|
2014-04-04 06:06:19 +00:00
|
|
|
cleanEnv :: IO ()
|
|
|
|
cleanEnv = void $ unsetEnv "GCONV_PATH"
|
|
|
|
|
2014-04-04 01:22:37 +00:00
|
|
|
file :: FilePath -> FilePath -> FilePath
|
2014-04-04 03:35:36 +00:00
|
|
|
file propellorbin dest = dest </> takeFileName propellorbin
|
2014-04-04 01:22:37 +00:00
|
|
|
|
|
|
|
installFile :: FilePath -> FilePath -> IO ()
|
|
|
|
installFile top f = do
|
|
|
|
createDirectoryIfMissing True destdir
|
2014-04-04 03:16:34 +00:00
|
|
|
nukeFile dest
|
2014-04-04 01:22:37 +00:00
|
|
|
createLink f dest `catchIO` (const copy)
|
|
|
|
where
|
|
|
|
copy = void $ boolSystem "cp" [Param "-a", Param f, Param dest]
|
|
|
|
destdir = inTop top $ parentDir f
|
|
|
|
dest = inTop top f
|