Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Copy the post-update hook to created repos.

  • Loading branch information...
commit 11e7e1abbe8c271de70f708df4011b99469a0059 1 parent 2d5801e
@noteed authored
View
9 bin/ghost-control.hs
@@ -111,6 +111,9 @@ processCmd Init{..} = do
putStrLn "Add the following line to your main Nginx configuration"
putStrLn "file (inside an `http {..}` block.):"
putStrLn $ " include " ++ home ++ "/run/nginx.conf;"
+ putStrLn "Add the following line to your sudoers file:"
+ putStrLn " ghost ALL=(ALL) NOPASSWD: /etc/rc.d/nginx"
+ putStrLn "(so the post-update hook can instruct Nginx to reload its configuration)."
processCmd AddUser{..} = do
putStrLn "Ghost: adding a new user."
@@ -131,12 +134,14 @@ processCmd AddRepository{..} = do
putStrLn "Ghost: adding a new repository."
hFlush stdout
home <- getHomeDirectory
+ let repoDir = home </> "user" </> addRepoUserName </> addRepoName <.> "git"
-- TODO check username
-- TODO check repository name
_ <- runAndWaitProcess "git"
- ["init", "--bare",
- home </> "user" </> addRepoUserName </> addRepoName <.> "git"]
+ ["init", "--bare", repoDir]
Nothing
+ copyFile ("bin" </> "ghost-post-update")
+ (repoDir </> "hooks" </> "post-update")
return ()
-- | Given a username and its public SSH key, return a string
View
17 bin/ghost-post-update.hs
@@ -17,9 +17,10 @@ import Data.Version (showVersion)
import System.Console.CmdArgs.Implicit
import System.Directory
( createDirectoryIfMissing, doesFileExist
- , getCurrentDirectory)
+ , getCurrentDirectory, getHomeDirectory
+ )
import System.Environment (getEnvironment)
-import System.FilePath ((</>), (<.>), splitDirectories, splitPath)
+import System.FilePath ((</>), (<.>), dropExtension, splitDirectories, splitPath)
import System.IO (hPutStrLn, withFile, IOMode(WriteMode), hFlush, stdout, stderr)
import System.Posix.Process (executeFile)
import System.Process (runProcess, waitForProcess)
@@ -28,10 +29,6 @@ versionString :: String
versionString =
"ghost-post-update " ++ showVersion version ++ " Copyright (c) 2012 Vo Minh Thu."
--- | The Ghost user home.
-homeDir :: FilePath
-homeDir = "/home/thu/ghost" -- TODO "/home/ghost"
-
main :: IO ()
main = (processCmd =<<) $ cmdArgs $
modes
@@ -52,10 +49,12 @@ shell = PostUpdate
processCmd :: Cmd -> IO ()
processCmd PostUpdate{..} = do
+ home <- getHomeDirectory
currentDir <- getCurrentDirectory
- let domain = last $ splitDirectories currentDir
- productionDirectory = homeDir </> "run/production" </> domain
- stagingDirectory = homeDir </> "run/staging" </> domain
+ -- dropExtension to remove the .git from the bare repo name.
+ let domain = dropExtension . last $ splitDirectories currentDir
+ productionDirectory = home </> "run/production" </> domain
+ stagingDirectory = home </> "run/staging" </> domain
putStrLn $ "Ghost receiving push (updating " ++ postUpdateRef ++ ")."
putStrLn $ "Domain: " ++ domain
hFlush stdout
View
1  create-ghost-user.archlinux.sh
@@ -23,6 +23,7 @@ sudo useradd \
sudo mkdir -p /home/ghost/{.ssh,bin,administrator}
sudo cp `which ghost-command` /home/ghost/bin/
sudo cp `which ghost-control` /home/ghost/bin/
+sudo cp `which ghost-post-update` /home/ghost/bin/
sudo cp $public_key /home/ghost/.ssh/authorized_keys
sudo chown -R ghost:ghost /home/ghost/
ssh ghost@localhost bin/ghost-control init
View
5 scenario.sh
@@ -0,0 +1,5 @@
+#! /bin/sh
+sudo userdel ghost ; sudo rm -rf /home/ghost
+./create-ghost-user.archlinux.sh ~/.ssh/id_rsa.pub
+./add-user.sh noteed ~/.ssh/rum_key.pub
+./add-repository.sh noteed ghost
Please sign in to comment.
Something went wrong with that request. Please try again.