Skip to content

Commit

Permalink
fix(install): remove duplicated code in install script
Browse files Browse the repository at this point in the history
  • Loading branch information
psyray committed Feb 12, 2025
1 parent 900b2d6 commit 2a15cd7
Showing 1 changed file with 34 additions and 41 deletions.
75 changes: 34 additions & 41 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -236,46 +236,40 @@ main() {
check_docker
check_docker_compose

if [ -n "$SUDO_USER" ]; then
current_id=$(id -u "$SUDO_USER")
else
current_id=$(id -u)
fi

if [ "$current_id" -ne 1000 ]; then
INSTALL_TYPE="source"
log "Build has been forced because your user ID is not the same as the pre-built images. If you want to use pre-built images, your current user installing reNgine-ng must be 1000." $COLOR_RED
else
if [ $isNonInteractive = false ]; then
log "Do you want to build Docker images from source or use pre-built images (recommended)? \nThis saves significant build time but requires good download speeds for it to complete fast." $COLOR_RED
log "1) From source" $COLOR_YELLOW
log "2) Use pre-built images (default)" $COLOR_YELLOW
read -p "Enter your choice (1 or 2, default is 2): " choice

case $choice in
1)
INSTALL_TYPE="source"
;;
2|"")
INSTALL_TYPE="prebuilt"
;;
*)
log "Invalid choice. Defaulting to pre-built images." $COLOR_RED
INSTALL_TYPE="prebuilt"
;;
esac
fi
fi

if [ -z "$INSTALL_TYPE" ]; then
log "Error: INSTALL_TYPE is not set" $COLOR_RED
exit 1
elif [ "$INSTALL_TYPE" != "prebuilt" ] && [ "$INSTALL_TYPE" != "source" ]; then
log "Error: INSTALL_TYPE must be either 'prebuilt' or 'source'" $COLOR_RED
exit 1
fi
if [ -n "$SUDO_USER" ]; then
current_id=$(id -u "$SUDO_USER")
else
current_id=$(id -u)
fi

log "Selected installation type: $INSTALL_TYPE" $COLOR_CYAN
# Install type
if [ "$current_id" -ne 1000 ]; then
# If the user is not 1000, force source install because pre-built images are not compatible with user > 1000
INSTALL_TYPE="source"
log "Build has been forced because your user ID is not the same as the pre-built images. If you want to use pre-built images, your current user installing reNgine-ng must be 1000." $COLOR_RED
else
if [ $isNonInteractive = false ]; then
log "Do you want to build Docker images from source or use pre-built images (recommended)? \nThis saves significant build time but requires good download speeds for it to complete fast." $COLOR_RED
log "1) From source" $COLOR_YELLOW
log "2) Use pre-built images (default)" $COLOR_YELLOW
read -p "Enter your choice (1 or 2, default is 2): " choice

case $choice in
1)
INSTALL_TYPE="source"
;;
2|"")
INSTALL_TYPE="prebuilt"
;;
*)
log "Invalid choice. Defaulting to pre-built images." $COLOR_RED
INSTALL_TYPE="prebuilt"
;;
esac
elif [ $isNonInteractive = true ]; then
INSTALL_TYPE="${INSTALL_TYPE:-prebuilt}"
fi
fi

# Non-interactive install
if [ $isNonInteractive = true ]; then
Expand All @@ -292,12 +286,11 @@ log "Selected installation type: $INSTALL_TYPE" $COLOR_CYAN
exit 1
fi

INSTALL_TYPE=${INSTALL_TYPE:-prebuilt}
log "Non-interactive installation parameter set. Installation begins." $COLOR_GREEN
fi

if [ -z "$INSTALL_TYPE" ]; then
log "Error: INSTALL_TYPE is not set" $COLOR_RED
log "Error: INSTALL_TYPE is not set in .env, please set it to either 'prebuilt' or 'source'" $COLOR_RED
exit 1
elif [ "$INSTALL_TYPE" != "prebuilt" ] && [ "$INSTALL_TYPE" != "source" ]; then
log "Error: INSTALL_TYPE must be either 'prebuilt' or 'source'" $COLOR_RED
Expand Down

0 comments on commit 2a15cd7

Please sign in to comment.