1 # reexec library script
4 Copyright (c) 2000-2012, CyberLeo
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
10 * Redistributions of the source code must retain the above copyright
11 notice, this list of conditions, and the following disclaimer.
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions, and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15 * Neither the name of the organization nor the names of its contributors
16 may be used to endorse or promote products derived from this software
17 without specific prior written permission.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
25 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 HOWEVER CAUSED AND ON ANY THEORY OF LIABILTY, WHETHER IN CONTRACT, STRICT
27 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
28 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 if [ -z "${__reexec_sh_loaded}" ]
34 __reexec_sh_loaded=yes
35 echo "**** Deprecated: Use suexec instead ****" >&2
37 # exec a command via sudo/su
38 # Can be used to reexec this process, if run like this from the top-level:
39 # reexec "${0}" "${@}"
40 # Specify target user name with -u as the first parameter
41 # reexec -u user "${0}" "${@}"
44 # Set name if user provided
52 if [ "$(id -un)" != "${user}" ]
56 [ -x "$(which sudo 2>/dev/null)" ] || cmd="su ${user} -c"