~jdstrand/ufw/trunk

« back to all changes in this revision

Viewing changes to snap-files/bin/srv

  • Committer: Jamie Strandboge
  • Date: 2016-12-26 19:43:56 UTC
  • mto: This revision was merged to the branch mainline in revision 968.
  • Revision ID: jamie@ubuntu.com-20161226194356-271jrb9db9jd0vl2
update to use snapcraft wholly:
- add snapcraft.yaml with make plugin
- adjust Makefile to take SNAP=yes arg for 'all' and 'install'
- remove snappy-packaging/
- add snap-files/bin/*

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
set -e
 
3
 
 
4
if [ -z "$SNAP" ]; then
 
5
    echo "SNAP not set"
 
6
    exit 1
 
7
fi
 
8
 
 
9
upgrade_path="$SNAP_DATA/.upgraded_${SNAP_VERSION}"
 
10
prev_rules="$SNAP_DATA/.rules.orig"
 
11
 
 
12
copy_if_same() {
 
13
    bn="$1"
 
14
    prev_shipped="$prev_rules/$bn"
 
15
    inuse="$SNAP_DATA/etc/ufw/$bn"
 
16
    new_shipped="$SNAP/usr/share/ufw/iptables/$bn"
 
17
 
 
18
    # if the old shipped rules are the same as the rules in use, but the new
 
19
    # shipped rules are different, then copy the new rules to the rules in use
 
20
    if diff "$prev_shipped" "$inuse" >/dev/null ; then
 
21
        if ! diff "$new_shipped" "$prev_shipped" > /dev/null ; then
 
22
            echo "Updating '$bn'"
 
23
            cp -f --preserve=mode "$new_shipped" "$inuse"
 
24
        else
 
25
            echo "'$bn' has changes that cannot be merged. For details, see:"
 
26
            echo "$ diff -Nau $new_shipped $inuse"
 
27
        fi
 
28
    fi
 
29
}
 
30
 
 
31
# First run, none of this exists, so just copy over wholesale
 
32
if [ ! -e "$SNAP_DATA/lib" ]; then
 
33
    cp -fr --preserve=mode "$SNAP/lib" "$SNAP_DATA"
 
34
fi
 
35
if [ ! -e "$SNAP_DATA/etc" ]; then
 
36
    cp -fr --preserve=mode "$SNAP/etc" "$SNAP_DATA"
 
37
    chmod 640 "$SNAP_DATA"/etc/ufw/*.rules
 
38
    chmod 640 "$SNAP_DATA"/etc/ufw/*.init
 
39
fi
 
40
 
 
41
# Next, make sure these files are available for upgrade comparisons
 
42
if [ ! -e "$prev_rules" ]; then
 
43
    mkdir "$prev_rules"
 
44
fi
 
45
 
 
46
# On upgrades, detect if the rules file matches the shipped file, and if
 
47
# so, apply any changes to the rules file (ie, emulate ucf)
 
48
if [ ! -e "$upgrade_path" ]; then
 
49
    for fn in before.rules before6.rules after.rules after6.rules ; do
 
50
        if [ -e "$prev_rules/$fn" ]; then
 
51
            copy_if_same "$fn"
 
52
        fi
 
53
        # create/overwrite the new, upgraded rules for comparison on next
 
54
        # upgrade
 
55
        cp -f --preserve=mode "$SNAP/usr/share/ufw/iptables/$fn" "$prev_rules"
 
56
    done
 
57
 
 
58
    # remove old for housekeeping
 
59
    rm -f "$SNAP_DATA/.upgraded*"
 
60
 
 
61
    # add new
 
62
    touch "$upgrade_path"
 
63
fi
 
64
 
 
65
"$SNAP"/lib/ufw/ufw-init --rootdir "$SNAP" --datadir "$SNAP_DATA" start