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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
From 4e7ab7455206ec157a72d07c40c07f1a299529f1 Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org>
Date: Fri, 3 Dec 2010 08:49:43 +0000
Subject: [PATCH] lbu: remount LBU_MEDIA as read-write if it was read-only
ref #477
---
lbu.in | 34 +++++++++++++++++++++++++++++-----
1 files changed, 29 insertions(+), 5 deletions(-)
diff --git a/lbu.in b/lbu.in
index dfd7e3c..a0dfe16 100644
--- a/lbu.in
+++ b/lbu.in
@@ -1,7 +1,7 @@
#!/bin/sh
# lbu - utility to create local backups.
-# Copyright (c) 2006 Natanael Copa
+# Copyright (c) 2006-2010 Natanael Copa <ncopa@alpinelinux.org>
# May be distributed under GPL2
VERSION=@VERSION@
@@ -54,6 +54,9 @@ Common options:
cleanup() {
local i
+ for i in $REMOUNT_RO_LIST; do
+ mount -o remount,ro $i
+ done
for i in $UMOUNT_LIST; do
umount $i
done
@@ -64,9 +67,30 @@ exit_clean() {
exit 1
}
+# check if given dir is not a mounted mountpoint
+is_unmounted() {
+ awk "\$2 == \"$1\" {exit 1}" /proc/mounts
+}
+
mount_once() {
- if awk "\$2 == \"$1\" {exit 1}" /proc/mounts; then
- mount $1 && UMOUNT_LIST="$1 $UMOUNT_LIST"
+ if is_unmounted "$1"; then
+ mount $1 && UMOUNT_LIST="$1 $UMOUNT_LIST" || return 1
+ fi
+}
+
+# check if given dir is read-only
+is_ro() {
+ local tmpfile=$(mktemp -p "$1")
+ [ -z "$tmpfile" ] && return 0
+ rm -f "$tmpfile"
+ return 1
+}
+
+mount_once_rw() {
+ mount_once "$1" || return 1
+ if is_ro "$1"; then
+ REMOUNT_RO_LIST="$1 $REMOUNT_RO_LIST"
+ mount -o remount,rw "$1"
fi
}
@@ -385,7 +409,7 @@ cmd_commit() {
# mount media unles its already mounted
mnt=/media/$media
[ -d "$mnt" ] || usage
- mount_once "$mnt" || die "failed to mount $mnt"
+ mount_once_rw "$mnt" || die "failed to mount $mnt"
# find the outfile
outfile="$mnt/$(hostname).apkovl.tar.gz"
@@ -538,7 +562,7 @@ cmd_revert() {
if [ -n "$ENCRYPTION" ]; then
current="$current.$ENCRYPTION"
fi
- mount_once "$mnt" || die "failed to mount $mnt"
+ mount_once_rw "$mnt" || die "failed to mount $mnt"
[ -f "$revertto" ] || die "file not found: $revertto"
backup_apkovl "$current"
vecho "Reverting to $1"
--
1.7.3.2
|