github.com/Mirantis/virtlet@v1.5.2-0.20191204181327-1659b8a48e9b/images/image_skel/rsyncd.sh (about) 1 #!/bin/bash 2 3 # TODO: only include this script in the build image 4 5 # based on build/rsync.sh from Kubernetes. Original copyright follows: 6 7 # Copyright 2016 The Kubernetes Authors. 8 # 9 # Licensed under the Apache License, Version 2.0 (the "License"); 10 # you may not use this file except in compliance with the License. 11 # You may obtain a copy of the License at 12 # 13 # http://www.apache.org/licenses/LICENSE-2.0 14 # 15 # Unless required by applicable law or agreed to in writing, software 16 # distributed under the License is distributed on an "AS IS" BASIS, 17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 # See the License for the specific language governing permissions and 19 # limitations under the License. 20 21 # This script will set up and run rsyncd to allow data to move into and out of 22 # our dockerized build system. This is used for syncing sources and changes of 23 # sources into the docker-build-container. It is also used to transfer built binaries 24 # and generated files back out. 25 # 26 # When run as root (rare) it'll preserve the file ids as sent from the client. 27 # Usually it'll be run as non-dockerized UID/GID and end up translating all file 28 # ownership to that. 29 30 31 set -o errexit 32 set -o nounset 33 set -o pipefail 34 35 port="${1:-8730}" 36 if [[ $# > 0 ]]; then 37 shift 38 fi 39 40 # The directory that gets sync'd 41 VOLUME=/go/src/github.com/Mirantis/virtlet 42 43 CONFDIR="/tmp/rsync.virtlet" 44 PIDFILE="${CONFDIR}/rsyncd.pid" 45 CONFFILE="${CONFDIR}/rsyncd.conf" 46 SECRETS="${CONFDIR}/rsyncd.secrets" 47 48 mkdir -p "${CONFDIR}" 49 50 if [[ -f "${PIDFILE}" ]]; then 51 PID=$(cat "${PIDFILE}") 52 echo "Cleaning up old PID file: ${PIDFILE}" 53 kill $PID &> /dev/null || true 54 rm "${PIDFILE}" 55 fi 56 57 PASSWORD=$(</rsyncd.password) 58 59 cat <<EOF >"${SECRETS}" 60 virtlet:${PASSWORD} 61 EOF 62 chmod go= "${SECRETS}" 63 64 USER_CONFIG= 65 if [[ "$(id -u)" == "0" ]]; then 66 USER_CONFIG=" uid = 0"$'\n'" gid = 0" 67 fi 68 69 cat <<EOF >"${CONFFILE}" 70 pid file = ${PIDFILE} 71 use chroot = no 72 log file = /dev/stdout 73 reverse lookup = no 74 munge symlinks = no 75 port = ${port} 76 address = 127.0.0.1 77 [virtlet] 78 numeric ids = true 79 $USER_CONFIG 80 auth users = virtlet 81 secrets file = ${SECRETS} 82 read only = false 83 path = ${VOLUME} 84 EOF 85 # removed for now: 86 # filter = - /.make/ - /.git/ - /_tmp/ 87 88 exec /usr/bin/rsync --no-detach --daemon --config="${CONFFILE}" "$@"