2018年1月5日金曜日

VagrantでTightVNC ServerとEclipse、Xfceデスクトップ環境がインストールされた仮想マシン(Ubuntu16.04)を構築する

以下のVagrantfileを使用して、TightVNC ServerとEclipse、Xfceデスクトップ環境をインストールした仮想マシン(Ubuntu16.04)を構築する事ができます。
仮想マシン構築後、VNCクライアントから192.168.1.113:5901にアクセスします。パスワードはvagrantです。

Vagrantfile
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "bento/ubuntu-16.04"
  config.vm.hostname = "ub1604vncxfceeclipse"
  config.vm.network :public_network, ip:"192.168.1.113"
  config.vm.provider :virtualbox do |vbox|
     vbox.name = "ub1604vncxfceeclipse"
     vbox.gui = true
     vbox.cpus = 4
     vbox.memory = 4096
  end
  config.vm.provision "shell", inline: <<-SHELL
sed -i.bak -e "s#http://archive.ubuntu.com/ubuntu/#http://ftp.riken.jp/pub/Linux/ubuntu/#g"; /etc/apt/sources.list
localectl set-locale LANG=ja_JP.UTF-8
localectl set-keymap jp106
apt-get update
apt-get -y install fcitx-mozc xubuntu-desktop language-pack-ja tightvncserver expect
im-config -n fcitx

# set passwd for vnc
cat << EOC > /tmp/initpass.sh
/usr/bin/expect << EOF
spawn "vncpasswd"
expect "Password:"
send "vagrant\\r"
expect "Verify:"
send "vagrant\\r"
expect "Would you like to enter a view-only password (y/n)?"
send "n\\r"
expect eof
exit
EOF
EOC
chmod +x /tmp/initpass.sh
sudo -u vagrant -H /bin/bash -c "/tmp/initpass.sh"

sudo -u vagrant -H /bin/bash -c "/usr/bin/vncserver"
echo 'startxfce4 &' >> /home/vagrant/.vnc/xstartup
chown vagrant:vagrant /home/vagrant/.vnc/xstartup

cat << EOF > /etc/systemd/system/vnc@.service
[Unit]
Description=tightvncserver
After=syslog.target network.target
[Service]
Type=forking
User=vagrant
PAMName=login
PIDFile=/home/vagrant/.vnc/%H:%i.pid
ExecStartPre=/usr/bin/vncserver -kill :%i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -geometry 1280x800 -depth 24 :%i
ExecStop=/usr/bin/vncserver -kill :%i
[Install]
WantedBy=multi-user.target
EOF
systemctl enable vnc@1.service
systemctl dbus start

cat << EOC > /tmp/startvnc.sh
/usr/bin/expect << EOF
spawn systemctl start vnc@1.service
expect "Password:"
send "vagrant\\r"
expect eof
exit
EOF
EOC

chmod +x /tmp/startvnc.sh
sudo -u vagrant -H /bin/bash -c "/tmp/startvnc.sh"

# install java
apt-get -y install openjdk-8-jdk

wget http://ftp.jaist.ac.jp/pub/eclipse/technology/epp/downloads/release/oxygen/1/eclipse-java-oxygen-1-linux-gtk-x86_64.tar.gz
tar xvfz eclipse-java-oxygen-1-linux-gtk-x86_64.tar.gz
mv eclipse /opt

# eclipse oxygenのショートカットを作成
cat << EOF > /usr/share/applications/eclipse.desktop
#!/usr/bin/env xdg-open
[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Exec=/opt/eclipse/eclipse
Name=eclipse
Categories=Utility;Development;
EOF

SHELL
end

〇eclipseの画面



○関連情報
・Eclipseに関する他の記事はこちらを参照してください。

0 件のコメント:

コメントを投稿