forked from clearlinux/mixer-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
superpack-maker.sh
executable file
·107 lines (92 loc) · 3.63 KB
/
superpack-maker.sh
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
102
103
104
105
106
107
#!/bin/bash
# Create super packs
#
# usage:
#
# mixer-superpack-maker.sh <to version> <delta pack count> [<update directory>]
#
# mixer-superpack-maker.sh 2820 5 /home/clr/mix/update
# Creates superpack for version 2820. The superpack will replace the
# oldest pack in that directory, excluding zero packs. 5 delta packs will
# remain unchanged, the remaining delta packs will by symlinked to the
# superpack. This script will use /home/clr/mix/update for the update
# directory.
#
# mixer-superpack-maker.sh 2820 5
# Same as above except the update dir will default to /var/lib/update
# NOTE: delta packs must be created by calling mixer-pack-maker.sh before
# calling this script.
if [ -z "$1" ]; then
echo "$0 - missing to version"
exit 1
fi
if [ -z "$2" ]; then
echo "$0 - missing delta pack count"
exit 1
fi
TO_VER=$1 # $MIXVER in create_update.sh
DELTA_PACK_COUNT=$2 # $DELTA_PACK_COUNT in create_update.sh
UPDATE_DIR=${3:-"/var/lib/update"} # Defaults to /var/lib/update
WORK_DIR=$UPDATE_DIR/www/$TO_VER
CUR_DIR=$PWD
# Measure size of all packs before superpack created, report to stdout
INIT_SIZE=`sudo du -sck $WORK_DIR/pack* | tail -1 | awk {'print $1'}`
echo "Initial size before super pack created: $INIT_SIZE kB"
# Get a list of all bundles
MOM=$WORK_DIR/Manifest.MoM
BUNDLE_LIST=$(cat ${MOM} | awk -v V=${TO_VER} '$1 ~ /^M\./ && $3 == V { print $4 }')
for BUNDLE in $BUNDLE_LIST; do
#SUPERPACK=""
echo "Creating superpack for $BUNDLE"
VER_LIST=()
# Get a list of all packs except 0 pack
VER_LIST=`ls $WORK_DIR | egrep -o "pack-$BUNDLE-from-[0-9]+.tar" | egrep -o '[1-9][0-9]*0'`
# Store in temporary file so we can version sort
for v in ${VER_LIST[@]}; do echo $v >> $WORK_DIR/tempver; done
if [ -e ${WORK_DIR}/tempver ]; then
VER_LIST=`sort --version-sort $WORK_DIR/tempver`
sudo rm $WORK_DIR/tempver
fi
VER_LIST=($VER_LIST)
# Make the super pack
# untar into superpack/delta and superpack/staged directory
# all delta files have different names to they won't be overwritten
# duplicate fullfiles are overwritten - this is where we save space
sudo mkdir -p "$WORK_DIR/superpack"/{"delta","staged"}
sudo mkdir $WORK_DIR/tmp
for v in ${VER_LIST[@]}; do
# untar into a tmp directory so we can move everything over
sudo tar -xf "$WORK_DIR/pack-$BUNDLE-from-$v.tar" -C $WORK_DIR/tmp
mv "$WORK_DIR/tmp/delta"/* "$WORK_DIR/superpack/delta" 2>/dev/null
mv "$WORK_DIR/tmp/staged"/* "$WORK_DIR/superpack/staged" 2>/dev/null
done
sudo rm -rf $WORK_DIR/tmp
# tar everything in the superpack into a tar file named for the oldest
# existing delta pack in the directory.
cd $WORK_DIR/superpack
sudo tar -cf "pack-$BUNDLE-from-${VER_LIST[0]}.tar" *
sudo mv "pack-$BUNDLE-from-${VER_LIST[0]}.tar" $WORK_DIR/
cd $CUR_DIR
sudo rm -rf $WORK_DIR/superpack
# remove unnecessary delta packs and create symlinks to the superpack with
# the same name as the removed delta pack.
let "NUM_PACKS = ${#VER_LIST[@]}"
let "END_BRIDGE = $NUM_PACKS - $DELTA_PACK_COUNT"
SUPERPACK="$WORK_DIR/pack-$BUNDLE-from-${VER_LIST[0]}.tar"
i=1
for v in ${VER_LIST[@]:1}; do
if [ $i -lt $END_BRIDGE ] && [ $NUM_PACKS -gt 1 ]; then
sudo rm "$WORK_DIR/pack-$BUNDLE-from-$v.tar"
sudo ln -s "$SUPERPACK" "$WORK_DIR/pack-$BUNDLE-from-$v.tar"
fi
let "i++"
done
# finally, compress the superpack and remove the .xz extension
sudo xz $SUPERPACK
sudo mv "$SUPERPACK.xz" $SUPERPACK
done
# report end size and delta size
END_SIZE=`sudo du -sck $WORK_DIR/pack* | tail -1 | awk {'print $1'}`
echo "Pack size after super pack created: $END_SIZE kB"
let "DELTA_SIZE = $END_SIZE - $INIT_SIZE"
echo "Total delta: $DELTA_SIZE kB"