writeFstab :: FilePath -- ^ Capsule location.
             -> FilePath -- ^ New fstab location
             -> Options
             -> IO ()
  writeFstab capsuleLoc tmpFstab opts = do
    pkgSrcMnt <- fmap (\a -> fmap (mkBindMount internalPkgSrcDir) a) 
        . mapM canonicalizePath $ optPkgSrcDir opts
    otherMounts <- fmap (\a -> fmap mkMount a)
        . mapM (\a -> mkMountPoint internalMntDir a) 
        $ optMount opts
    let mounts = (maybeToList pkgSrcMnt) ++ otherMounts
    mapM_ (debugM "hgc" . (\a -> "Mount point: " ++ a)) mounts
    let writeMounts str = str ++ "\n" ++ unlines mounts
    readFile fstabloc >>= writeFile tmpFstab . writeMounts
    where
      fstabloc = (capsuleLoc </> "fstab")
      internalPkgSrcDir = capsuleLoc </> "rootfs/var/cache/aura/src"
      internalMntDir = capsuleLoc </> "rootfs/mnt"
      mkBindMount int ext = intercalate " " [ext, int, "none", "bind", "0", "0"]
      mkMount (a,b) = mkBindMount (internalMntDir </> b) a

  -- Clean the template, removing specified cache directories (/var/cache/pacman etc)
writeFstab :: FilePath -- ^ Capsule location.
             -> FilePath -- ^ New fstab location
             -> Options
             -> IO ()
writeFstab capsuleLoc tmpFstab opts = do
    pkgSrcMnt <- fmap (\a -> fmap (mkBindMount internalPkgSrcDir) a) 
        . mapM canonicalizePath $ optPkgSrcDir opts
    otherMounts <- fmap (\a -> fmap mkMount a)
        . mapM (\a -> mkMountPoint internalMntDir a) 
        $ optMount opts
    let mounts = (maybeToList pkgSrcMnt) ++ otherMounts
    mapM_ (debugM "hgc" . (\a -> "Mount point: " ++ a)) mounts
    let writeMounts str = str ++ "\n" ++ unlines mounts
    readFile fstabloc >>= writeFile tmpFstab . writeMounts
    where
      fstabloc = (capsuleLoc </> "fstab")
      internalPkgSrcDir = capsuleLoc </> "rootfs/var/cache/aura/src"
      internalMntDir = capsuleLoc </> "rootfs/mnt"
      mkBindMount int ext = intercalate " " [ext, int, "none", "bind", "0", "0"]
      mkMount (a,b) = mkBindMount (internalMntDir </> b) a

  -- Clean the template, removing specified cache directories (/var/cache/pacman etc)
writeFstab capsuleLoc tmpFstab opts = do
    pkgSrcMnt <- fmap (\a -> fmap (mkBindMount internalPkgSrcDir) a) 
        . mapM canonicalizePath $ optPkgSrcDir opts
    otherMounts <- fmap (\a -> fmap mkMount a)
        . mapM (\a -> mkMountPoint internalMntDir a) 
        $ optMount opts
    let mounts = (maybeToList pkgSrcMnt) ++ otherMounts
    mapM_ (debugM "hgc" . (\a -> "Mount point: " ++ a)) mounts
    let writeMounts str = str ++ "\n" ++ unlines mounts
    readFile fstabloc >>= writeFile tmpFstab . writeMounts
    where
      fstabloc = (capsuleLoc </> "fstab")
      internalPkgSrcDir = capsuleLoc </> "rootfs/var/cache/aura/src"
      internalMntDir = capsuleLoc </> "rootfs/mnt"
      mkBindMount int ext = intercalate " " [ext, int, "none", "bind", "0", "0"]
      mkMount (a,b) = mkBindMount (internalMntDir </> b) a

  -- Clean the template, removing specified cache directories (/var/cache/pacman etc)