2017-07-14 67 views
0

當您使用流浪者構建虛擬機時,您是否可以幫助我在用戶級別執行命令?具體來說,我試圖更新Ubuntu屏幕左側的「啓動器圖標」。在下面的vagrant文​​件中,我已經嘗試了inline shell和一個內聯腳本。我將不勝感激您提供的任何幫助。流浪者執行命令行用戶級別

$script = <<SCRIPT 
    echo "Configuring Launcher Icons..." 
    gsettings set com.canonical.Unity.Launcher favorites "['application://org.gnome.Nautilus.desktop', 'application://chromium-browser.desktop', 'unity://running-apps', 'application://terminator.desktop', 'unity://expo-icon', 'unity://devices']" 
    service lightdm restart 
SCRIPT 

Vagrant.configure(2) do |config| 
    config.vm.box = "box-cutter/ubuntu1604-desktop" 

    config.vm.provider "virtualbox" do |vb| 
     # Display the VirtualBox GUI when booting the machine 
     vb.gui = true 
     vb.name = "UpdateLauncherIcons" 

     # Customize the amount of memory on the VM: 
     vb.memory = "4096" 
    end 

    config.vm.provision "shell", inline: <<-SHELL 
     # Update OS 
     apt-get update 
     apt-get upgrade 
     apt-get --yes install git 
     apt-get --yes install terminator 
     apt-get --yes install chromium-browser 

     gsettings set com.canonical.Unity.Launcher favorites "['application://org.gnome.Nautilus.desktop', 'application://chromium-browser.desktop', 'unity://running-apps', 'application://terminator.desktop', 'unity://expo-icon', 'unity://devices']" 
     service lightdm restart 

    SHELL 

    config.vm.provision "shell", inline: $script 

end 

筆記,流浪確實提供一條錯誤消息在執行內聯腳本時:

==> default: Running provisioner: shell... 
default: Running: inline script 
==> default: Configuring Launcher Icons... 
==> default: 
==> default: (process:6221): dconf-WARNING **: failed to commit changes to dconf: Cannot autolaunch D-Bus without X11 $DISPLAY 

進一步的測試證實,以及當在客戶機終端窗口內執行的命令下面工作。再一次,挑戰是讓這個命令從主機上執行的vagrantfile中運行。

gsettings set com.canonical.Unity.Launcher favorites "['application://org.gnome.Nautilus.desktop', 'application://chromium-browser.desktop', 'unity://running-apps', 'application://terminator.desktop', 'unity://expo-icon', 'unity://devices']" 
+0

'sudo -u vagrant​​'在您的聯機供應商中。 –

+0

@CodeGnome我試過你的建議和使用: 'sudo -u vagrant gsettings set com.canonical.Unity.Launcher favorites「['application://org.gnome.Nautilus.desktop','unity:// running-但是,我仍然在運行vagrantfile的主機終端中收到一條錯誤消息:「我的應用程序」 '==>默認:(進程:5495):dconf-CRITICAL **:無法創建目錄'/root/.cache/dconf':Permission de nied。 dconf將無法正常工作。' 您有任何其他建議嗎? – Nick

+0

爲什麼你以root身份創建任何東西?流浪使用者通常是'vagrant'或'ubuntu',並且默認使用sudo以root身份運行。我想你可能會更多地解釋你正在處理的權限和位置,因爲這顯然是一個權限問題。 –

回答

0

沒有使用過Ubuntu桌面放浪盒很長一段時間,但在我們的團隊項目的一個類似的設置使用「特權:假」爲殼供應方:

config.vm.provision "shell", privileged: false, path: "scripts/setup-desktop.sh" 
config.vm.provision "shell", privileged: false, path: "scripts/configure-desktop.sh" 

以及爲準備腳本設置自動登錄

echo "autologin-user=vagrant" | sudo tee -a /etc/lightdm/lightdm.conf 

# restart desktop 
sudo service lightdm restart 

下一個提供腳本,然後使用一些自動啓動功能來運行它

#!/bin/bash 

#modify shortcuts on ubuntu cause that are used in eclipse 
cat <<AUTOSTART_SHORTCUTS | sudo tee /home/vagrant/bin/modify-shortcuts 
#!/bin/sh 
gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-down [] 
gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-up [] 
#Disable Resize window (Alt + F8) 
gsettings set org.gnome.desktop.wm.keybindings begin-resize [] 
#Disable move window (Alt + F7) 
gsettings set org.gnome.desktop.wm.keybindings begin-move [] 

AUTOSTART_SHORTCUTS 
sudo chmod 777 /home/vagrant/bin/modify-shortcuts 

cat <<GSETTINGS | sudo tee /home/vagrant/bin/setup-unity 
#!/bin/sh 
# set favourites in launcher 
gsettings set com.canonical.Unity.Launcher favorites "['application://nautilus.desktop', 'application://gnome-terminal.desktop', 'application://firefox.desktop', 'application://chromium-browser.desktop', 'application://gvim.desktop', 'application://IDEA.desktop']" 

# set german keyboard 
gsettings set org.gnome.desktop.input-sources sources "[('xkb', 'de'), ('xkb', 'us')]" 

#Disabling screensaver 
#gsettings set org.gnome.desktop.screensaver idle-activation-enabled false 
gsettings set org.gnome.desktop.session idle-delay 0 

# disable screensaver locking desktop 
gsettings set org.gnome.desktop.screensaver lock-enabled false 

# cleanup 
sudo rm -f /home/vagrant/.config/autostart/setup-unity.desktop 
GSETTINGS 
sudo chmod 777 /home/vagrant/bin/setup-unity 

mkdir -p .config/autostart 

cat <<AUTOSTART_SHORTCUTS_DT | sudo tee /home/vagrant/.config/autostart/modify-shortcuts.desktop 
[Desktop Entry] 
Type=Application 
Exec=/home/vagrant/bin/modify-shortcuts 
Hidden=false 
NoDisplay=false 
X-GNOME-Autostart-enabled=true 
Name[en_US]=modify-shortcuts 
Name=modify-shortcuts 
Comment[en_US]= 
Comment= 
AUTOSTART_SHORTCUTS_DT 
cat <<GSETTINGS_DT | sudo tee /home/vagrant/.config/autostart/setup-unity.desktop 
[Desktop Entry] 
Type=Application 
Exec=/home/vagrant/bin/setup-unity 
Hidden=false 
NoDisplay=false 
X-GNOME-Autostart-enabled=true 
Name[en_US]=setup-unity 
Name=setup-unity 
Comment[en_US]= 
Comment=setup-unity 
GSETTINGS_DT 

# restart desktop 
sudo service lightdm restart 
+0

我很感謝您在查找和發佈此信息時的時間。我嘗試過使用你的所有建議而沒有成功。我希望對shell供應商來說「特權:假」是關鍵,但似乎我仍然失去了一些東西。 – Nick