# this script is a convenience wrapper around systemctl
if[$user_id -ne 0];then
echo"Must run as sudo"
exit1
fi
function failed()
{
localerror=${1:-Undefined error}
echo"Failed: $error" >&2
exit1
}
if[ ! -f "${TEMPLATE_PATH}"];then
failed "Must run from runner root or install is corrupt"
fi
#check if we run as root
if[[$(id -u) !="0"]];then
echo"Failed: This script requires to run with sudo." >&2
exit1
fi
function install()
{
echo"Creating launch runner in ${UNIT_PATH}"
if[ -f "${UNIT_PATH}"];then
failed "error: exists ${UNIT_PATH}"
fi
if[ -f "${TEMP_PATH}"];then
rm "${TEMP_PATH}"|| failed "failed to delete ${TEMP_PATH}"
fi
# can optionally use username supplied
run_as_user=${arg_2:-$SUDO_USER}
echo"Run as user: ${run_as_user}"
run_as_uid=$(id -u ${run_as_user})|| failed "User does not exist"
echo"Run as uid: ${run_as_uid}"
run_as_gid=$(id -g ${run_as_user})|| failed "Group not available"
echo"gid: ${run_as_gid}"
sed "s/{{User}}/${run_as_user}/g; s/{{Description}}/$(echo${SVC_DESCRIPTION}| sed -e 's/[\/&]/\\&/g')/g; s/{{RunnerRoot}}/$(echo${RUNNER_ROOT}| sed -e 's/[\/&]/\\&/g')/g;""${TEMPLATE_PATH}" > "${TEMP_PATH}"|| failed "failed to create replacement temp file"
mv "${TEMP_PATH}""${UNIT_PATH}"|| failed "failed to copy unit file"