substVmScript ::
  forall e.
  (Member EnvironmentReader e, Member ExcB9 e) =>
  VmScript ->
  Eff e VmScript
substVmScript = everywhereM gsubst
  where
    gsubst :: GenericM (Eff e)
    gsubst = mkM substMountPoint `extM` substSharedDir `extM` substScript
    substMountPoint NotMounted = pure NotMounted
    substMountPoint (MountPoint x) = MountPoint <$> substStr x
    substSharedDir (SharedDirectory fp mp) =
      SharedDirectory <$> substStr fp <*> pure mp
    substSharedDir (SharedDirectoryRO fp mp) =
      SharedDirectoryRO <$> substStr fp <*> pure mp
    substSharedDir s = pure s
    substScript (In fp s) = In <$> substStr fp <*> pure s
    substScript (Run fp args) = Run <$> substStr fp <*> mapM substStr args
    substScript (As fp s) = As <$> substStr fp <*> pure s
    substScript s = pure s
substVmScript ::
  forall e.
  (Member EnvironmentReader e, Member ExcB9 e) =>
  VmScript ->
  Eff e VmScript
substVmScript = everywhereM gsubst
  where
    gsubst :: GenericM (Eff e)
    gsubst = mkM substMountPoint `extM` substSharedDir `extM` substScript
    substMountPoint NotMounted = pure NotMounted
    substMountPoint (MountPoint x) = MountPoint <$> substStr x
    substSharedDir (SharedDirectory fp mp) =
      SharedDirectory <$> substStr fp <*> pure mp
    substSharedDir (SharedDirectoryRO fp mp) =
      SharedDirectoryRO <$> substStr fp <*> pure mp
    substSharedDir s = pure s
    substScript (In fp s) = In <$> substStr fp <*> pure s
    substScript (Run fp args) = Run <$> substStr fp <*> mapM substStr args
    substScript (As fp s) = As <$> substStr fp <*> pure s
    substScript s = pure s
substVmScript = everywhereM gsubst
  where
    gsubst :: GenericM (Eff e)
    gsubst = mkM substMountPoint `extM` substSharedDir `extM` substScript
    substMountPoint NotMounted = pure NotMounted
    substMountPoint (MountPoint x) = MountPoint <$> substStr x
    substSharedDir (SharedDirectory fp mp) =
      SharedDirectory <$> substStr fp <*> pure mp
    substSharedDir (SharedDirectoryRO fp mp) =
      SharedDirectoryRO <$> substStr fp <*> pure mp
    substSharedDir s = pure s
    substScript (In fp s) = In <$> substStr fp <*> pure s
    substScript (Run fp args) = Run <$> substStr fp <*> mapM substStr args
    substScript (As fp s) = As <$> substStr fp <*> pure s
    substScript s = pure s