Created
July 14, 2016 17:03
-
-
Save sosukeinu/9ddcdbf09cab5a659724c2626ec9e0ef to your computer and use it in GitHub Desktop.
Update Symbolic Links from older versions of Homebrew Cask to new location so you don't have to re-install all of your apps. Please feel free to make improvements, as this was just kind of thrown together.
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
#!/bin/sh | |
# | |
shopt -s nocaseglob | |
# parse basic commandline, equals-based arguments | |
# example: ./update_symbolic_links.sh -e=app -in=. | |
# example: ./update_symbolic_links.sh -e=app -in=/Users/username/Applications/ | |
for i in "$@" | |
do | |
case $i in | |
-e=*|--extension=*) | |
EXTENSION="${i#*=}" | |
shift # past argument=value | |
;; | |
-in=*|--inpath=*) | |
INPATH="${i#*=}" | |
shift # past argument=value | |
;; | |
-out=*|--outpath=*) | |
OUTPATH="${i#*=}" | |
shift # past argument=value | |
;; | |
--default) | |
DEFAULT=YES | |
shift # past argument with no value | |
;; | |
*) | |
# unknown option | |
;; | |
esac | |
done | |
replacement="/usr/local/Caskroom" | |
prefix="/opt/homebrew-cask/Caskroom" | |
for file in "${INPATH}"*."${EXTENSION}"; do | |
FILE=${file##*/} | |
echo "FILE: ${FILE}" | |
FILENAME="${FILE%.*}" | |
echo "FILENAME: ${FILENAME}" | |
original_string=$(readlink "${INPATH}${FILE}") | |
echo "original string: ${original_string}" | |
result_string=${original_string#$prefix} | |
result_string=$replacement$result_string | |
echo "result string: ${result_string}" | |
ln -sfn $result_string ${INPATH} | |
final_string=$(readlink "${INPATH}${FILE}") | |
echo "final string: ${final_string}" | |
done | |
echo "FILE EXTENSION = ${EXTENSION}" | |
echo "IN PATH = ${INPATH}" | |
echo "OUT PATH = ${OUTPATH}" | |
echo "Number files in IN PATH with EXTENSION:" $(ls -1 "${INPATH}"/*."${EXTENSION}" | wc -l) | |
if [[ -n $1 ]]; then | |
echo "Last line of file specified as non-opt/last argument:" | |
tail -1 $1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment