File: check.awk

package info (click to toggle)
intel-mkl 2020.4.304-7
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 566,272 kB
  • sloc: xml: 3,919; sh: 798; python: 252; cpp: 211; ansic: 169; lisp: 145; awk: 117; makefile: 46
file content (169 lines) | stat: -rw-r--r-- 5,679 bytes parent folder | download | duplicates (4)
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# Copyright 2006-2020 Intel Corporation.
#
# This software and the related documents are Intel copyrighted materials,
# and your use of them is governed by the express license under which they
# were provided to you (License). Unless the License provides otherwise,
# you may not use, modify, copy, publish, distribute, disclose or transmit
# this software or the related documents without Intel's prior written
# permission.
#
# This software and the related documents are provided as is, with no express
# or implied warranties, other than those that are expressly stated in the
# License.

# Validates data in ini files. note it attempts to validate file names
# by regex because there is no other way to validate non-existent ones.

BEGIN {
    allokflag = 1;

    # try this out to see if you can break it
    # I used a regex because the user may not be running as root. in any
    # case we would not want to allow some paths even if they can be
    # created.
    filepat = "^/[a-zA-Z0-9 ._/-]*$";
    # we don't use --posix for compatibility reasons
    snpat = "^[a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9]-[a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9]$" ;
    lspat = "^[0-9]+@[a-zA-Z0-9._-]+$";

    # it would not be very hard to read the data from a file rather than
    # hardwire it as here.

    # this might be useful, if not remove it.

    # exclude table
    exclude["NO_VALIDATE"] = 1;  # example

    # validation data

    # section data is made up of "name1:val1:val2..." blocks separated
    # by ";". value strings are evaluated as regex, and may be fancier
    # than what is shown, for example [Yy][Ee][Ss]. regex can allow
    # arbitrary values, for example TEXT might be "[A-Za-z][A-Za-z_0-9]+"

	sections["silent"] = sections["silent"] "ACCEPT_EULA:^accept$:^decline$";
	sections["silent"] = sections["silent"] ";";
	sections["silent"] = sections["silent"] "CONTINUE_WITH_OPTIONAL_ERROR:^yes$:^no$";
	sections["silent"] = sections["silent"] ";";
	sections["silent"] = sections["silent"] "PSET_INSTALL_DIR:^/opt/intel$:^$:"filepat;
	sections["silent"] = sections["silent"] ";";
	sections["silent"] = sections["silent"] "CONTINUE_WITH_INSTALLDIR_OVERWRITE:^yes$:^no$";
	sections["silent"] = sections["silent"] ";";
	sections["silent"] = sections["silent"] "COMPONENTS:^ALL$:^DEFAULTS$:^$:"comppat;
	sections["silent"] = sections["silent"] ";";
	sections["silent"] = sections["silent"] "PSET_MODE:^install$:^repair$:^uninstall$";
	sections["silent"] = sections["silent"] ";";
	sections["silent"] = sections["silent"] "CLUSTER_INSTALL_REMOTE:^yes$:^no$";
	sections["silent"] = sections["silent"] ";";
	sections["silent"] = sections["silent"] "CLUSTER_INSTALL_TEMP:^$:"filepat;
	sections["silent"] = sections["silent"] ";";
	sections["silent"] = sections["silent"] "CLUSTER_INSTALL_MACHINES_FILE:^$:"filepat;
	sections["silent"] = sections["silent"] ";";
	sections["silent"] = sections["silent"] "SIGNING_ENABLED:^yes$:^no$";
	sections["silent"] = sections["silent"] ";";
	sections["silent"] = sections["silent"] "ARCH_SELECTED:^IA32$:^INTEL64$:^ALL$";
	sections["silent"] = sections["silent"] ";";
#for backward compatibility
	sections["silent"] = sections["silent"] "INSTALL_MODE:^RPM$:^NONRPM$";
	sections["silent"] = sections["silent"] ";";
	sections["silent"] = sections["silent"] "download_only:^yes$";
	sections["silent"] = sections["silent"] ";";
	sections["silent"] = sections["silent"] "download_dir:^$:"filepat;
	sections["silent"] = sections["silent"] ";";
        sections["silent"] = sections["silent"] "IGNORE_LARGE_FILES_DOWNLOAD:^yes$";
	sections["silent"] = sections["silent"] ";";
        sections["silent"] = sections["silent"] "MAX_COMPONENT_SIZE_MB:^[0-9]+$";
	sections["silent"] = sections["silent"] ";";
}

/^[A-Za-z][-A-Za-z_0-9]*=.*/ {     # name=value pair
    sub(/^[ \t]+/,"", $0);  # remove leading whitespaces
    sub(/[ \t]+$/,"", $0);  # remove trailing whitespaces
    if($0 ~ /..*[ \t].*/)   # check for space
    {
        if(split($0,nameval,"=") == 2)
        {
            name  = nameval[1];
            value = nameval[2];
            if(!validate(name,value))
            {
                allokflag = 0;
            }
        }
    }
    else
    {
        if(split($1,nameval,"=") == 2)
        {
            name  = nameval[1];
            value = nameval[2];

            if(!validate(name,value))
            {
                allokflag = 0;
            }
        }
    }

    next;
}

END {
    if(!allokflag)
    {
        print FILENAME " has errors";
        exit 1
    }
    else
    {
        exit 0
    }
}

function validate(name,value)
{
    if(name in exclude)  # skip it
    {
        return 1;
    }

    namefound = 0;

    sectiondata = sections["silent"];

    if((cnt = split(sectiondata,arr,";")))
    {
        for(i=1;i<=cnt;++i)
        {
            # split the name and possibly multiple values
            if((num = split(arr[i],list,":")))
            {
                # the first one is the name
                if(list[1] == name)
                {
                    namefound = 1;
                    # the rest are values
                    for(j=2;j<=num;++j)
                    {
                        # stop looking if we match
                        if(value ~ list[j])
                        {
                            return 1;
                        }
                    }
                }
            }
        }
    }

    if(namefound)
    {
        printf("\"%s\" is not a valid value for \"%s\"\n",value,name);
    }
    else
    {
        printf("Name \"%s\" is not valid\n",name);
    }

    return 0;
}