Changeset - 44094e9d54b7
[Not reviewed]
0 1 0
Branko Majic (branko) - 2 years ago 2022-08-21 13:41:24
branko@majic.rs
[factorio_development.sh] Avoid switching directories within commands:

- Should make commands easily callable from within other commands.
- Avoid using the single quotes (don't -> do not) so Emacs syntax
highlighter/formatter would not get confused.
1 file changed with 6 insertions and 11 deletions:
0 comments (0 inline, 0 general) First comment
games/factorio_development.sh
Show inline comments
 
@@ -418,13 +418,13 @@ function command_build() {
 
    done
 

	
 
    if [[ $error_count != 0 ]]; then
 
        return 1
 
    fi
 

	
 
    # Do some basic validation so we don't overwrite things by mistake.
 
    # Do some basic validation so we do not overwrite things by mistake.
 
    if [[ -e $archive_file ]]; then
 
        error "Output archive already exists: $archive_file"
 
        return 1
 
    fi
 

	
 
    info "Building release: $mod_version"
 
@@ -432,35 +432,30 @@ function command_build() {
 
    # Set-up the necessary directories.
 
    rm -rf "$target_dir"
 
    mkdir -p "$target_dir"
 
    mkdir -p "$dist_dir"
 

	
 
    # Copy the files.
 
    if ! cd "$base_dir/"; then
 
        error "Failed to switch to base directory: $base_dir"
 
        return 1
 
    fi
 
    for mod_file in "${mod_files[@]}"; do
 
        install -m 0644 -D "$mod_file" "${target_dir}/${mod_file%%${source_dir}/}"
 
        if ! (cd "$base_dir" && install -m 0644 -D "$mod_file" "${target_dir}/${mod_file%%${source_dir}/}"); then
 
            error "Failed to copy the file: $mod_file"
 
            return 1
 
        fi
 
    done
 

	
 
    # Move sources to base directory.
 
    if [[ $source_dir != . ]]; then
 
        mv -n "${target_dir}/${source_dir}"/* "${target_dir}"
 
        if ! rmdir "${target_dir}/${source_dir}"; then
 
            error "Failed to remove directory: ${target_dir}/${source_dir}"
 
            return 1
 
        fi
 
    fi
 

	
 
    # Zip the files.
 
    if ! cd "$build_dir/"; then
 
        error "Failed to switch to build directory: $build_dir"
 
        return 1
 
    fi
 
    if ! zip -q -r "$archive_file" "$(basename "$target_dir")"; then
 
    if ! (cd "$build_dir/" && zip -q -r "$archive_file" "$(basename "$target_dir")"); then
 
        error "Could not prepare the release archive."
 
        return 1
 
    fi
 

	
 
    rm -rf "$target_dir"
 

	
0 comments (0 inline, 0 general) First comment
You need to be logged in to comment. Login now