-
Notifications
You must be signed in to change notification settings - Fork 3
/
versioncheck.hs
71 lines (59 loc) · 1.71 KB
/
versioncheck.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import Text.Parsec.Prim
import Text.Parsec.Char
import Text.Parsec.String
import Text.Parsec.Combinator
import System.FilePath ((</>))
import System.Posix.Files
import System.Directory
--import System.Process
isCabal :: String -> Bool
isCabal str
| length str > 6 = let ext = reverse . take 6 . reverse $ str in ext == ".cabal"
| otherwise = False
cabalName :: Parser String
cabalName = do
manyTill anyChar (try (string "Name:"))
spaces
many1 (noneOf " \n")
cabalVersion :: Parser String
cabalVersion = do
manyTill anyChar (try (string "Version:"))
spaces
many1 (oneOf "0123456789.")
nameVersion :: Parser (String,String)
nameVersion = do
n <- cabalName
v <- cabalVersion
return (n,v)
main = do
putStrLn "version check"
currdir <- getDirectoryContents "."
let cabalfile = head $ filter isCabal currdir
str <- readFile cabalfile
let Right (name,version) = parse nameVersion "" str
filename = name ++ "-" ++ version
linkbase = "/home/wavewave/nfs/doc/prog"
docbase = "/home/wavewave/nfs/usr/share/doc"
linkpath = linkbase </> name
origpath = docbase </> filename
putStrLn $ "ln -s " ++ origpath ++ " " ++ linkpath
test <- getDirectoryContents linkbase
if elem name test
then do
putStrLn "removing link"
removeLink linkpath
else do
putStrLn "doesn't exist"
return ()
{- putStrLn $ show test
b <- fileExist linkpath
if b
then do
putStrLn $ "removing link"
removeLink linkpath
else do
putStrLn $ "doesn't exist"
return () -}
{- readProcess "ln" ["-s", origpath, linkpath] "" -}
createSymbolicLink origpath linkpath
return ()