Skip to content

Instantly share code, notes, and snippets.

@WyrdNexus
Created April 10, 2020 17:24
Show Gist options
  • Save WyrdNexus/faa1cfb49cd558283aa6eb40f66a8c42 to your computer and use it in GitHub Desktop.
Save WyrdNexus/faa1cfb49cd558283aa6eb40f66a8c42 to your computer and use it in GitHub Desktop.
Win Dev with Vagrant Linux Composer modules: don't break the git
#!/usr/bin/env bash
# before using, add to path
# e.g.: sudo mv ./comp /root/bin/comp; sudo ln -s /sbin/comp /root/bin/comp
# ~/dev should point to project directory
# set HOME to your user directory
# USAGE
# $ sudo comp m - mount a local user-directory over your project/modules
# -- then you can run composer commands without screwing up your windows environment
# $ sudo comp u - umount project/modules
# -- everything running from windows folders again.
HOME="/home/vagrant"
[ $EUID -ne 0 ] && { echo "Comp must be ran as root"; exit 1; }
ACT=$1
[ -z "$ACT" ] && { echo "Missing action arg. Mount or Umount? (u/m): "; read ACT; }
[ -e $HOME/dev ] && { PROJ=$(readlink -f ~/dev); PROJ="${PROJ%%*()}"; }
[ -z "$PROJ" ] && { echo "no project found at ~/dev"; exit 1; }
SETOWN=false
[ ! -d $HOME/comp ] && mkdir ~/comp
[ ! -d $HOME/comp/modules ] && { mkdir ~/comp/modules; SETOWN=true; }
[ ! -d $HOME/comp/modules/core ] && mkdir ~/comp/modules/core
[ ! -d $HOME/comp/modules/downstream ] && mkdir ~/comp/modules/downstream
[ ! -d $HOME/comp/modules/media ] && mkdir ~/comp/modules/media
[ ! -d $HOME/comp/modules/waffles ] && mkdir ~/comp/modules/waffles
if [ $SETOWN ]; then
chown -R vagrant:vagrant $HOME/comp
chmod -R 775 $HOME/comp
fi
case $ACT in
u | U | umount | Umount)
echo "Umount $PROJ/modules"
echo -e " --- \e[34mBack to dev\e[39m --- "
umount $PROJ/modules/core
umount $PROJ/modules/downstream
umount $PROJ/modules/media
umount $PROJ/modules/waffles
;;
m | M | mount | Mount)
echo "Mount $PROJ/modules";
echo -e " --- \e[34mComposer time\e[39m --- "
mount -o bind $HOME/comp/modules/core $PROJ/modules/core
mount -o bind $HOME/comp/modules/downstream $PROJ/modules/downstream
mount -o bind $HOME/comp/modules/media $PROJ/modules/media
mount -o bind $HOME/comp/modules/waffles $PROJ/modules/waffles
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment