Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
f1f182c0
Unverified
Commit
f1f182c0
authored
Jun 18, 2019
by
Erik Wilson
Committed by
GitHub
Jun 18, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #540 from erikwilson/install-args-quoting
Quote installer arguments
parents
7069d51b
deb41784
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
7 deletions
+48
-7
install.sh
install.sh
+48
-7
No files found.
install.sh
View file @
f1f182c0
...
@@ -88,9 +88,33 @@ verify_system() {
...
@@ -88,9 +88,33 @@ verify_system() {
fatal
"Can not find systemd or openrc to use as a process supervisor for k3s"
fatal
"Can not find systemd or openrc to use as a process supervisor for k3s"
}
}
# --- add quotes to command arguments ---
quote
()
{
for
arg
in
"
$@
"
;
do
printf
"%s
\n
"
"
$arg
"
|
sed
"s/'/'
\\\\
''/g;1s/^/'/;
\$
s/
\$
/'/"
done
}
# --- add indentation and trailing slash to quoted args ---
quote_indent
()
{
printf
' \\'
"
\n
"
for
arg
in
"
$@
"
;
do
printf
"
\t
%s "
'\\'
"
\n
"
"
$(
quote
"
$arg
"
)
"
done
}
# --- escape most punctuation characters, except quotes, forward slash, and space ---
escape
()
{
printf
"%s"
"
$@
"
|
sed
-e
's/\([][!#$%&()*;<=>?\_`{|}]\)/\\\1/g;'
}
# --- escape double quotes ---
escape_dq
()
{
printf
"%s"
"
$@
"
|
sed
-e
's/"/\\"/g'
}
# --- define needed environment variables ---
# --- define needed environment variables ---
setup_env
()
{
setup_env
()
{
# --- use command args if passed or create default ---
# --- use command args if passed or create default ---
case
"
$1
"
in
case
"
$1
"
in
# --- if we only have flags discover if command should be server or agent ---
# --- if we only have flags discover if command should be server or agent ---
...
@@ -103,15 +127,14 @@ setup_env() {
...
@@ -103,15 +127,14 @@ setup_env() {
fi
fi
CMD_K3S
=
agent
CMD_K3S
=
agent
fi
fi
CMD_K3S_EXEC
=
"
${
CMD_K3S
}
$@
"
;;
;;
# --- command is provided ---
# --- command is provided ---
(
*
)
(
*
)
CMD_K3S
=
"
$1
"
CMD_K3S
=
"
$1
"
CMD_K3S_EXEC
=
"
$@
"
shift
;;
;;
esac
esac
CMD_K3S_EXEC
=
$(
trim
(
)
{
echo
$@
;
}
&&
trim
${
CMD_K3S_EXEC
}
)
CMD_K3S_EXEC
=
"
${
CMD_K3S
}$(
quote_indent
"
$@
"
)
"
# --- use systemd name if defined or create default ---
# --- use systemd name if defined or create default ---
if
[
-n
"
${
INSTALL_K3S_NAME
}
"
]
;
then
if
[
-n
"
${
INSTALL_K3S_NAME
}
"
]
;
then
...
@@ -123,6 +146,17 @@ setup_env() {
...
@@ -123,6 +146,17 @@ setup_env() {
SYSTEM_NAME
=
k3s-
${
CMD_K3S
}
SYSTEM_NAME
=
k3s-
${
CMD_K3S
}
fi
fi
fi
fi
# --- check for invalid characters in system name ---
valid_chars
=
$(
printf
"%s"
"
${
SYSTEM_NAME
}
"
|
sed
-e
's/[][!#$%&()*;<=>?\_`{|}/[:space:]]/^/g;'
)
if
[
"
${
SYSTEM_NAME
}
"
!=
"
${
valid_chars
}
"
]
;
then
invalid_chars
=
$(
printf
"%s"
"
${
valid_chars
}
"
|
sed
-e
's/[^^]/ /g'
)
fatal
"Invalid characters for system name:
${
SYSTEM_NAME
}
${
invalid_chars
}
"
fi
# --- set related files from system name ---
SERVICE_K3S
=
${
SYSTEM_NAME
}
.service
SERVICE_K3S
=
${
SYSTEM_NAME
}
.service
UNINSTALL_K3S_SH
=
${
SYSTEM_NAME
}
-uninstall
.sh
UNINSTALL_K3S_SH
=
${
SYSTEM_NAME
}
-uninstall
.sh
KILLALL_K3S_SH
=
k3s-killall.sh
KILLALL_K3S_SH
=
k3s-killall.sh
...
@@ -482,7 +516,9 @@ Type=${SYSTEMD_TYPE}
...
@@ -482,7 +516,9 @@ Type=${SYSTEMD_TYPE}
EnvironmentFile=
${
FILE_K3S_ENV
}
EnvironmentFile=
${
FILE_K3S_ENV
}
ExecStartPre=-/sbin/modprobe br_netfilter
ExecStartPre=-/sbin/modprobe br_netfilter
ExecStartPre=-/sbin/modprobe overlay
ExecStartPre=-/sbin/modprobe overlay
ExecStart=
${
BIN_DIR
}
/k3s
${
CMD_K3S_EXEC
}
ExecStart=
${
BIN_DIR
}
/k3s \\
${
CMD_K3S_EXEC
}
KillMode=process
KillMode=process
Delegate=yes
Delegate=yes
LimitNOFILE=infinity
LimitNOFILE=infinity
...
@@ -517,7 +553,9 @@ start_pre() {
...
@@ -517,7 +553,9 @@ start_pre() {
supervisor=supervise-daemon
supervisor=supervise-daemon
name="
${
SYSTEM_NAME
}
"
name="
${
SYSTEM_NAME
}
"
command="
${
BIN_DIR
}
/k3s"
command="
${
BIN_DIR
}
/k3s"
command_args="
${
CMD_K3S_EXEC
}
>>
${
LOG_FILE
}
2>&1"
command_args="
$(
escape_dq
"
${
CMD_K3S_EXEC
}
"
)
>>
${
LOG_FILE
}
2>&1"
pidfile="/var/run/
${
SYSTEM_NAME
}
.pid"
pidfile="/var/run/
${
SYSTEM_NAME
}
.pid"
respawn_delay=5
respawn_delay=5
...
@@ -590,10 +628,13 @@ service_enable_and_start() {
...
@@ -590,10 +628,13 @@ service_enable_and_start() {
return
0
return
0
}
}
# --- re-evaluate args to include env command ---
eval set
--
$(
escape
"
${
INSTALL_K3S_EXEC
}
"
)
$(
quote
"
$@
"
)
# --- run the install process --
# --- run the install process --
{
{
verify_system
verify_system
setup_env
${
INSTALL_K3S_EXEC
}
$@
setup_env
"
$@
"
download_and_verify
download_and_verify
create_symlinks
create_symlinks
create_killall
create_killall
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment