Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Really call function TRACE_disable_power().
[simgrid.git] / tools / check_dist_archive
1 #!/bin/bash
2
3 set -e
4
5 if [ "$1" = "-batch" ]; then
6     shift
7     interactive=0
8 elif [ -t 1 ]; then
9     interactive=1
10 else
11     interactive=0
12 fi
13
14 if [ $# -lt 1 -o $# -gt 3 ]; then
15     cat <<EOF
16 Usage: $0 [-batch] archive.tar.gz [git_url [git_branch]]
17 EOF
18     exit 1
19 fi
20
21 archive=$1
22 if [ ! -r "$archive" ]; then
23     printf 'File not found: %s\n' "$archive"
24     exit 1
25 fi
26
27 if [ $# -ge 2 ]; then
28     giturl=$2
29     gitbranch=${3:-master}
30 else
31     giturl=$(git rev-parse --show-toplevel)
32     gitbranch=$(git branch | sed -n '/^\*/{s/^..//;p;}')
33 fi
34
35 tmpdir=$(mktemp -d)
36 trap "rm -fr \"$tmpdir\"" EXIT
37
38 arch_dir="$tmpdir/a"
39 git_dir="$tmpdir/b"
40
41 myname=$(type -p "$0")
42 case "$myname" in
43     /*)
44         exclude="$myname.exclude"
45         ;;
46     *)
47         exclude="$PWD/$myname.exclude"
48         ;;
49 esac
50
51 if [ ! -r "$exclude" ]; then
52     printf 'File not found: %s\n' "$exclude"
53     exit 1
54 fi
55
56 echo "Exclude patterns extracted from file: $exclude"
57
58 echo "Extracting archive: $archive -> $arch_dir"
59 tar --directory "$tmpdir" \
60     --transform 's!^[^/]*!a!' \
61     --extract --gunzip --file "$archive"
62
63 echo "Copying git repository: $giturl/$gitbranch -> $git_dir"
64 git archive --format=tar --prefix="b/" --remote="$giturl" "$gitbranch" \
65     | tar --directory "$tmpdir" --extract --file -
66
67 fa=from_tgz
68 fb=from_git
69 cd "$tmpdir"
70
71 sed -n '/^-/{s/^- //;p;}' "$exclude" > ea
72 sed -n '/^+/{s/^+ //;p;}' "$exclude" > eb
73
74 find a -type f \
75     | sed 's!^a/!!' \
76     | grep -E -v -x -f ea \
77     | sort > "$fa"
78 find b -type f \
79     | sed 's!^b/!!' \
80     | grep -E -v -x -f eb \
81     | sort > "$fb"
82
83 diffcmd() {
84     if cmp -s "$fa" "$fb"; then
85         status=0
86         echo "The archive looks good."
87     else
88         status=1
89         echo "Some files are missing and/or unexpected in the archive."
90         diff -u "$fa" "$fb"
91     fi
92 }
93
94 colordiff=$(type -p colordiff)
95 colorless() {
96     if [ -x "$colordiff" ]; then
97         "$colordiff" | less -R -F -X
98     else
99         less -F -X
100     fi
101 }
102
103 if [ "$interactive" = "1" ]; then
104     diffcmd | colorless
105 else
106     diffcmd
107 fi || true
108
109 exit $status