From 03d4363a24998cd670061fde1ea4b8db8cbc5b32 Mon Sep 17 00:00:00 2001 From: pho Date: Sun, 7 Oct 2007 13:16:59 +0900 Subject: [PATCH 1/1] Initial record darcs-hash:20071007041659-62b54-2fae55997fc892cf7d5b84de0cdee216fe5b5535.gz --- .boring | 55 ++++++++++++++++++++++++ Main.hs | 105 +++++++++++++++++++++++++++++++++++++++++++++ Makefile | 31 +++++++++++++ Rakka.buildinfo.in | 5 +++ Rakka.cabal | 29 +++++++++++++ Setup.hs | 4 ++ configure.ac | 19 ++++++++ 7 files changed, 248 insertions(+) create mode 100644 .boring create mode 100644 Main.hs create mode 100644 Makefile create mode 100644 Rakka.buildinfo.in create mode 100644 Rakka.cabal create mode 100755 Setup.hs create mode 100644 configure.ac diff --git a/.boring b/.boring new file mode 100644 index 0000000..eac5262 --- /dev/null +++ b/.boring @@ -0,0 +1,55 @@ +# Boring file regexps: +\.hi$ +\.hi-boot$ +\.o-boot$ +\.o$ +\.o\.cmd$ +# *.ko files aren't boring by default because they might +# be Korean translations rather than kernel modules. +# \.ko$ +\.ko\.cmd$ +\.mod\.c$ +(^|/)\.tmp_versions($|/) +(^|/)CVS($|/) +\.cvsignore$ +^\.# +(^|/)RCS($|/) +,v$ +(^|/)\.svn($|/) +\.bzr$ +(^|/)SCCS($|/) +~$ +(^|/)_darcs($|/) +\.bak$ +\.BAK$ +\.orig$ +\.rej$ +(^|/)vssver\.scc$ +\.swp$ +(^|/)MT($|/) +(^|/)\{arch\}($|/) +(^|/).arch-ids($|/) +(^|/), +\.prof$ +(^|/)\.DS_Store$ +(^|/)BitKeeper($|/) +(^|/)ChangeSet($|/) +\.py[co]$ +\.elc$ +\.class$ +\# +(^|/)Thumbs\.db$ +(^|/)autom4te\.cache($|/) +(^|/)config\.(log|status)$ +^\.depend$ +(^|/)(tags|TAGS)$ +#(^|/)\.[^/] +(^|/|\.)core$ +\.(obj|a|exe|so|lo|la)$ +^\.darcs-temp-mail$ + +.setup-config$ +^Rakka.buildinfo$ +^Setup$ +^configure$ +^dist(/|$) diff --git a/Main.hs b/Main.hs new file mode 100644 index 0000000..942787c --- /dev/null +++ b/Main.hs @@ -0,0 +1,105 @@ +{-# LANGUAGE CPP #-} +import Control.Monad +import Data.Maybe +import Network +import System.Console.GetOpt +import System.Environment +import System.Exit +import System.Posix.Types +import System.Posix.User + +data CmdOpt + = OptPortNum PortNumber + | OptLSDir FilePath + | OptUserName String + | OptGroupName String + | OptHelp + deriving (Eq, Show) + + +defaultPort :: PortNumber +defaultPort = fromIntegral 8080 + +defaultUserName :: String +defaultUserName = "daemon" + +defaultGroupName :: String +defaultGroupName = "daemon" + + +options :: [OptDescr CmdOpt] +options = [ Option ['p'] ["port"] + (ReqArg (OptPortNum . fromIntegral . read) "NUM") + ("Port number to listen. (default: " ++ show defaultPort ++ ")") + + , Option ['d'] ["localstatedir"] + (ReqArg OptLSDir "DIR") + ("Path to the database directory. (default: " ++ LOCALSTATEDIR ++ ")") + + , Option ['u'] ["user"] + (ReqArg OptUserName "USER") + ("Which user to setuid. (default: " ++ defaultUserName ++ ")") + + , Option ['g'] ["group"] + (ReqArg OptGroupName "GROUP") + ("Which user to setgid. (default: " ++ defaultGroupName ++ ")") + + , Option ['h'] ["help"] + (NoArg OptHelp) + "Print this message." + ] + + +printUsage :: IO () +printUsage = do putStrLn "Usage:" + putStrLn " rakka [OPTIONS...]" + putStrLn "" + putStr $ usageInfo "Options:" options + + +main :: IO () +main = do (opts, nonOpts, errors) <- return . getOpt Permute options =<< getArgs + + when (not $ null errors) + $ do mapM_ putStr errors + exitWith $ ExitFailure 1 + + when (any (\ x -> x == OptHelp) opts) + $ do printUsage + exitWith ExitSuccess + + when (not $ null nonOpts) + $ do printUsage + exitWith $ ExitFailure 1 + + portNum <- getPortNum opts + uid <- getUserID opts + + print portNum + print uid + + +getPortNum :: [CmdOpt] -> IO PortNumber +getPortNum opts + = do let xs = mapMaybe (\ x -> case x of + OptPortNum n -> Just n + _ -> Nothing) opts + case xs of + [] -> return defaultPort + (x:[]) -> return x + _ -> error "too many --port options." + + +getUserID :: [CmdOpt] -> IO UserID +getUserID opts + = do let xs = mapMaybe (\ x -> case x of + OptUserName n -> Just n + _ -> Nothing) opts + name = case xs of + [] -> defaultUserName + (x:[]) -> x + _ -> error "too many --user options." + + userEnt <- getUserEntryForName name + return $ userID userEnt + \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..41fe052 --- /dev/null +++ b/Makefile @@ -0,0 +1,31 @@ +CABAL_FILE = Rakka.cabal +GHC = ghc +EXECUTABLE = ./dist/build/Rakka/rakka + +build: .setup-config Setup + ./Setup build + +run: build + @echo ".:.:. Let's go .:.:." + $(EXECUTABLE) + +.setup-config: $(CABAL_FILE) configure Setup Rakka.buildinfo.in + ./Setup configure + +configure: configure.ac + autoconf + +Setup: Setup.hs + $(GHC) --make Setup + +clean: + rm -rf dist Setup Setup.o Setup.hi .setup-config + find . -name '*~' -exec rm -f {} \; + +install: build + ./Setup install + +sdist: Setup + ./Setup sdist + +.PHONY: build run clean install doc sdist \ No newline at end of file diff --git a/Rakka.buildinfo.in b/Rakka.buildinfo.in new file mode 100644 index 0000000..f0b4306 --- /dev/null +++ b/Rakka.buildinfo.in @@ -0,0 +1,5 @@ +-- -*- haskell-cabal -*- +Executable: + rakka +GHC-Options: + -DLOCALSTATEDIR="@RAKKA_LOCALSTATEDIR@" diff --git a/Rakka.cabal b/Rakka.cabal new file mode 100644 index 0000000..ebb4531 --- /dev/null +++ b/Rakka.cabal @@ -0,0 +1,29 @@ +Name: + Rakka +Synopsis: + Wiki engine with Subversion backend +Description: + FIXME: write this +Version: + 0.1 +License: + PublicDomain +Author: + PHO +Maintainer: + PHO +Stability: + experimental +Homepage: + http://ccm.sherry.jp/Rakka/ +Category: + Web +Tested-With: + GHC == 6.6.1 +Build-Depends: + base, network, unix, Lucu + +Executable: + rakka +Main-Is: + Main.hs diff --git a/Setup.hs b/Setup.hs new file mode 100755 index 0000000..39a7547 --- /dev/null +++ b/Setup.hs @@ -0,0 +1,4 @@ +#!/usr/bin/env runghc + +import Distribution.Simple +main = defaultMainWithHooks defaultUserHooks diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..1a6e943 --- /dev/null +++ b/configure.ac @@ -0,0 +1,19 @@ +AC_INIT([Rakka], [], [phonohawk at ps dot sakura dot ne dot jp]) + +AC_CONFIG_SRCDIR([Rakka.cabal]) + +# $localstatedir has a reference to ${prefix} but the ${prefix} is +# "NONE" at this time. AC_OUTPUT changes the value of ${prefix} from +# "NONE" to $ac_default_prefix but it's too late! +if test "x$prefix" = "xNONE"; then + prefix=$ac_default_prefix +fi + +RAKKA_LOCALSTATEDIR=`eval echo "$localstatedir"`/rakka +AC_SUBST([RAKKA_LOCALSTATEDIR]) + +AC_CONFIG_FILES([ + Rakka.buildinfo +]) +AC_OUTPUT + -- 2.40.0