-
Notifications
You must be signed in to change notification settings - Fork 35
feat: Add auto-start feature #84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # ----- Constants ----- | ||
| DOCKER_IMAGE_REPO=${DOCKER_IMAGE_REPO:="wheelos/apollo"} | ||
| GEOLOC=${GEOLOC:="cn"} | ||
| GEO_REGISTRY="" | ||
|
|
||
| function geo_specific_config() { | ||
| local geo="$1" | ||
| if [[ -z "${geo}" ]]; then | ||
| echo "Use default GeoLocation settings" | ||
| return | ||
| fi | ||
| echo "Setup geolocation specific configurations for ${geo}" | ||
|
|
||
| if [[ "${geo}" == "cn" ]]; then | ||
| echo "GeoLocation settings for Mainland China" | ||
| GEO_REGISTRY="registry.cn-hangzhou.aliyuncs.com" | ||
| else | ||
| echo "GeoLocation settings for ${geo} is not ready, fallback to default" | ||
| fi | ||
| } | ||
|
|
||
| # Function: Pull Docker image, check local cache first if requested | ||
| function docker_pull() { | ||
| local base_image_name="$1" | ||
| local __final_image_var_name="$2" | ||
|
|
||
| # Determine the pull candidate based on geolocation | ||
| local pull_candidate_image_name="${base_image_name}" | ||
| if [[ -n "${GEO_REGISTRY}" ]]; then | ||
| pull_candidate_image_name="${GEO_REGISTRY}/${base_image_name}" | ||
| fi | ||
|
|
||
| # Check if local image exists | ||
| if docker image inspect "${pull_candidate_image_name}" >/dev/null 2>&1; then | ||
| echo "Using local image '${pull_candidate_image_name}'." | ||
| else | ||
| echo "Starting pull of docker image '${pull_candidate_image_name}' ..." | ||
| if ! docker pull "${pull_candidate_image_name}"; then | ||
| echo "Failed to pull docker image: '${pull_candidate_image_name}'" | ||
| return 1 | ||
| fi | ||
| fi | ||
|
|
||
| eval "${__final_image_var_name}='${pull_candidate_image_name}'" # Store the final image name | ||
| return 0 | ||
| } | ||
|
|
||
| # Function: Determine image based on architecture and GPU usage | ||
| function determine_image() { | ||
| local arch="$1" # e.g., x86 or arm | ||
| local os_ver="$2" # e.g., 20.04 | ||
| local gpu="$3" # e.g., true (for GPU) or false (for CPU) | ||
|
|
||
| # Construct the base image name using the specified format | ||
| local base_image_name="dev-${arch}-${os_ver}" | ||
| local image_name="" | ||
|
|
||
| # Append GPU or CPU suffix based on the input | ||
| if [[ "$gpu" == "true" ]]; then | ||
| image_name="${DOCKER_IMAGE_REPO}:${base_image_name}-gpu" | ||
| else | ||
| image_name="${DOCKER_IMAGE_REPO}:${base_image_name}-cpu" | ||
| fi | ||
|
|
||
| # Pull the Docker image or use the existing one | ||
| if ! docker_pull "${image_name}" "APOLLO_IMAGE"; then | ||
| echo "Failed to determine image." | ||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
| # Main function to call from whl.sh | ||
| function select_container() { | ||
| local arch="$1" | ||
| local os_ver="$2" | ||
| local gpu="$3" | ||
|
|
||
| geo_specific_config "${GEOLOC}" | ||
| determine_image "${arch}" "${os_ver}" "${gpu}" | ||
| } | ||
|
|
||
| # Allow invocation of select_container from the command line for testing | ||
| if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then | ||
| select_container "$@" | ||
| fi |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,50 @@ | ||||||||||||||||||||||
| #!/bin/bash | ||||||||||||||||||||||
| set -e | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # 1. Dynamically create users identical to those on the host machine | ||||||||||||||||||||||
| USER_NAME=${USER_NAME:-apollo} | ||||||||||||||||||||||
| USER_ID=${USER_ID:-1000} | ||||||||||||||||||||||
| GROUP_ID=${GROUP_ID:-1000} | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if ! getent group "$USER_NAME" >/dev/null; then | ||||||||||||||||||||||
| groupadd -g "$GROUP_ID" "$USER_NAME" 2>/dev/null || groupmod -g "$GROUP_ID" $(getent group "$GROUP_ID" | cut -d: -f1) | ||||||||||||||||||||||
| fi | ||||||||||||||||||||||
|
Comment on lines
+9
to
+11
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if ! id -u "$USER_NAME" >/dev/null 2>&1; then | ||||||||||||||||||||||
| useradd -u "$USER_ID" -g "$GROUP_ID" -m -s /bin/bash "$USER_NAME" | ||||||||||||||||||||||
| echo "$USER_NAME ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers | ||||||||||||||||||||||
| fi | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # 2. Correct critical directory permissions | ||||||||||||||||||||||
| chown "$USER_NAME":"$USER_NAME" /apollo | ||||||||||||||||||||||
|
Comment on lines
+15
to
+19
|
||||||||||||||||||||||
| echo "$USER_NAME ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers | |
| fi | |
| # 2. Correct critical directory permissions | |
| chown "$USER_NAME":"$USER_NAME" /apollo | |
| fi | |
| # 2. Correct critical directory permissions | |
| chown "$USER_NAME":"$USER_NAME" /apollo | |
| chown "$USER_NAME":"$USER_NAME" /apollo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment says the supported values are "stable/test", but the actual CLI parsing and usage text in this script uses "stable/testing". Please align the comment with the real option name to avoid misleading users.