diff options
| author | Joey Hess <joey@kitenet.net> | 2014-04-04 01:12:44 -0400 |
|---|---|---|
| committer | Joey Hess <joey@kitenet.net> | 2014-04-04 01:12:44 -0400 |
| commit | 8bb175d1078de6add55f5c5f689693495d141436 (patch) | |
| tree | 74173c19b2b293b94d993398c41a3063d2f5b364 /Propellor/Property/Docker | |
| parent | eea8637afe78ceff25ddd11d365a3fc022cc5fa4 (diff) | |
| parent | ccc82907124ccd2ad4951c2c4946ae20af007530 (diff) | |
Merge branch 'joeyconfig'
Conflicts:
config.hs
Diffstat (limited to 'Propellor/Property/Docker')
| -rw-r--r-- | Propellor/Property/Docker/Shim.hs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/Propellor/Property/Docker/Shim.hs b/Propellor/Property/Docker/Shim.hs new file mode 100644 index 00000000..01c2b22f --- /dev/null +++ b/Propellor/Property/Docker/Shim.hs @@ -0,0 +1,58 @@ +-- | Support for running propellor, as built outside a docker container, +-- inside the container. +-- +-- Note: This is currently Debian specific, due to glibcLibs. + +module Propellor.Property.Docker.Shim (setup, file) where + +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' + let gconvdir = (dest ++) $ parentDir $ + fromMaybe (error "cannot find gconv directory") $ + headMaybe $ filter ("/gconv/" `isInfixOf`) glibclibs + let linkerparams = ["--library-path", intercalate ":" libdirs ] + let shim = file propellorbin dest + writeFile shim $ unlines + [ "#!/bin/sh" + , "GCONV_PATH=" ++ shellEscape gconvdir + , "export GCONV_PATH" + , "exec " ++ unwords (map shellEscape $ linker : linkerparams) ++ + " " ++ shellEscape propellorbin ++ " \"$@\"" + ] + modifyFileMode shim (addModes executeModes) + return shim + +file :: FilePath -> FilePath -> FilePath +file propellorbin dest = dest </> takeFileName propellorbin + +installFile :: FilePath -> FilePath -> IO () +installFile top f = do + createDirectoryIfMissing True destdir + nukeFile dest + 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 |
