1+ #! /bin/bash
2+ # Licensed to the Apache Software Foundation (ASF) under one
3+ # or more contributor license agreements. See the NOTICE file
4+ # distributed with this work for additional information
5+ # regarding copyright ownership. The ASF licenses this file
6+ # to you under the Apache License, Version 2.0 (the
7+ # "License"); you may not use this file except in compliance
8+ # with the License. You may obtain a copy of the License at
9+ #
10+ # http://www.apache.org/licenses/LICENSE-2.0
11+ #
12+ # Unless required by applicable law or agreed to in writing, software
13+ # distributed under the License is distributed on an "AS IS" BASIS,
14+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+ # See the License for the specific language governing permissions and
16+ # limitations under the License.
17+
18+ # ###############################
19+ #
20+ # Prep
21+ #
22+ # ###############################
23+
24+ if [ " $1 " == " -h" ]; then
25+ echo " $0 [-h] <username> <uid> <gid>"
26+ echo " this script is used internally by other scripts in the same directory to create a user with the running host user's same uid and gid"
27+ exit 1
28+ fi
29+
30+ # arguments
31+ username=$1
32+ uid=$2
33+ gid=$3
34+ BUILD_HOME=$4
35+
36+ # ###############################
37+ #
38+ # Main
39+ #
40+ # ###############################
41+
42+ # disable git directory ownership checks
43+ su ${username} -c " git config --global safe.directory '*'"
44+
45+ if grep " ^ID=" /etc/os-release | grep -q ' debian\|ubuntu' ; then
46+ deluser docker
47+ adduser --quiet --disabled-login --no-create-home --uid $uid --gecos ${username} ${username}
48+ groupmod --non-unique -g $gid $username
49+ gpasswd -a ${username} sudo > /dev/null
50+ else
51+ adduser --no-create-home --uid $uid ${username}
52+ fi
53+
54+ # sudo priviledges
55+ echo " ${username} ALL=(root) NOPASSWD:ALL" > /etc/sudoers.d/${username}
56+ chmod 0440 /etc/sudoers.d/${username}
57+
58+ # proper permissions
59+ chown -R ${username} :${username} /home/docker
60+ chmod og+wx ${BUILD_HOME}
0 commit comments