1#!/usr/bin/env bash 2# 3# Script to rename DLL name within side deck. 4# 5 6# Stops execution if a command or pipeline has an error. 7set -e 8 9sidedeck=$1 10old_dll_name=$2 11new_dll_name=$3 12 13function error() { 14 printf "ERROR: %s\n" "$*" 15 exit 1 16} 17 18function usage() { 19cat <<EOF 20Usage: $(basename $0) <side deck file> <old dll name> <new dll name>: 21 [-h|--help] Display this help and exit. 22EOF 23} 24 25rename_dll_name_inside_side_deck() { 26 27if [[ -z "$sidedeck" || -z "$old_dll_name" || -z "$new_dll_name" ]]; then 28 usage 29 error "All 3 parameters must be specified." 30fi 31 32[[ -f "$sidedeck" ]] || error "The '$sidedeck' file must exists." 33 34old_len=${#old_dll_name} 35new_len=${#new_dll_name} 36 37if (( $new_len > $old_len )); then 38 error "New DLL name $new_dll_name must have $old_len characters or less." 39fi 40 41if ((padding_len=$old_len-$new_len )); then 42 pad=$(printf "%*s" $padding_len "") 43fi 44 45# Touch the temp. file and set the tag to 1047 first so the redirecting statement 46# will write in 1047 and not 819 encoding. 47touch $sidedeck.tmp; chtag -tc1047 $sidedeck.tmp 48sed "/ IMPORT /s/'$old_dll_name/$pad'$new_dll_name/g" $sidedeck > $sidedeck.tmp 49mv $sidedeck.tmp $sidedeck 50} 51 52function main() { 53 rename_dll_name_inside_side_deck 54} 55 56main "$@" 57 58