@@ -4,6 +4,7 @@ use std::path::{Path, PathBuf};
4
4
5
5
use argh:: FromArgs ;
6
6
use cookie_store:: { Cookie , CookieStore } ;
7
+ use daemonize_me:: Daemon ;
7
8
use etcetera:: BaseStrategy ;
8
9
use fuser:: MountOption ;
9
10
use url:: Url ;
@@ -14,13 +15,16 @@ use lib_bb::client::BBAPIClient;
14
15
#[ derive( FromArgs ) ]
15
16
/// A CLI tool to authenticate to and mount BlackboardFS
16
17
struct BbfsCli {
18
+ #[ argh( switch, short = 'm' ) ]
19
+ monitor : bool ,
17
20
/// the path to mount the Blackboard filesystem at
18
21
#[ argh( positional) ]
19
22
mount_point : PathBuf ,
20
23
}
21
24
22
25
fn main ( ) -> anyhow:: Result < ( ) > {
23
26
let args: BbfsCli = argh:: from_env ( ) ;
27
+ let mount_point = args. mount_point . canonicalize ( ) . unwrap ( ) ;
24
28
25
29
let strategy = etcetera:: choose_base_strategy ( ) . unwrap ( ) ;
26
30
let data_dir = {
@@ -31,16 +35,24 @@ fn main() -> anyhow::Result<()> {
31
35
} ;
32
36
33
37
let cookie_file = data_dir. join ( "cookie" ) ;
38
+ let stdout =
39
+ File :: create ( data_dir. join ( "stdout.log" ) ) . expect ( "failed to create stdout log file" ) ;
40
+ let stderr =
41
+ File :: create ( data_dir. join ( "stderr.log" ) ) . expect ( "failed to create stderr log file" ) ;
34
42
35
43
let bb_url = Url :: parse ( "https://learn.uq.edu.au/" ) . unwrap ( ) ;
36
44
37
45
let cookies = find_cookies ( & cookie_file, & bb_url) . unwrap ( ) ;
38
46
47
+ if !args. monitor {
48
+ Daemon :: new ( ) . stdout ( stdout) . stderr ( stderr) . start ( ) . unwrap ( ) ;
49
+ }
50
+
39
51
let client = BBAPIClient :: new ( cookies) ;
40
52
fuser:: mount2 (
41
53
BBFS :: new ( client) ,
42
- & args . mount_point ,
43
- & [ MountOption :: AutoUnmount ] ,
54
+ mount_point,
55
+ & [ MountOption :: AutoUnmount , MountOption :: RO ] ,
44
56
)
45
57
. unwrap ( ) ;
46
58
Ok ( ( ) )
0 commit comments