Created
July 3, 2017 01:48
-
-
Save darealshinji/6b69a505654056d097b432dfc5e7c31b to your computer and use it in GitHub Desktop.
Shell script helping to relocate an MXE prefix; see https://github.com/mxe/mxe/issues/1700
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| help="Relocate an MXE prefix\n\ | |
| \n\ | |
| Usage: $0 old_path new_path prefix\n\ | |
| \n\ | |
| old and new paths must be absolute\n\ | |
| new path must not be longer than the old one\n\n" | |
| if [ "x$3" = "x" ] || [ "x$2" = "x" ] || [ "x$1" = "x" ]; then | |
| printf "$help" | |
| exit 1 | |
| fi | |
| if [ "x$1" = "x--help" ]; then | |
| printf "$help" | |
| exit 0 | |
| fi | |
| old="${1%/}" | |
| new="${2%/}" | |
| pfx="$3" | |
| oldLen=$(printf "$old" | wc -c) | |
| newLen=$(printf "$new" | wc -c) | |
| if [ $newLen -gt $oldLen ]; then | |
| echo "Error: the new path must not be longer than the old one" | |
| exit 1 | |
| fi | |
| # prepend the new path with forward slashes until it has | |
| # the same lenght as the old path | |
| new="$(printf %$(($oldLen - $newLen))s | tr ' ' '/')$new" | |
| # simple and quick check if this is an MXE prefix | |
| if [ ! -f "$pfx/installed/check-requirements" ] || \ | |
| [ ! -x "$pfx/bin/config.guess" ]; | |
| then | |
| echo "Error: this doesn't look like an MXE prefix!" | |
| echo "Be sure to point to the MXE \`usr' directory." | |
| exit 1 | |
| fi | |
| printf "\nold: $old\nnew: $new\n\n" | |
| read -r -p "Do you want to substitute the old path with the new path? [y/N] " response | |
| echo "" | |
| if [[ ! "${response,,}" =~ ^(yes|y)$ ]]; then | |
| echo "Goodbye!" | |
| exit 0 | |
| fi | |
| find "$pfx"/* -type f -print -exec sed -i "s|$old|$new|g" '{}' \; | |
| echo "Done!" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment