File: executable.sh~

package info (click to toggle)
cssc 1.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 11,368 kB
  • sloc: cpp: 39,446; ansic: 17,403; sh: 11,328; python: 3,923; makefile: 1,929; perl: 342; awk: 15; sed: 15
file content (96 lines) | stat: -rw-r--r-- 1,895 bytes parent folder | download
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
. ../common/test-common
. ../common/real-thing

g=foo
s=s.$g

cleanup() {
    cmd="rm -f ${g} ${s}"
    echo "${cmd}" >> command.log
    $cmd
}
cleanup

expect_args() {
    function_name="$1"
    expected="$2"
    got="$3"

    detail="expected ${expected} arguments, but got ${got}"
    if test "${got}" -lt "${expected}"; then
	miscarry "Too few arguments to ${function_name}: ${detail}"
    elif test "${got}" -gt "${expected}"; then
	miscarry "Too many arguments to ${function_name}: ${detail}"
    fi
}

should_support_execute_bits() {
    expect_args should_support_execute_bits 0 $#
    if "${TESTING_CSSC}"; then
	true
    else
	case "`uname -s`" in
	    SunOS) true;;
	    *) false;;
	esac
    fi
}

if should_support_execute_bits; then
    # Not using ! is a workaround for the fact that Solaris /bin/sh doesn't support it.
    true
else
    echo "Your version of SCCS is not expected to support execute permissions; skipping."
    exit 0
fi

file_permissions() {
    expect_args file_permissions 1 $#
    ls -ld "$1" 2> /dev/null | sed -n -e '1 s/^.\(.........\).*/\1/p' 
}

is_owner_executable() {
    expect_args is_owner_executable 1 $#
    case `file_permissions "$1"` in
	??x*) true;;
	*) false;;
    esac
}
  
is_group_executable() {
    expect_args is_group_executable 1 $#
    case `file_permissions "$1"` in
	?????x*) true;;
	*) false;;
    esac
}

is_other_executable() {
    expect_args is_other_executable 1 $#
    case `file_permissions "$1"` in
	????????x*) true;;
	*) false;;
    esac
}

execute_perms() {
    expect_args execute_perms 1 $#
    result=""
    if is_owner_executable "$1"; then
	result="${result}u"
    fi
    if is_group_executable "$1"; then
	result="${result}g"
    fi
    if is_other_executable "$1"; then
	result="${result}o"
    fi
    echo "${result}"
}

docommand --silent x00 "touch ${g}"
docommand x25 "test -x ${s}" 0 "" ""


cleanup
exit $rv