From 7c5188b202977d341bdfae504c987e8ee0451157 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 22 Nov 2014 22:01:19 -0400 Subject: propellor spin --- src/Propellor/Shim.hs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/Propellor/Shim.hs') diff --git a/src/Propellor/Shim.hs b/src/Propellor/Shim.hs index 1bfbb0ca..6262ea5c 100644 --- a/src/Propellor/Shim.hs +++ b/src/Propellor/Shim.hs @@ -11,14 +11,18 @@ import Utility.LinuxMkLibs import Utility.SafeCommand import Utility.Path import Utility.FileMode +import Utility.FileSystemEncoding import Data.List import System.Posix.Files -- | Sets up a shimmed version of the program, in a directory, and -- returns its path. +-- +-- Propellor may be running from an existing shim, in which case it's +-- simply reused. setup :: FilePath -> FilePath -> IO FilePath -setup propellorbin dest = do +setup propellorbin dest = checkAlreadyShimmed propellorbin $ do createDirectoryIfMissing True dest libs <- parseLdd <$> readProcess "ldd" [propellorbin] @@ -36,7 +40,7 @@ setup propellorbin dest = do let linkerparams = ["--library-path", intercalate ":" libdirs ] let shim = file propellorbin dest writeFile shim $ unlines - [ "#!/bin/sh" + [ shebang , "GCONV_PATH=" ++ shellEscape gconvdir , "export GCONV_PATH" , "exec " ++ unwords (map shellEscape $ linker : linkerparams) ++ @@ -45,6 +49,17 @@ setup propellorbin dest = do modifyFileMode shim (addModes executeModes) return shim +shebang :: String +shebang = "#!/bin/sh" + +checkAlreadyShimmed :: FilePath -> IO FilePath -> IO FilePath +checkAlreadyShimmed f nope = withFile f ReadMode $ \h -> do + fileEncoding h + s <- hGetLine h + if s == shebang + then return f + else nope + -- Called when the shimmed propellor is running, so that commands it runs -- don't see it. cleanEnv :: IO () -- cgit v1.2.3 From 96ecbaad25076901802dd7a311161d46a1212d68 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 22 Nov 2014 22:10:53 -0400 Subject: pute full path to bin/propellor inside shim --- src/Propellor/Property/Chroot.hs | 2 +- src/Propellor/Property/Debootstrap.hs | 3 ++- src/Propellor/Property/Docker.hs | 2 +- src/Propellor/Shim.hs | 6 +++--- src/Propellor/Spin.hs | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) (limited to 'src/Propellor/Shim.hs') diff --git a/src/Propellor/Property/Chroot.hs b/src/Propellor/Property/Chroot.hs index c3b14a8e..f45e2fc1 100644 --- a/src/Propellor/Property/Chroot.hs +++ b/src/Propellor/Property/Chroot.hs @@ -88,7 +88,7 @@ propellChroot c@(Chroot loc _ _ _) mkproc systemdonly = property (chrootDesc c " let me = localdir "propellor" shim <- liftIO $ ifM (doesDirectoryExist d) ( pure (Shim.file me d) - , Shim.setup me d + , Shim.setup me Nothing d ) ifM (liftIO $ bindmount shim) ( chainprovision shim diff --git a/src/Propellor/Property/Debootstrap.hs b/src/Propellor/Property/Debootstrap.hs index a8c80348..f85eb2e6 100644 --- a/src/Propellor/Property/Debootstrap.hs +++ b/src/Propellor/Property/Debootstrap.hs @@ -263,7 +263,8 @@ fixForeignDev target = whenM (doesFileExist (target ++ foreignDevFlag)) $ do , Param "sh" , Param "-c" , Param $ intercalate " && " - [ "rm -rf /dev" + [ "apt-get -y install makedev" + , "rm -rf /dev" , "mkdir /dev" , "cd /dev" , "/sbin/MAKEDEV std ptmx fd consoleonly" diff --git a/src/Propellor/Property/Docker.hs b/src/Propellor/Property/Docker.hs index 460bc3ec..586ebc2e 100644 --- a/src/Propellor/Property/Docker.hs +++ b/src/Propellor/Property/Docker.hs @@ -377,7 +377,7 @@ runningContainer cid@(ContainerId hn cn) image runps = containerDesc cid $ prope liftIO $ do clearProvisionedFlag cid createDirectoryIfMissing True (takeDirectory $ identFile cid) - shim <- liftIO $ Shim.setup (localdir "propellor") (localdir shimdir cid) + shim <- liftIO $ Shim.setup (localdir "propellor") Nothing (localdir shimdir cid) liftIO $ writeFile (identFile cid) (show ident) ensureProperty $ boolProperty "run" $ runContainer img (runps ++ ["-i", "-d", "-t"]) diff --git a/src/Propellor/Shim.hs b/src/Propellor/Shim.hs index 6262ea5c..a97bf5c8 100644 --- a/src/Propellor/Shim.hs +++ b/src/Propellor/Shim.hs @@ -21,8 +21,8 @@ import System.Posix.Files -- -- Propellor may be running from an existing shim, in which case it's -- simply reused. -setup :: FilePath -> FilePath -> IO FilePath -setup propellorbin dest = checkAlreadyShimmed propellorbin $ do +setup :: FilePath -> Maybe FilePath -> FilePath -> IO FilePath +setup propellorbin propellorbinpath dest = checkAlreadyShimmed propellorbin $ do createDirectoryIfMissing True dest libs <- parseLdd <$> readProcess "ldd" [propellorbin] @@ -44,7 +44,7 @@ setup propellorbin dest = checkAlreadyShimmed propellorbin $ do , "GCONV_PATH=" ++ shellEscape gconvdir , "export GCONV_PATH" , "exec " ++ unwords (map shellEscape $ linker : linkerparams) ++ - " " ++ shellEscape propellorbin ++ " \"$@\"" + " " ++ shellEscape (fromMaybe propellorbin propellorbinpath) ++ " \"$@\"" ] modifyFileMode shim (addModes executeModes) return shim diff --git a/src/Propellor/Spin.hs b/src/Propellor/Spin.hs index 6add4f9f..228c4027 100644 --- a/src/Propellor/Spin.hs +++ b/src/Propellor/Spin.hs @@ -224,7 +224,7 @@ sendPrecompiled hn = void $ actionMessage ("Uploading locally compiled propellor createDirectoryIfMissing True "bin" unlessM (boolSystem "cp" [File me, File "bin/propellor"]) $ errorMessage "failed copying in propellor" - void $ Shim.setup "bin/propellor" "." + void $ Shim.setup "bin/propellor" (localdir "bin/propellor") "." changeWorkingDirectory tmpdir withTmpFile "propellor.tar." $ \tarball _ -> allM id [ boolSystem "strip" [File me] -- cgit v1.2.3