aboutsummaryrefslogtreecommitdiffstats
path: root/Mk/Scripts/qa.sh
blob: 172079809439beac103b83535afb8597794531fa (plain) (blame)
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/bin/sh
# MAINTAINER: portmgr@FreeBSD.org
# $FreeBSD$

if [ -z "${STAGEDIR}" -o -z "${PREFIX}" -o -z "${LOCALBASE}" ]; then
    echo "STAGEDIR, PREFIX, LOCALBASE required in environment." >&2
    exit 1
fi

LF=$(printf '\nX')
LF=${LF%X}

warn() {
    echo "Warning: $@" >&2
}

err() {
    echo "Error: $@" >&2
}

shebang() {
    local IFS rc

    rc=0
    IFS="$LF"
    
    for f in `find ${STAGEDIR} -type f -perm +111`; do
        interp=$(sed -n -e '1s/^#![[:space:]]*\([^[:space:]]*\).*/\1/p;2q' $f)
        case "$interp" in
        "") ;;
        /usr/bin/env) ;;
        ${LOCALBASE}/*) ;;
        ${PREFIX}/*) ;;
        /usr/bin/awk) ;;
        /usr/bin/sed) ;;
        /usr/bin/nawk) ;;
        /bin/csh) ;;
        /bin/sh) ;;
        *)
            err "${interp} is an invalid shebang you need USES=shebangfix for ${f#${STAGEDIR}${PREFIX}/}"
            rc=1
            ;;
        esac
    done

    return ${rc}
}

symlinks() {
    local rc

    rc=0

    while read l link; do
        [ -z "${l}" ] && continue
        case "${link}" in
            ${STAGEDIR}*)
                err "Bad symlinks ${l} pointing inside the stage directory"
                rc=1
                ;;
        esac
    # Use heredoc to avoid losing rc from find|while subshell
    done << EOF
$(find ${STAGEDIR} -type l -exec stat -f "%N %Y" {} +)
EOF

    return ${rc}
}

paths() {
    local rc

    rc=0

    while read f; do
        [ -z "${f}" ] && continue
        # Ignore false-positive/harmless files
        case "${f}" in
            */lib/ruby/gems/*/Makefile) continue ;;
            */lib/ruby/gems/*/Makefile.html) continue ;;
            */lib/ruby/gems/*/mkmf.log) continue ;;
        esac
        err "${f} is referring to ${STAGEDIR}"
        rc=1
    # Use heredoc to avoid losing rc from find|while subshell
    done << EOF
$(find ${STAGEDIR} -type f -exec grep -l "${STAGEDIR}" {} +)
EOF

    return ${rc}
}

# For now do not raise an error, just warnings
stripped() {
    [ -x /usr/bin/file ] || return # this is fatal
    [ -n "${STRIP}" ] || return 0
    find ${STAGEDIR} -type f -exec /usr/bin/file -nNF '' {} + | while
        read f output; do
        case "${output}" in
            ELF\ *,\ not\ stripped*) warn "${f} is not stripped consider using \${STRIP_CMD}" ;;
        esac
    done
}

desktopfileutils() {
    if [ -z "${USESDESKTOPFILEUTILS}" ]; then
        grep -q MimeType= ${STAGEDIR}${PREFIX}/share/applications/*.desktop 2>/dev/null &&
        warn "you need USES=desktop-file-utils"
    else
        grep -q MimeType= ${STAGEDIR}${PREFIX}/share/applications/*.desktop 2>/dev/null ||
        warn "you may not need USES=desktop-file-utils"
    fi
    return 0
}

sharedmimeinfo() {
    local f found

    found=0
    for f in ${STAGEDIR}${PREFIX}/share/mime/packages/*.xml; do
        [ "${f}" = "${STAGEDIR}${PREFIX}/share/mime/packages/*.xml" ] && break #no matches
        [ "${f}" = "${STAGEDIR}${PREFIX}/share/mime/packages/freedesktop.org.xml" ] && continue
        found=1
        break
    done
    if [ -z "${USESSHAREDMIMEINFO}" -a ${found} -eq 1 ]; then
        warn "you need USES=shared-mime-info"
    elif [ -n "${USESSHAREDMIMEINFO}" -a ${found} -eq 0 ]; then
        warn "you may not need USES=shared-mime-info"
    fi
    return 0
}

suidfiles() {
    local filelist

    filelist=`find ${STAGEDIR} -type f \
        \( -perm -u+x -or -perm -g+x -or -perm -o+x \) \
        \( -perm -u+s -or -perm -g+s \)`
    if [ -n "${filelist}" ]; then
        warn "setuid files in the stage directory (are these necessary?):"
        ls -liTd ${filelist}
    fi
    return 0
}

checks="shebang symlinks paths stripped desktopfileutils sharedmimeinfo suidfiles"

ret=0
cd ${STAGEDIR}
for check in ${checks}; do
    ${check} || ret=1
done

exit $ret