-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrs.sh
129 lines (102 loc) · 2.53 KB
/
rs.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# //////////////////////////////////////////////////////////////////////////// #
# // ARGS PARSE ////////////////////////////////////////////////////////////// #
# //////////////////////////////////////////////////////////////////////////// #
SCRIPTNAME=$(basename "$0")
SCRIPT_DIR=$(dirname "$0")
log() {
>&2 echo " |$_err $1"
}
print_help() {
cat << EOF
Usage: $SCRIPTNAME [options] [commands]
options
-------
-h|--help) get this help
-C|--config) set distribution config file
-v|--verbose) show script source script
-c ) reserved for Makefile operations
EOF
}
## parse cmd parameters:
while [[ "$1" == -* ]] ; do
case "$1" in
-h|--help)
print_help
exit
;;
-c) # this argument is reserved for shell execution (by Makefile)
CMD=shell
shift
break
;;
-C|--config)
CONFIG_FILE=$2
shift 2
;;
-v|--verbose)
set -o verbose
shift
;;
--)
shift
break
;;
*)
break
;;
esac
done
if [ $# -lt 1 ] ; then
echo "Incorrect parameters. Use --help for usage instructions."
exit 1
fi
SSHREMOTE_NAME="spilds1"
SSHREMOTE_HOST="spilds"
SSHREMOTE_PORT=22
SSHREMOTE_USER="rigoni"
SSHREMOTE_PEM=~/.ssh/id_rsa
SSHREMOTE_SCRIPTPATH=.ssrremote
write_config() {
file_name=${SSHREMOTE_SCRIPTPATH}/${SSHREMOTE_NAME}.sh
log "Writing script file in ${file_name}"
[ -d ${SSHREMOTE_SCRIPTPATH} ] || mkdir -p ${SSHREMOTE_SCRIPTPATH}
cat <<- _EOF_ > ${file_name}
# Docker container config
# created: $(date)
SSHREMOTE_NAME=${SSHREMOTE_NAME}
SSHREMOTE_HOST=${SSHREMOTE_HOST}
SSHREMOTE_PORT=${SSHREMOTE_PORT}
SSHREMOTE_USER=${SSHREMOTE_USER}
SSHREMOTE_PEM=${SSHREMOTE_PEM}
_EOF_
}
read_config() {
file_name=${SSHREMOTE_SCRIPTPATH}/${SSHREMOTE_NAME}.sh
[ -f ${file_name} ] && source ${file_name}
}
genkey() {
pem=${1:-${SSHREMOTE_PEM:-~/.ssh/id_rsa}}
if [ ! -f $pem ]; then
ssh-keygen -t rsa -b 2048 -f $1 -C "$2"
fi
}
copyid() {
genkey ${SSHREMOTE_PEM}
ssh-copy-id -i ${SSHREMOTE_PEM} -p ${SSHREMOTE_PORT} -f ${SSHREMOTE_USER}@${SSHREMOTE_HOST}
}
execute() {
M_ENV="$(export -p | awk '{printf("%s; ",$0)}')"
# xhost local:andrea > /dev/null
log "Docker: Entering container ${DOCKER_CONTAINER} ";
quoted_args="$(printf " %q" "$@")"
if [ -n "${MAKESHELL}" ]; then
${MAKESHELL} ${quoted_args};
else
docker exec ${INT} --user ${USER} ${DOCKER_CONTAINER} /bin/bash -l -c \
"save_path=\$PATH; $M_ENV \
export PATH=\$save_path; \
cd $(pwd); \
export MAKESHELL=${DOCKER_SHELL}; \
${quoted_args}";
fi
}