diff --git a/compose/postgres.yml b/compose/postgresql.yml similarity index 100% rename from compose/postgres.yml rename to compose/postgresql.yml diff --git a/compose/video-worker.yml b/compose/video-worker.yml deleted file mode 100644 index b1e35b71..00000000 --- a/compose/video-worker.yml +++ /dev/null @@ -1,22 +0,0 @@ -services: - video: - image: ${REGISTRY:-registry.fit2cloud.com}/jumpserver/video-worker:${VERSION} - container_name: jms_video_worker - hostname: jms_video_worker - ulimits: - core: 0 - restart: always - env_file: - - ${CONFIG_FILE} - ports: - - 9000:9000 - volumes: - - ${VOLUME_DIR}/video/data:/opt/video-worker/data - healthcheck: - test: "curl -fsL http://localhost:9000/video-worker/health/ > /dev/null" - interval: 10s - timeout: 5s - retries: 3 - start_period: 10s - networks: - - net diff --git a/jmsctl.sh b/jmsctl.sh index 68feb5a2..343a1dfb 100755 --- a/jmsctl.sh +++ b/jmsctl.sh @@ -78,6 +78,13 @@ function service_to_docker_name() { EXE="" function start() { + target="/opt/jumpserver/installer" + if [[ -L "${target}" ]]; then + rm -f "${target}" + fi + if [[ ! -e "${target}" ]]; then + ln -s "${PROJECT_DIR}" "${target}" || echo "" + fi ${EXE} up -d } diff --git a/scripts/0_prepare.sh b/scripts/0_prepare.sh index 5ff425b0..9ebe23ca 100644 --- a/scripts/0_prepare.sh +++ b/scripts/0_prepare.sh @@ -63,6 +63,12 @@ function prepare_image_files() { echo "$(gettext 'Docker is not running, please install and start') ..." exit 1 fi + + if [[ ! -d "${IMAGE_DIR}" ]]; then + mkdir -p "${IMAGE_DIR}" + fi + rm -f "${IMAGE_DIR}/*" + pull_images images=$(get_images) @@ -78,9 +84,6 @@ function prepare_image_files() { saved_id=$(cat "${md5_path}") fi - if [[ ! -d "${IMAGE_DIR}" ]]; then - mkdir -p "${IMAGE_DIR}" - fi if [[ -f "${image_path}" ]]; then if [[ "${image_id}" != "${saved_id}" ]]; then diff --git a/scripts/1_config_jumpserver.sh b/scripts/1_config_jumpserver.sh index fe489ee2..4d3bab08 100644 --- a/scripts/1_config_jumpserver.sh +++ b/scripts/1_config_jumpserver.sh @@ -231,16 +231,8 @@ function set_service() { fi } -function init_db() { - echo_yellow "\n6. $(gettext 'Init JumpServer Database')" - if ! perform_db_migrations; then - log_error "$(gettext 'Failed to change the table structure')!" - exit 1 - fi -} - function set_others() { - echo_yellow "\n7. $(gettext 'Configure Others')" + echo_yellow "\n6. $(gettext 'Configure Others')" lang=$(get_config LANGUAGE_CODE "zh") read_from_input lang "$(gettext 'Please enter language')" "zh/en/ja/es/ko/ru/vi" "${lang}" set_config LANGUAGE_CODE "${lang}" @@ -269,9 +261,6 @@ function main() { if set_others; then echo_done fi - if init_db; then - echo_done - fi } if [[ "$0" == "${BASH_SOURCE[0]}" ]]; then diff --git a/scripts/4_install_jumpserver.sh b/scripts/4_install_jumpserver.sh index b34b5e73..6bca413b 100644 --- a/scripts/4_install_jumpserver.sh +++ b/scripts/4_install_jumpserver.sh @@ -9,6 +9,7 @@ function pre_install() { if [[ -n "$UNCHECK_DEPENDENCIES" ]]; then return 0 fi + if ! command -v systemctl &>/dev/null; then docker version &>/dev/null || { log_error "$(gettext 'The current Linux system does not support systemd management. Please deploy docker by yourself before running this script again')" @@ -19,6 +20,7 @@ function pre_install() { exit 1 } fi + if ! command -v iptables &>/dev/null; then log_error "$(gettext 'command not found, Please install it first') iptables" exit 1 @@ -93,14 +95,22 @@ function main() { exit 1 fi + echo_green "\n>>> $(gettext 'Install and Configure JumpServer')" + if ! bash "${BASE_DIR}/1_config_jumpserver.sh"; then + exit 1 + fi + echo_green "\n>>> $(gettext 'Loading Docker Image')" if ! bash "${BASE_DIR}/3_load_images.sh"; then exit 1 fi - echo_green "\n>>> $(gettext 'Install and Configure JumpServer')" - if ! bash "${BASE_DIR}/1_config_jumpserver.sh"; then + + echo_green "\n>>> $(gettext 'Initialize Database')" + if ! perform_db_migrations; then + log_error "$(gettext 'Failed to change the table structure')!" exit 1 fi + installation_log "install" post_install } diff --git a/scripts/logo.txt b/scripts/logo.txt new file mode 100644 index 00000000..4948fa88 --- /dev/null +++ b/scripts/logo.txt @@ -0,0 +1,7 @@ + + ██╗██╗ ██╗███╗ ███╗██████╗ ███████╗███████╗██████╗ ██╗ ██╗███████╗██████╗ + ██║██║ ██║████╗ ████║██╔══██╗██╔════╝██╔════╝██╔══██╗██║ ██║██╔════╝██╔══██╗ + ██║██║ ██║██╔████╔██║██████╔╝███████╗█████╗ ██████╔╝██║ ██║█████╗ ██████╔╝ + ██ ██║██║ ██║██║╚██╔╝██║██╔═══╝ ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██╔══╝ ██╔══██╗ + ╚█████╔╝╚██████╔╝██║ ╚═╝ ██║██║ ███████║███████╗██║ ██║ ╚████╔╝ ███████╗██║ ██║ + ╚════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚══════╝╚═╝ ╚═╝ diff --git a/scripts/utils.sh b/scripts/utils.sh index 3bf9188d..de241fdf 100644 --- a/scripts/utils.sh +++ b/scripts/utils.sh @@ -5,6 +5,9 @@ BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" . "${BASE_DIR}/const.sh" +common_services=(core celery koko lion chen web) +xpack_services=(magnus razor xrdp video panda nec facelive) + function check_root() { [[ "$(id -u)" == 0 ]] } @@ -48,7 +51,11 @@ function has_config() { function get_config() { key=$1 default=${2-''} - value=$(grep "^${key}=" "${CONFIG_FILE}" | awk -F= '{ print $2 }' | awk -F' ' '{ print $1 }' | tail -1) + + if [[ -f "${CONFIG_FILE}" ]]; then + value=$(grep "^${key}=" "${CONFIG_FILE}" | awk -F= '{ print $2 }' | awk -F' ' '{ print $1 }' | tail -1) + fi + if [[ -z "$value" ]];then value="$default" fi @@ -66,12 +73,10 @@ function get_config_or_env() { key=$1 value='' default=${2-''} - if [[ -f "${CONFIG_FILE}" ]];then - value=$(get_config "$key") - fi - if [[ -z "$value" ]];then - value=$(get_env_value "$key") + value=$(get_env_value "$key") + if [[ -z "$value" && -f "${CONFIG_FILE}" ]];then + value=$(get_config "$key") fi if [[ -z "$value" ]];then @@ -138,6 +143,40 @@ function check_db_data() { fi } +function get_enabled_services() { + enabled_services=() + + use_xpack=$(get_config_or_env USE_XPACK) + services=("${common_services[@]}") + if [[ "${use_xpack}" == "1" ]]; then + services+=("${xpack_services[@]}") + fi + + for service in "${services[@]}"; do + key=$(echo "$service" | tr '[:lower:]' '[:upper:]') + key="${key}_ENABLED" + key=$(echo "$key" | sed 's/-/_/g') + if [[ "${service}" == "video-worker" ]]; then + key="VIDEO_ENABLED" + fi + if [[ "$(get_config_or_env "${key}")" != "0" ]]; then + enabled_services+=("${service}") + fi + done + + echo "${enabled_services[@]}" +} + +function get_config_enabled() { + key=$1 + value=$(get_config "${key}") + if [[ "${value}" == "0" || "${value}" == "false" || "${value}" == "False" ]]; then + return 0 + else + return 1 + fi +} + function get_db_info() { info_type=$1 db_engine=$(get_config DB_ENGINE "mysql") @@ -179,7 +218,7 @@ function get_db_info() { elif [[ "${mariadb_data_exists}" == "1" ]]; then echo "compose/mariadb.yml" elif [[ "${postgres_data_exists}" == "1" ]]; then - echo "compose/postgres.yml" + echo "compose/postgresql.yml" fi ;; *) @@ -197,34 +236,24 @@ function get_db_images_file() { function get_images() { use_xpack=$(get_config_or_env USE_XPACK) - db_images=$(get_db_images) - images=( - "redis:7.4.6-bookworm" - "${db_images}" - ) - for image in "${images[@]}"; do - echo "${image}" + images=("redis:7.4.6-bookworm") + images+=("$(get_db_images)") + enabled_services=$(get_enabled_services) + + for service in ${enabled_services}; do + if [[ "${service}" == "video" ]]; then + image="jumpserver/video-worker:${VERSION}" + elif [[ "${service}" == "" || "${service}" == "celery" ]]; then + continue + else + image="jumpserver/${service}:${VERSION}" + fi + if [[ "${use_xpack}" == "1" ]]; then + image="registry.fit2cloud.com/${image}" + fi + images+=("${image}") done - if [[ "$use_xpack" == "1" ]];then - echo "registry.fit2cloud.com/jumpserver/core:${VERSION}" - echo "registry.fit2cloud.com/jumpserver/koko:${VERSION}" - echo "registry.fit2cloud.com/jumpserver/lion:${VERSION}" - echo "registry.fit2cloud.com/jumpserver/chen:${VERSION}" - echo "registry.fit2cloud.com/jumpserver/web:${VERSION}" - echo "registry.fit2cloud.com/jumpserver/magnus:${VERSION}" - echo "registry.fit2cloud.com/jumpserver/razor:${VERSION}" - echo "registry.fit2cloud.com/jumpserver/video-worker:${VERSION}" - echo "registry.fit2cloud.com/jumpserver/xrdp:${VERSION}" - echo "registry.fit2cloud.com/jumpserver/panda:${VERSION}" - echo "registry.fit2cloud.com/jumpserver/nec:${VERSION}" - echo "registry.fit2cloud.com/jumpserver/facelive:${VERSION}" - else - echo "jumpserver/core:${VERSION}" - echo "jumpserver/koko:${VERSION}" - echo "jumpserver/lion:${VERSION}" - echo "jumpserver/chen:${VERSION}" - echo "jumpserver/web:${VERSION}" - fi + echo "${images[@]}" } function read_from_input() { @@ -248,6 +277,12 @@ function read_from_input() { fi echo -n "${msg}: " + if [[ "${AUTO_INSTALL}" == "1" ]]; then + echo "${default}" + export "${var}"="${default}" + return + fi + read -r input if [[ -z "${input}" && -n "${default}" ]]; then export "${var}"="${default}" @@ -336,12 +371,7 @@ function get_docker_compose_services() { use_xpack=$(get_config_or_env USE_XPACK) - services="core celery koko lion chen web" - - receptor_enabled=$(get_config RECEPTOR_ENABLED) - if [[ "${receptor_enabled}" == "1" ]]; then - services+=" receptor" - fi + services=$(get_enabled_services) if [[ "${ignore_db}" != "ignore_db" ]]; then case "${db_engine}" in @@ -355,23 +385,10 @@ function get_docker_compose_services() { [[ "${redis_host}" == "redis" ]] && services+=" redis" fi - for service in core celery koko lion chen web; do - enabled=$(get_config "${service^^}_ENABLED") - [[ "${enabled}" == "0" ]] && services="${services//${service}/}" - done - [[ "${use_es}" == "1" ]] && services+=" es" [[ "${use_minio}" == "1" ]] && services+=" minio" [[ "${use_loki}" == "1" ]] && services+=" loki" - if [[ "${use_xpack}" == "1" ]]; then - services+=" magnus razor xrdp video panda nec facelive" - for service in magnus razor xrdp video panda nec facelive; do - enabled=$(get_config "${service^^}_ENABLED") - [[ "${enabled}" == "0" ]] && services="${services//${service}/}" - done - fi - echo "${services}" } @@ -381,6 +398,7 @@ function get_docker_compose_cmd_line() { use_xpack=$(get_config_or_env USE_XPACK) https_port=$(get_config HTTPS_PORT) db_images_file=$(get_db_images_file) + cmd="docker compose" if [[ "${use_ipv6}" != "1" ]]; then cmd+=" -f compose/network.yml" @@ -389,42 +407,10 @@ function get_docker_compose_cmd_line() { fi services=$(get_docker_compose_services "$ignore_db") - for service in core celery receptor koko lion chen web redis; do - if [[ "${services}" =~ ${service} ]]; then + for service in $services; do cmd+=" -f compose/${service}.yml" - fi done - if [[ "${services}" =~ "mysql" || "${services}" =~ "postgresql" ]]; then - cmd+=" -f ${db_images_file}" - fi - - use_es=$(get_config USE_ES) - if [[ "${use_es}" == "1" ]]; then - cmd+=" -f compose/es.yml" - fi - - use_minio=$(get_config USE_MINIO) - if [[ "${use_minio}" == "1" ]]; then - cmd+=" -f compose/minio.yml" - fi - - if [[ -n "${https_port}" ]]; then - cmd+=" -f compose/lb.yml" - fi - - if [[ "${services}" =~ loki ]]; then - cmd+=" -f compose/loki.yml" - fi - - if [[ "${use_xpack}" == '1' ]]; then - for service in magnus razor xrdp video panda nec facelive; do - if [[ "${services}" =~ ${service} ]]; then - cmd+=" -f compose/${service}.yml" - fi - done - fi - echo "${cmd}" } @@ -543,16 +529,7 @@ function prepare_config() { } function echo_logo() { - cat <<"EOF" - - ██╗██╗ ██╗███╗ ███╗██████╗ ███████╗███████╗██████╗ ██╗ ██╗███████╗██████╗ - ██║██║ ██║████╗ ████║██╔══██╗██╔════╝██╔════╝██╔══██╗██║ ██║██╔════╝██╔══██╗ - ██║██║ ██║██╔████╔██║██████╔╝███████╗█████╗ ██████╔╝██║ ██║█████╗ ██████╔╝ - ██ ██║██║ ██║██║╚██╔╝██║██╔═══╝ ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██╔══╝ ██╔══██╗ - ╚█████╔╝╚██████╔╝██║ ╚═╝ ██║██║ ███████║███████╗██║ ██║ ╚████╔╝ ███████╗██║ ██║ - ╚════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚══════╝╚═╝ ╚═╝ - -EOF + cat "${BASE_DIR}/logo.txt" echo -e "\t\t\t\t\t\t\t\t Version: \033[33m $VERSION \033[0m \n" } diff --git a/static.env b/static.env index fe82e3fd..b261ef51 100644 --- a/static.env +++ b/static.env @@ -1 +1,6 @@ -export VERSION=dev +export VERSION=v4.10.15-osm +export USE_XPACK=1 +export REGISTRY=registry.fit2cloud.com +export XRDP_ENABLED=0 +export FACELIVE_ENABLED=0 +export VIDEO_ENABLED=0