내 스크립트에 대한 도움말 또는 조언

내 스크립트에 대한 도움말 또는 조언

VirtualBox에서 Ubuntu를 실행하고 NetBeans를 사용하는 경우 유용할 수 있는 다음 스크립트를 작성했습니다. 이 스크립트는 다음과 같이 다른 VirtualBox 요구 사항에도 사용될 수 있습니다.

  1. 애플리케이션(NetBeans)을 설치합니다.
  2. Ubuntu가 게스트 추가로 실행되고 있는지 테스트합니다.
  3. 일반적으로 모든 시스템(호스트 또는 게스트)에서 동일하게 유지되는 기본 프로젝트 이름을 기반으로 공유 폴더 마운트를 시도합니다.
  4. rc.local사용 편의성을 위해 마운트를 작성합니다 .
  5. 폴더가 마운트 해제될 수 있도록 사용자 저장소에 파일을 생성 및/또는 추가합니다.

업그레이드하지 않으면 스크립트가 완벽하게 작동합니다. 이러한 시나리오에서는 여러 개의 마운트가 수행되고 에 여러 항목이 있으므로 마운트 해제 스크립트가 의도한 대로 작동하지 않습니다 /etc/mtab.

이는 일반적으로 모든 마운트가 마운트 해제될 수 있으므로 umount플래그를 사용하여 해결할 수 없습니다 . 모든 공유 폴더를 마운트 해제할 필요가 없기 때문에 원하는 솔루션이 아닙니다 .-f -l -a -tumount -a -t vboxsf/target

해결책을 찾았지만 bash/스크립팅이 처음이고 구현 방법을 모릅니다. 내 해결책은 rc.local중복 마운트를 피하기 위해 잠재적인 중복 행을 테스트하는 것입니다.

#!/bin/bash
#Author: Yucca Nel http://thejarbar.org
#Will restart system
PATH="/sbin:/usr/sbin:/bin:/usr/bin"
export PATH

#Modify these variables as needed...
tempWork=/tmp/work
startupScript=/etc/init.d/rc.local
defaultNetBeansVersion=7.0.1

echo "Provide NetBeans version (7.0.1 is default) then hit [Enter] :"
  read NetBeansVersion

  if [ -z "$NetBeansVersion" ]
    then
    $NetBeansVersion=$defaultNetBeansVersion
  fi

mkdir -p /$tempWork;
cd /$tempWork;

wget http://dlc.sun.com.edgesuite.net/netbeans/7.0.1/final/bundles/netbeans-$NetBeansVersion-ml-javase-linux.sh;
sh $tempWork/*sh;


#Add Netbeans launcher to your PATH. Doing so allows you to run 'netbeans' command from the terminal
#This line will need to be changed if you changed the default install location (IOW Netbeans is not in ~/)
sudo ln -f -s ~/netbeans-$NetBeansVersion/bin/netbeans /usr/bin/;

#If you use VirtualBox , you can share your projects between Host and guest. Name of shared
#folder must match 'NetBeansProjects'
mkdir -p $HOME/NetBeansProjects

if [ -f /sbin/mount.vboxsf ]
then
    sudo /sbin/umount /home/$HOME/NetBeansProjects
    sudo /sbin/mount.vboxsf NetBeansProjects $HOME/NetBeansProjects
fi

if mountpoint -q ~/NetBeansProjects
then
#Add it to the universal start script to automate process...
    sudo sed -ie '$d' $startupScript
    echo "sudo /sbin/mount.vboxsf NetBeansProjects $HOME/NetBeansProjects"| sudo tee -a $startupScript
    echo "exit 0"| sudo tee -a $startupScript
    sudo chmod +x $startupScript

#Create a mount and unmount script file and add it to users local bin
    rm -rf $tempWork/*
    echo '#!/bin/bash' > $tempWork/netbeans-mount.sh
    echo '#!/bin/bash' > $tempWork/netbeans-umount.sh
    echo '#!/bin/bash' > $tempWork/mount-from-host.sh
    echo '#!/bin/bash' > $tempWork/unmount-from-host.sh
    echo "sudo /sbin/mount.vboxsf NetBeansProjects $HOME/NetBeansProjects" >> $tempWork/netbeans-mount.sh
    echo "sudo /sbin/mount.vboxsf NetBeansProjects $HOME/NetBeansProjects" >> $tempWork/mount-from-host.sh
    echo "sudo umount $HOME/NetBeansProjects" >> $tempWork/netbeans-umount.sh
    echo "sudo umount $HOME/NetBeansProjects" >> $tempWork/unmount-from-host.sh
    echo "exit 0" >> $tempWork/unmount-from-host.sh
    echo "exit 0" >> $tempWork/mount-from-host.sh
    echo "exit 0" >> $tempWork/netbeans-mount.sh
    echo "exit 0" >> $tempWork/netbeans-umount.sh

    sudo chmod +x $tempWork/*
    sudo mv -f $tempWork/*.sh /usr/local/bin
    rm -rf $tempWork
fi

#This function is used to cleanly exit with an error code.
function error_exit {
    sleep 7
    exit 1
}
#restart
sudo reboot
exit 0

어떤 조언이 있습니까? 내 목표는 가장 필요한 도구를 모든 Linux(Ubuntu뿐만 아니라)에 다운로드하고 기존 개발 호스트가 있는 경우 다시 설치할 필요가 없는 잠재적인 항목을 마운트하는 Java 개발자를 위한 슈퍼 스크립트를 작성하는 것입니다. Maven, Tomcat, SVN, JBoss와 같은 것들은 이미 호스트 시스템에 있고 다른 시스템을 하나로 결합하면 추가적인 이점이 있는 경우 특별한 게스트 설치가 필요하지 않습니다. 예를 들어 Windows는 Photoshop 및 Safari 브라우저를 실행할 수 있지만 Linux는 기본적으로 SSH와 같은 더 나은 사용자 정의 및 도구를 제공합니다.

답변1

제가 이해했는지 잘 모르겠지만... 여기서는 grep 출력의 고유 라인 수를 계산합니다.

grep "sudo /sbin/mount.vboxsf" /etc/rc.local | sort | uniq -c | wc -l

두 개는 에코 라인에서 나오고 두 개는 명령줄에서 나옵니다. 항상 4와 같아야 합니다. 그렇죠?

관련 정보