-
Notifications
You must be signed in to change notification settings - Fork 0
/
sqo
executable file
·101 lines (85 loc) · 2.63 KB
/
sqo
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/sbin/runscript
# Copyright 1999-2006 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $
#
# /etc/init.d/squash_overlays allows efficient compression of
# Gentoo overlays arborescence
#
# It requires support for the loop device and squashfs enabled in the kernel,
# module autoloading is also *highly* recommended.
#
# Author: Mathias Laurin <[email protected]>
# 2006-11-28, v.0.1.5(4)
# patched for aufs - yoshi314
PORTDIR=/mnt/storage/overlays
SQFS_DIRNAME=/mnt/storage
SQFS_CUR="$SQFS_DIRNAME/overlays.sqfs"
SQFS_NEW="$SQFS_DIRNAME/overlays-current.sqfs"
SQFS_OLD="$SQFS_DIRNAME/overlays-old.sqfs"
DEF_RW="/dev/shm/.overlays-rw"
PMANAGER=paludis
#compression: currently available are xz, lzo, gzip
#this might fail if your mksquashfs is older and doesn't support that option
COMP=gzip
depend() {
use local
}
if [ "$PMANAGER" = "paludis" ] ; then
_UID=$(grep ^paludisbuild /etc/passwd | cut -d\: -f3)
_GID=$(grep ^paludisbuild /etc/group | cut -d\: -f3)
else
_UID=$(grep ^portage /etc/passwd | cut -d\: -f3)
_GID=$(grep ^portage /etc/group | cut -d\: -f3)
fi
setup() {
rm "$SQFS_OLD" "$SQFS_NEW"
einfo "Attempting to build initial squashfs image from $PORTDIR"
mksquashfs $PORTDIR $SQFS_NEW -force-uid ${_UID} -force-gid ${_GID} -comp $COMP -no-recovery 2>/dev/null
}
start() {
ebegin "Mounting read-only squashfs image"
if [ ! -f "$SQFS_CUR" ] ; then
if [ ! -f "$SQFS_OLD" ]; then
einfo "it appears you have no squashfs images yet. If you want to create initial images from $PORTDIR, run $0 setup"
retval=1
eend $retval
fi
fi
mount -rt squashfs -o loop,nodev,noexec $SQFS_CUR $PORTDIR
retval=$?
eend $retval
[ $retval -ne 0 ] && return $retval
ebegin "Mounting read-write with unionfs"
if [ ! $PORTAGE_RW ]
then
einfo " mounted in tmpfs (RAM)"
PORTAGE_RW="${DEF_RW}"
fi
[ -d $PORTAGE_RW ] || mkdir -p $PORTAGE_RW
chmod 0750 $PORTAGE_RW
chown ${_UID}:${_GID} $PORTAGE_RW
mount -t aufs -o br=$PORTAGE_RW=rw:$PORTDIR=ro none $PORTDIR
eend $?
}
stop() {
ebegin "Updating overlays tree"
[ ! $PORTAGE_RW ] && PORTAGE_RW="${DEF_RW}"
if [ ! -z `ls -A --ignore=.wh* $PORTAGE_RW | head -n1` ]
then
einfo " Syncing the tree"
mv -f $SQFS_NEW $SQFS_OLD
mksquashfs $PORTDIR $SQFS_NEW -force-uid ${_UID} -force-gid ${_GID} -comp $COMP -no-recovery 2>/dev/null
retval=$?
ln -sf $SQFS_NEW $SQFS_CUR
else
einfo " Nothing to do"
retval=0
fi
eend $retval
ebegin "Unmounting the tree"
umount -t aufs $PORTDIR
umount -t squashfs $PORTDIR
rm -rf $PORTAGE_RW
eend 0
}