Last active
October 29, 2020 09:19
-
-
Save venth/aa004d4b651b5f31ef3e94cc08eb7747 to your computer and use it in GitHub Desktop.
bash scripts that creates ramdisk on osx system and use ramdisk to deal with maven target directories; based on: https://stackoverflow.com/questions/46224103/create-apfs-ram-disk-on-macos-high-sierra
This file contains 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 | |
delete=false | |
while [ $# -gt 0 ]; do | |
case "$1" in | |
-s*|--size*|--size=*) | |
size="${1#*=}" | |
size=$(($size*2048)) | |
;; | |
-d|--delete) | |
delete=true | |
;; | |
--help) | |
echo 'Usage: ramdisk --size=<in megabytes>' | |
echo ' creates ramdisk' | |
echo 'Usage: ramdisk --delete' | |
echo ' deletes already created ramdisk, if exists' | |
;; | |
*) | |
echo 'Usage: ramdisk --size=<in megabytes>' | |
echo ' creates ramdisk' | |
echo 'Usage: ramdisk --delete' | |
echo ' deletes already created ramdisk, if exists' | |
exit 1 | |
esac | |
shift | |
done | |
ramdisk_name='APFS RAM Disk' | |
if [ "$delete" = true ]; then | |
[ -d "/Volumes/$ramdisk_name" ] && diskutil eject "/Volumes/$ramdisk_name" | |
else | |
[ -d "/Volumes/$ramdisk_name" ] || diskutil partitionDisk $(hdiutil attach -nomount ram://$size) 1 GPTFormat APFS 'APFS RAM Disk' '100%' | |
fi |
This file contains 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 | |
delete=false | |
while [ $# -gt 0 ]; do | |
case "$1" in | |
-d|--delete) | |
delete=true | |
;; | |
--help) | |
echo 'If used without parameters creates maven target directories on ramdisk' | |
echo 'and creates link that leads to the created directory.' | |
echo 'If used with --delete parameter it unlinks all target links' | |
exit 0 | |
;; | |
*) | |
echo 'If used without parameters creates maven target directories on ramdisk' | |
echo 'and creates link that leads to the created directory.' | |
echo 'If used with --delete parameter it unlinks all target links' | |
exit 1 | |
esac | |
shift | |
done | |
if [ "$delete" = true ]; then | |
find "$(pwd)" -type l -name target | xargs -I {} unlink "{}" || exit 1 | |
exit 0 | |
fi | |
ramdisk_name='APFS RAM Disk' | |
ramdisk_dir="/Volumes/$ramdisk_name" | |
current_dir="$(pwd)" | |
if [ ! -d "$ramdisk_dir" ]; then | |
echo "Please create ramdisk: '$ramdisk_name' first (e.g: ramdisk --size 512)" | |
exit 1 | |
fi | |
echo "Re-link all target directories from: $current_dir" | |
find "$current_dir" -type f -name pom.xml ! -path '*/target/*' | \ | |
xargs -I {} dirname "{}" | \ | |
xargs -I {} mkdir -p "${ramdisk_dir}{}/target" | |
find "$current_dir" -type f -name pom.xml ! -path '*/target/*' | \ | |
xargs -I {} dirname "{}" | \ | |
xargs -I {} rm -rf "{}/target" | |
find "$current_dir" -type f -name pom.xml ! -path '*/target/*' | \ | |
xargs -I {} dirname "{}" | \ | |
xargs -I {} ln -sf "${ramdisk_dir}{}/target" "{}/target" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment