]> src.bluestatic.org Git - armadillo.git/blob - main.go
Create a README file
[armadillo.git] / main.go
1 //
2 // Armadillo File Manager
3 // Copyright (c) 2010-2012, Robert Sesek <http://www.bluestatic.org>
4 //
5 // This program is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free Software
7 // Foundation, either version 3 of the License, or any later version.
8 //
9
10 package main
11
12 import (
13 "github.com/rsesek/armadillo/config"
14 "github.com/rsesek/armadillo/server"
15 "flag"
16 "fmt"
17 "os"
18 "strings"
19 )
20
21 var (
22 configPath = flag.String("config", "~/.armadillo", "Path to the configuration file")
23 jailRoot = flag.String("jail", "", "Restrict file operations to this directory root")
24 port = flag.Int("port", 0, "Port to run the server on")
25 )
26
27 func main() {
28 flag.Parse()
29
30 // Load the configuration file, if it is present.
31 var configuration = new(config.Configuration)
32 fmt.Printf("Reading configuration from %v\n", *configPath)
33 if len(*configPath) > 0 {
34 *configPath = strings.Replace(*configPath, "~", "$HOME", 1)
35 *configPath = os.ExpandEnv(*configPath)
36 error := config.ReadFromFile(*configPath, configuration)
37 if error != nil {
38 fmt.Printf("Error while reading configuration: %v\n", error)
39 }
40 }
41
42 // Override configuration values with command line arguments.
43 if *jailRoot != "" {
44 configuration.JailRoot = *jailRoot
45 }
46 if *port != 0 {
47 configuration.Port = *port
48 }
49
50 if configuration.Port == 0 {
51 fmt.Printf("Failed to start server (invalid port)\n")
52 os.Exit(1)
53 }
54
55 // Run the server.
56 fmt.Printf("Starting Armadillo on port %d with root:\n %v\n",
57 configuration.Port, configuration.JailRoot)
58 server.RunBackEnd(configuration)
59 }