-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathptree-update
More file actions
executable file
·99 lines (70 loc) · 2.03 KB
/
ptree-update
File metadata and controls
executable file
·99 lines (70 loc) · 2.03 KB
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
#!/bin/bash
ionice -c 3 -p $$
renice -n 15 -p $$
# change this
PORTDIR="/data/portage/tree/"
SQUASH_SOURCE="/data/portage/tree.squashfs"
TMPFS="/tmp"
TMPDIR="portage_tree_rw"
TMPFS_DEST="/tmp/portage_tree_merge"
# 1 = ask before running every command (do this the first time)
# 0 = just do it
TESTING=1
SQUASH_OPTS="-comp xz -b 1M -force-uid portage -force-gid portage"
# for testing purpuses
run() {
if [[ $TESTING -eq 0 ]]; then
printf "Running %s...\n" "$*"
else
printf "Run %s ? (y/n) " "$*"
read a
if [[ $a != y* ]]; then
printf " Not running %s.\n" "$*"
return;
fi
fi
eval "$@"
if [[ $? -ne 0 ]]; then
printf "Command returned %s\n" "$?"
read wait_
fi
}
if ! $(grep -q squashfs /proc/filesystems); then
printf "You don't have SquashFS support in /proc/filesystems\n"
return 1;
fi
if ! $(mount | grep -q " $TMPFS .* tmpfs "); then
printf "Please ensure %s is a real tmpfs\n" "$TMPFS"
return 1;
fi
# make sure the old squashfs image is mounted
if ! $(grep -q "$SQUASH_SOURCE" /proc/mounts); then
run mount -o ro "$SQUASH_SOURCE" "$PORTDIR"
fi
if grep -q aufs /proc/filesystems; then
run mkdir "$TMPFS/$TMPDIR"
run mkdir "$TMPFS_DEST"
run mount -t aufs treemerge -o "br:$TMPFS/$TMPDIR:$PORTDIR" "$TMPFS_DEST"
run PORTDIR="$TMPFS_DEST" emerge --sync --quiet
run mksquashfs "$TMPFS_DEST" "$SQUASH_SOURCE.new" $SQUASH_OPTS
run umount "$TMPFS_DEST"
run rmdir "$TMPFS_DEST"
run umount "$PORTDIR"
run rm -r "$TMPFS/$TMPDIR"
# run umount "$PORTDIR"
run mv "$SQUASH_SOURCE.new" "$SQUASH_SOURCE"
run mount -o ro "$SQUASH_SOURCE" "$PORTDIR"
else
# TODO: check if there is enaugh space on tmpfs
# TODO: check if there is enaugh ram
printf "Falling back to the old rsync way\n"
run rsync -au $PORTDIR $TMPFS_DEST
run mount --bind $TMPFS_DEST $PORTDIR
run emerge --sync --quiet
run umount $PORTDIR # bind mount
run umount $PORTDIR # old squashfs
run mv $SQUASH_SOURCE /tmp/ # backup
run mksquashfs $TMPFS_DEST $SQUASH_SOURCE $SQUASH_OPTS
run rm -r $TMPFS_DEST
run mount -o ro $SQUASH_SOURCE $PORTDIR
fi