[r85]: do-detect-sudo.sh  Maximize  Restore  History

Download this file

52 lines (42 with data), 1.1 kB

 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
#!/bin/sh
# This work is partially financed by the European Commission under the
# Framework 6 Information Society Technologies Project
# "Wirelessly Accessible Sensor Populations (WASP)".
TARGET_LOCATION="$1"
if [ -z "$TARGET_LOCATION" ]; then
cat >&2 <<_EOF
do-detect-sudo is used internally only. Do not call it manually
Usage: do-detect-sudo.sh <directory to check write access>
_EOF
exit 1
fi
set -eu
istgtwritable() {
(
set -eu
$INSTALL_LAUNCHER mkdir -p "$TARGET_LOCATION"
$INSTALL_LAUNCHER touch "$TARGET_LOCATION"/test.dat
rc=$?
$INSTALL_LAUNCHER rm -f "$TARGET_LOCATION"/test.dat
exit $rc
) 2>/dev/null
}
INSTALL_LAUNCHER=
NEED_SUDO=0
istgtwritable || NEED_SUDO=1
if [ $NEED_SUDO = 1 ]; then
cat >&2 <<_EOF
Cannot write to $TARGET_LOCATION. Trying to use sudo. Please ensure that
1. sudo is installed
2. your account is privileged in /etc/sudoers
All binary installation tasks will be invoked using sudo.
_EOF
INSTALL_LAUNCHER=sudo
if ! sudo true || ! istgtwritable ; then
cat >&2 <<_EOF
Even using sudo, $TARGET_LOCATION is not writable. Aborting.
_EOF
exit 1
fi
fi
echo "$INSTALL_LAUNCHER"

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks