私のスクリプトに関するヘルプやアドバイス

私のスクリプトに関するヘルプやアドバイス

私は次のスクリプトを書きました。これは、VirtualBox で Ubuntu を実行し、NetBeans を利用する場合に役立つかもしれません。このスクリプトは、次のことを行うため、VirtualBox のその他のニーズにも使用できます。

  1. アプリケーション (NetBeans) をインストールします。
  2. Ubuntu がゲスト追加機能を使用して実行されているかどうかをテストします。
  3. 通常、どのシステム (ホストまたはゲスト) でも同じであるデフォルトのプロジェクト名に基づいて共有フォルダーをマウントしようとします。
  4. 使いやすさのためにマウントを書き込みますrc.local
  5. フォルダーをアンマウントできるように、ユーザーのビンにファイルを作成または追加します。

アップグレードしない限り、スクリプトは問題なく動作します。アップグレードする場合、複数のマウントが行われ、 に複数のエントリが存在するため、アンマウント スクリプトは意図したとおりに機能しません/etc/mtab

umountこれは、のようなフラグを使用しても解決できません-f -l -a -t。通常、これによりすべてのマウントがアンマウントされる可能性があります。すべての共有フォルダーをアンマウントする必要がない可能性があるため、これも望ましい解決策umount -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

何かアドバイスはありますか? 私の目標は、Java 開発者向けのスーパー スクリプトを記述して、ほとんどの必要なツールを Linux (Ubuntu だけでなく) にダウンロードし、既存の開発ホストがある場合に再インストールする必要のない可能性のあるものをマウントすることです。Maven、Tomcat、SVN、JBoss などは、すでにホスト システム上にある場合は特別なゲスト インストールは必要ありません。また、異なるシステムを 1 つに組み合わせることにはさらなる利点があります。たとえば、Windows では Photoshop や Safari ブラウザーを実行できますが、Linux ではより優れたカスタマイズと ssh などのツールがすぐに使用できます。

答え1

理解できたか分かりませんが、ここでは grep 出力から一意の行の数を数えます。

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

2 つはエコー ラインから、2 つはコマンド ラインから来ます。常に 4 になるはずですよね?

関連情報