Browse Source

First commit

Stephen Starkey 3 months ago
commit
76a2bbccae
5 changed files with 71 additions and 0 deletions
  1. 1
    0
      .gitignore
  2. 27
    0
      README.md
  3. 8
    0
      build.sh
  4. 33
    0
      ensure-mounted.scm
  5. 2
    0
      install-deps.sh

+ 1
- 0
.gitignore View File

@@ -0,0 +1 @@
1
+output

+ 27
- 0
README.md View File

@@ -0,0 +1,27 @@
1
+ensure-mounted
2
+==============
3
+
4
+Sometimes things in your `/etc/fstab` can't mount at startup. They
5
+have to be mounted a bit later. You can run this binary in your
6
+crontab to mount those things.
7
+
8
+preparing
9
+---------
10
+You need to install [https://call-cc.org/](Chicken Scheme).
11
+
12
+Then, run `./install-deps.sh` to install all the eggs this project
13
+requires.
14
+
15
+building
16
+--------
17
+After preparing, simply run `./build.sh`
18
+
19
+A binary called `ensure-mounted` will show up in the `output` directory.
20
+
21
+installing
22
+----------
23
+Put the binary somewhere and run it from your crontab.
24
+
25
+Here's an example cron line:
26
+
27
+    *  *    * * *   root    /usr/local/bin/ensure-mounted > /var/log/mounts.log 2>&1

+ 8
- 0
build.sh View File

@@ -0,0 +1,8 @@
1
+#!/bin/bash
2
+FILE=ensure-mounted.scm
3
+rm -rf output
4
+mkdir output
5
+cd output
6
+cp ../$FILE .
7
+csc $FILE
8
+rm -f $FILE

+ 33
- 0
ensure-mounted.scm View File

@@ -0,0 +1,33 @@
1
+(use posix)
2
+(use utils)
3
+(require-extension srfi-1) ;lists
4
+(require-extension srfi-113) ;sets
5
+(require-extension srfi-128) ;comparators
6
+(require-extension s) ;strings
7
+
8
+(define (start-ensure? v) (string=? "#== ensure-mounted" v))
9
+(define (end-ensure? v) (string=? "#== ensure-mounted-end" v))
10
+(define (mount-point line) (second (s-split " " line)))
11
+(define string-comparator (make-comparator string? string=? string<? string-hash))
12
+(define (mount-points lines) 
13
+  (list->set string-comparator (map mount-point lines)))
14
+
15
+(define (existing-mount-lines)
16
+  (s-split "\n" (read-all "/proc/mounts")))
17
+
18
+(define (desired-mount-lines)
19
+  (let ((fstab (s-split "\n" (read-all "/etc/fstab"))))
20
+    (let ((start-index (list-index start-ensure? fstab))
21
+       	  (end-index (list-index end-ensure? fstab)))
22
+      (if (and (> start-index 0) (> end-index start-index))
23
+        (let ((num-to-keep (- end-index start-index 1))) 
24
+          (take (drop fstab (+ 1 start-index)) num-to-keep))
25
+        (print "fstab is not properly annotated")))))
26
+
27
+(define (mount path)
28
+  (print "Mounting: " path)
29
+  (print (call-with-input-pipe (s-concat "mount " path) read-all)))
30
+
31
+(let ((existing (mount-points (existing-mount-lines)))
32
+      (desired (mount-points (desired-mount-lines))))
33
+  (set-for-each mount (set-difference desired existing)))

+ 2
- 0
install-deps.sh View File

@@ -0,0 +1,2 @@
1
+#!/bin/bash
2
+sudo chicken-install s srfi-1 srfi-113 srfi-128