jlacroix

Arch Linux Fabfile

Apr 10th, 2015
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 9.37 KB | None | 0 0
  1. # System installation script
  2.  
  3. from fabric.api import put, run, settings, sudo, task
  4. from fabric.contrib.files import contains, exists
  5.  
  6.  
  7. @task  # Configure wired networking
  8. def configure_wired_networking():
  9.     sudo('pacman -Sy --needed --noconfirm network-manager-applet \
  10. networkmanager networkmanager-openvpn networkmanager-pptp \
  11. networkmanager-vpnc')
  12.     sudo('systemctl enable NetworkManager')
  13.  
  14.  
  15. @task  # Configure wireless networking
  16. def configure_wireless_networking():
  17.     configure_wired_networking()
  18.     sudo('pacman -Sy --needed --noconfirm network-manager-applet \
  19. networkmanager networkmanager-openvpn wireless_tools wpa_supplicant \
  20. wpa_actiond dialog')
  21.  
  22.  
  23. @task  # Install Intel driver
  24. def install_video_intel():
  25.     if not contains('/etc/pacman.conf', 'archlinuxfr'):
  26.         configure_repositories()
  27.     sudo('pacman -Sy --needed --noconfirm xf86-video-intel \
  28. lib32-intel-dri lib32-mesa lib32-libgl xorg-server xorg-xinit \
  29. xorg-server-utils mesa')
  30.  
  31.  
  32. @task  # Install nouveau driver
  33. def install_video_nouveau():
  34.     if not contains('/etc/pacman.conf', 'archlinuxfr'):
  35.         configure_repositories()
  36.     sudo('pacman -Sy --needed --noconfirm xf86-video-nouveau \
  37. lib32-nouveau-dri xorg-server xorg-xinit xorg-server-utils mesa')
  38.  
  39.  
  40. @task  # Install nvidia driver
  41. def install_video_nvidia():
  42.     if not contains('/etc/pacman.conf', 'archlinuxfr'):
  43.         configure_repositories()
  44.     sudo('pacman -Sy --needed --noconfirm nvidia lib32-nvidia-libgl \
  45. xorg-server xorg-xinit xorg-server-utils mesa')
  46.  
  47.  
  48. @task  # Install vbox driver
  49. def install_video_vbox():
  50.     sudo('pacman -Sy --needed --noconfirm virtualbox-guest-utils \
  51. xorg-server xorg-xinit xorg-server-utils mesa mesa-libgl')
  52.     sudo('touch /etc/modules-load.d/virtualbox.conf')
  53.     sudo('echo vboxguest >> /etc/modules-load.d/virtualbox.conf')
  54.     sudo('echo vboxsf >> /etc/modules-load.d/virtualbox.conf')
  55.     sudo('echo vboxvideo >> /etc/modules-load.d/virtualbox.conf')
  56.  
  57.  
  58. @task  # Set hostname for the machine
  59. def set_hostname():
  60.     sudo('echo "Please enter the hostname:" && read myhostname && \
  61. hostnamectl set-hostname "$myhostname"')
  62.  
  63.  
  64. @task  # Configure date/time synchronization
  65. def configure_ntp():
  66.     put('ntp.conf', '/etc/ntp.conf', use_sudo=True)
  67.     sudo('chown root:root /etc/ntp.conf')
  68.     sudo('chmod 644 /etc/ntp.conf')
  69.  
  70.     sudo('pacman -S --needed --noconfirm ntp')
  71.     sudo('systemctl start ntpd')
  72.     sudo('systemctl enable ntpd')
  73.     sudo('timedatectl set-ntp 1')
  74.  
  75.  
  76. @task  # Configure repositories
  77. def configure_repositories():
  78.     if exists('/etc/pacman.d'):
  79.         put('pacman.conf', '/etc/pacman.conf', use_sudo=True)
  80.         sudo('chown root:root /etc/pacman.conf')
  81.         sudo('chmod 644 /etc/pacman.conf')
  82.         sudo('pacman -Syyy')
  83.         sudo('pacman -S --needed --noconfirm yaourt')
  84.  
  85.  
  86. @task  # Create local user account
  87. def create_user():
  88.     if not contains('/etc/group', 'vboxusers'):
  89.         run('groupadd vboxusers')
  90.     if not contains('/etc/group', 'sudo'):
  91.         run('groupadd sudo')
  92.     if contains('/etc/passwd', 'jay'):
  93.         print('The user already exists, so skipping user creation.')
  94.     else:
  95.         run('useradd -m -g users -G wheel,storage,power,vboxusers,sudo -s \
  96. /bin/bash jay')
  97.         run('passwd jay')
  98.  
  99.  
  100. @task  # Install games
  101. def install_games():
  102.     if not contains('/etc/pacman.conf', 'archlinuxfr'):
  103.         configure_repositories()
  104.     if not exists('/home/jay'):
  105.         create_user()
  106.     if not exists('/home/jay/.mame'):
  107.         run('mkdir /home/jay/.mame')
  108.         run('chmod 755 /home/jay/.mame')
  109.         put('mame.ini', '/home/jay/.mame/mame.ini')
  110.         run('chmod 644 /home/jay/.mame/mame.ini')
  111.         run('chown jay:jay -R /home/jay/.mame')
  112.         sudo('pacman -Sy --needed --noconfirm chromium-bsu frozen-bubble \
  113. mednafen neverball sdlmame supertux supertuxkart steam wesnoth')
  114.  
  115.  
  116. @task  # Install GNOME
  117. def install_gnome():
  118.     if not contains('/etc/pacman.conf', 'archlinuxfr'):
  119.         configure_repositories()
  120.     if not exists('/home/jay'):
  121.         create_user()
  122.     sudo('pacman -Sy --needed --noconfirm evince file-roller gnome-control-center \
  123. gnome-music gnome-power-manager gnome-shell gnome-shell-extensions \
  124. gnome-terminal gnome-tweak-tool libreoffice-gnome nautilus \
  125. ttf-liberation ttf-dejavu xdg-user-dirs')
  126.  
  127.  
  128. @task  # Install lightdm on the target
  129. def install_lightdm():
  130.     sudo('pacman -Sy --needed --noconfirm acpid lightdm lightdm-gtk2-greeter')
  131.     if not exists('/etc/lightdm'):
  132.         sudo('mkdir /etc/lightdm')
  133.     put('lightdm.conf', '/etc/lightdm/lightdm.conf', use_sudo=True)
  134.     put('lightdm-gtk-greeter.conf', '/etc/lightdm/lightdm-gtk-greeter.conf', use_sudo=True)
  135.     put('lightdm.png', '/etc/lightdm/lightdm.png', use_sudo=True)
  136.     sudo('systemctl enable lightdm.service')
  137.     sudo('systemctl enable acpid.service')
  138.     sudo('locale-gen')
  139.  
  140.  
  141. @task  # Install MATE on the target
  142. def install_mate():
  143.     sudo('pacman -Sy --needed --noconfirm atril caja mate-backgrounds \
  144.            mate-control-center mate-desktop mate-dialogs \
  145.            mate-icon-theme mate-media-pulseaudio mate-menus \
  146.            mate-notification-daemon mate-panel mate-polkit \
  147.            mate-session-manager mate-settings-daemon-pulseaudio \
  148.            mate-screensvaer-hacks mate-terminal mate-themes mozo pluma')
  149.  
  150.  
  151. @task  # Install openbox packages on the target
  152. def install_openbox():
  153.     if not exists('/home/jay'):
  154.         create_user()
  155.     sudo('pacman -Sy --needed base-devel')
  156.     if not contains('/etc/pacman.conf', 'archlinuxfr'):
  157.         configure_repositories()
  158.     if not exists('/usr/bin/yaourt'):
  159.         run('pacman -S --noconfirm yaourt')
  160.     if not exists('/usr/bin/tintwizard'):
  161.         with settings(warn_only=True):
  162.             run('yaourt tintwizard')
  163.     if not exists('/usr/bin/compton'):
  164.         with settings(warn_only=True):
  165.             run('yaourt compton')
  166.     sudo('pacman -Sy --needed --noconfirm acpid cantarell-fonts \
  167. clipit dmenu gksu gmrun gnome-keyring gnome-themes-standard gsimplecal \
  168. gtk-engine-murrine gtk-engine-unico lxappearance mousepad nitrogen \
  169. obconf oblogout obmenu openbox pcmanfm plank scrot tint2 tilda \
  170. volumeicon xarchiver xscreensaver')
  171.     put('oblogout.conf', '/etc/oblogout.conf', use_sudo=True)
  172.  
  173.  
  174. @task  # Install packages
  175. def install_packages():
  176.     sudo('pacman -Sy --needed base-devel')
  177.     if not contains('/etc/pacman.conf', 'archlinuxfr'):
  178.         configure_repositories()
  179.     if not exists('/home/jay'):
  180.         create_user()
  181.     if not exists('/usr/bin/yaourt'):
  182.         sudo('pacman -Sy --noconfirm yaourt')
  183.     if not exists('/usr/bin/google-chrome-stable'):
  184.         with settings(warn_only=True):
  185.             run('yaourt google-chrome')
  186.     if not exists('/usr/bin/urxvt'):
  187.         with settings(warn_only=True):
  188.             run('yaourt rxvt-unicode-pixbuf')
  189.     sudo('pacman -Sy --needed --noconfirm alsa-utils asunder banshee \
  190. brasero cmus codeblocks colordiff conky dosfstools easytag eclipse  \
  191. exfat-utils fabric filezilla fish flake8 freerdp fuse-exfat \
  192. galculator geany geany-plugins gimp git gparted gst-libav \
  193. gst-plugins-bad gst-plugins-base gst-plugins-good gst-plugins-ugly \
  194. gvfs gvfs-smb gtk-recordmydesktop guake htop hunspell-en hyphen-en \
  195. iotop lame libreoffice-writer libreoffice-calc linux-lts \
  196. linux-lts-headers libreoffice-common libreoffice-en-US \
  197. libreoffice-impress libtheora libvorbis lm_sensors midori mosh mpv \
  198. ncdu net-tools nfs-utils ntfs-3g openssh pavucontrol p7zip pep8-python2 \
  199. pep8-python3 plank python-pip remmina roxterm screen smbclient sshfs \
  200. stalonetray synapse terminus-font terminator the_silver_searcher tmux \
  201. transmission-gtk \ttf-liberation ttf-dejavu unrar viewnior vim-nerdtree \
  202. vim-python3 vim-colorsamplerpack vlc vorbis-tools xchat \
  203. xcursor-vanilla-dmz xsel xterm xvidcore zip')
  204.     put('syncthing.service', '/etc/systemd/system/syncthing.service', use_sudo=True)
  205.     sudo('chown root:root /etc/systemd/system/syncthing.service')
  206.     sudo('chmod +x /etc/systemd/system/syncthing.service')
  207.     sudo('systemctl enable syncthing.service')
  208.     if not exists('/home/jay/.local/share/applications'):
  209.         run('mkdir -p /home/jay/.local/share/applications')
  210.         run('chmod 755 -R /home/jay/.local')
  211.     if not exists('/home/jay/.local/share/applications/firefox.desktop'):
  212.         put('firefox.desktop', '\
  213. /home/jay/.local/share/applications/firefox.desktop')
  214.     if not exists('/home/jay/.local/share/applications/\
  215. thunderbird.desktop'):
  216.         put('thunderbird.desktop', '\
  217. /home/jay/.local/share/applications/thunderbird.desktop')
  218.  
  219.  
  220. @task  # Install sudo
  221. def install_sudo():
  222.     sudo('pacman -S --needed --noconfirm sudo')
  223.     if not contains('/etc/group', 'sudo'):
  224.         sudo('groupadd sudo')
  225.     if not exists('/home jay'):
  226.         create_user()
  227.     run('usermod -aG sudo jay')
  228.  
  229.  
  230. @task  # Configure virtualbox host
  231. def setup_virtualbox_host():
  232.     if not exists('/home/jay'):
  233.         create_user()
  234.     sudo('pacman -S --needed --noconfirm linux-headers virtualbox \
  235. virtualbox-host-modules virtualbox-host-modules-lts virtualbox-guest-iso')
  236.     sudo('usermod -aG vboxusers jay')
  237.     sudo('touch /etc/modules-load.d/virtualbox.conf')
  238.     sudo("echo 'vboxdrv' > /etc/modules-load.d/virtualbox.conf")
  239.     sudo("echo 'vboxnetadp' >> /etc/modules-load.d/virtualbox.conf")
  240.     sudo("echo 'vboxnetflt' >> /etc/modules-load.d/virtualbox.conf")
Advertisement
Add Comment
Please, Sign In to add comment