Bisa / factorio-init

Factorio init script
MIT License
415 stars 82 forks source link

New-game will fail with no custom settings but custom GLIBC #139

Closed jhawkwind closed 5 years ago

jhawkwind commented 5 years ago

If you are using an alternate GLIBC and you fail to specify either map-gen-settings OR map-settings, the game will not generate and fail with the following error message:

0.000  Error Util.cpp:49: Error configuring paths: There is no package core in /usr/share/factorio. Deduced executable directory: /opt/glibc-2.18/lib, read data: __PATH__system-read-data__, write data: __PATH__system-write-data__

This is because in the new-game routine, when you specify either of those settings, it adds the variable ${EXE_ARGS_GLIBC} at the end, but if you select neither, the variable does not get added and just goes straight to as_user "$createsavecmd" and forget to add the variable needed.

Solution is to instead append that line just prior to execution.

new-game)
    if [ -z $2 ]; then
      echo "You must specify a save name for your new game"
      exit 1
    fi
    savename="${WRITE_DIR}/saves/$2"
    createsavecmd="$BINARY --create \"${savename}\""

    # Check if user wants to use custom map gen settings
    if [ $3 ]; then
      if [ -e "${WRITE_DIR}/$3" ]; then
        createsavecmd="$createsavecmd --map-gen-settings=${WRITE_DIR}/$3"
      else
        echo "Specified map gen settings json does not exist"
        exit 1
      fi
    fi

    # Check if user wants to use custom map settings
    if [ $4 ]; then
      if [ -e "${WRITE_DIR}/$4" ]; then
        createsavecmd="$createsavecmd --map-settings=${WRITE_DIR}/$4"
      else
        echo "Specified map settings json does not exist"
        exit 1
      fi
    fi

    # Stop Service
    if is_running; then
      send_cmd "Generating new save, please stand by"
      if ! stop_service; then
        echo "Failed to stop server, unable to create new save"
        exit 1
      fi
    fi

    if ! as_user "$createsavecmd ${EXE_ARGS_GLIBC}"; then
      echo "Failed to create new game"
      exit 1
    else
      echo "New game created: ${savename}.zip"
    fi
    ;;