Skip to content

Commit 7089bfd

Browse files
BackSlasheridoby
authored andcommitted
Shared saver cleanup, better regex
1 parent 79c09d4 commit 7089bfd

File tree

1 file changed

+6
-35
lines changed

1 file changed

+6
-35
lines changed

shared-saver/script.sh

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,14 @@
11
#!/bin/sh
2-
### BEGIN INIT INFO
3-
# Provides:
4-
# Required-Start: $remote_fs $syslog
5-
# Required-Stop: $remote_fs $syslog
6-
# Default-Start: 2 3 4 5
7-
# Default-Stop: 0 1 6
8-
# Short-Description: Saves or loads VBox's shared folders
9-
# Description: Saves or loads VBox's shared folders
10-
### END INIT INFO
11-
122
set -e
133
set -x
144

155
# https://raw.githubusercontent.com/fhd/init-script-template/master/template
166

17-
dir=""
18-
cmd=""
19-
user=""
20-
21-
name=`basename $0`
22-
237
DUMP_FILE=/var/local/shared-saver-dump
24-
KERNEL_PASSPHRASE=root
25-
#KERNEL_PASSPHRASE=khack-kexec
26-
27-
LOGFILE="/home/vagrant/shared-saver-log-$(date '+%Y-%m-%d-%H-%M-%S')"
28-
log() {
29-
echo "$@" >>"$LOGFILE"
30-
}
318

329
save_file() {
33-
log 'saving mounts'
34-
mount | perl -ne 'print "$1\t$2\tvboxsf\tdefaults\t0\t0$/" if /^([\w\/]+) on (.+) type vboxsf \(.+\)$/' | tee "$DUMP_FILE"
10+
echo 'saving'
11+
mount | perl -ne 'print "$1\t$2\tvboxsf\tdefaults\t0\t0$/" if /^(\S+) on (.+) type vboxsf \(.+\)$/' | tee "$DUMP_FILE"
3512
}
3613

3714
is_magic() {
@@ -40,35 +17,29 @@ is_magic() {
4017

4118
force_load_file() {
4219
if [ -f "$DUMP_FILE" ]; then
20+
'file found, loading'
4321
mount -aT "$DUMP_FILE"
4422
else
45-
log 'file not found, skipping'
23+
echo 'file not found, skipping'
4624
fi
4725
}
4826

4927
load_file() {
50-
log 'loading mounts, before checking'
28+
echo 'loading mounts, before checking'
5129
if is_magic; then
5230
force_load_file
5331
fi
5432
}
5533

5634
case "$1" in
5735
start)
58-
# TODO do we need to handle /var/lock/subsys? https://unix.stackexchange.com/a/114277
59-
# TODO read state if we have the magic passphrase in kernel CLI
6036
load_file
6137
;;
6238
stop)
63-
# TODO dump state to file
6439
save_file
6540
;;
66-
status)
67-
# We're never running
68-
echo "This is useless"
69-
;;
7041
*)
71-
echo "Usage: $0 {start|stop|status}"
42+
echo "Usage: $0 {start|stop}"
7243
exit 1
7344
;;
7445
esac

0 commit comments

Comments
 (0)