-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·68 lines (56 loc) · 1.57 KB
/
run.sh
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
#!/bin/bash
programName=$0
function usage {
echo ""
echo "Connect to a Docker container via sFTP"
echo ""
echo "usage: $programName --cid string "
echo ""
echo " --cid string container id (example: fe5780b2c44d)"
echo ""
}
function die {
printf "Script failed: %s\n\n" "$1"
exit 1
}
while [ $# -gt 0 ]; do
if [[ $1 == "--"* ]]; then
v="${1/--/}"
declare "$v"="$2"
shift
fi
shift
done
#RUN
if [[ -z $cid ]]; then
usage
die "Missing parameter --cid"
fi
containerName=$(docker inspect --format '{{.Name}}' "$cid" | sed 's/^\/\(.*\)/\1/')
echo "Start sftp-docker for container: $containerName"
workdirPath="/home/sftp-docker"
docker cp "docker-fs/sftp-docker" "$cid:$workdirPath"
if [ $? -ne 0 ]; then
echo "Failed to copy files to container ID: $cid"
exit 1
fi
docker exec "$cid" chmod -R +x "$workdirPath"
docker exec "$cid" "$workdirPath/setup_sftp.sh"
# Check if the chmod command was successful
if [ $? -ne 0 ]; then
echo "Failed to change file permissions in container ID: $cid"
exit 1
fi
ipAddress=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' "$cid")
if [ -z "$ipAddress" ]; then
networkMode=$(docker inspect --format '{{ .HostConfig.NetworkMode }}' "$cid")
if [ "$networkMode" = "host" ]; then
ipAddress="127.0.0.1"
else
echo "ERROR: Can not determinate ipAddress of container. Check its network"
fi
fi
ssh-keygen -f "$HOME/.ssh/known_hosts" -R "$ipAddress"
echo "Sftp-docker finished."
echo "ADDRESS : sftp://root@$ipAddress"
echo "PASSWORD: root"