Class: VpsCli::Setup

Inherits:
Object
  • Object
show all
Defined in:
lib/vps_cli/setup.rb

Overview

Various setup to include ufw firewalls, adding repos, adding fonts etc

Class Method Summary collapse

Class Method Details

.add_asciinema_repoObject

Deprecated.

Now part of the standard packaging of Ubuntu 18.04+



99
100
101
102
# File 'lib/vps_cli/setup.rb', line 99

def self.add_asciinema_repo
  # asciinema repo for recording the terminal
  Rake.sh('sudo apt-add-repository -y ppa:zanchey/asciinema')
end

.add_dejavu_sans_mono_fontObject



46
47
48
49
# File 'lib/vps_cli/setup.rb', line 46

def self.add_dejavu_sans_mono_font
  Rake.sh('mkdir -p ~/.local/share/fonts')
  Rake.sh(%(cd ~/.local/share/fonts && curl -fLo "DejaVu Sans Mono for Powerline Nerd Font Complete.otf" https://github.com/ryanoasis/nerd-fonts/raw/master/patched-fonts/DejaVuSansMono/Regular/complete/DejaVu%20Sans%20Mono%20Nerd%20Font%20Complete%20Mono.ttf))
end

.add_docker_repoObject

Deprecated.

Now part of the standard packaging of Ubuntu 18.04+



66
67
68
69
70
71
72
73
74
75
# File 'lib/vps_cli/setup.rb', line 66

def self.add_docker_repo
  # Instructions straight from https://docs.docker.com/install/linux/docker-ce/ubuntu/#set-up-the-repository
  # Docker repo
  Rake.sh('curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -')
  Rake.sh('sudo apt-key fingerprint 0EBFCD88')
  Rake.sh(%{yes "\n" | sudo add-apt-repository -y \
      "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
         $(lsb_release -cs) \
         stable"})
end

.add_mosh_repoObject

Deprecated.

Now part of the standard packaging of Ubuntu 18.04+



93
94
95
96
# File 'lib/vps_cli/setup.rb', line 93

def self.add_mosh_repo
  # mosh repo
  Rake.sh(%(yes "\n" | sudo add-apt-repository ppa:keithw/mosh))
end

.add_neovim_repoObject

Deprecated.

Now part of the standard packaging of Ubuntu 18.04+



87
88
89
90
# File 'lib/vps_cli/setup.rb', line 87

def self.add_neovim_repo
  # add neovim
  Rake.sh('sudo add-apt-repository ppa:neovim-ppa/stable')
end

.add_reposObject

Adds repos to the package manager to be tracked Adds the following repos: docker, yarn This method used to add neovim, asciinema, and mosh as well But they are all part of the base ubuntu 18.10 release



56
57
58
59
60
61
62
63
# File 'lib/vps_cli/setup.rb', line 56

def self.add_repos
  ## Now part of cosmic release for Ubuntu 18.10
  # add_yarn_repo
  # add_docker_repo
  # add_neovim_repo
  # add_mosh_repo
  # add_asciinema_repo
end

.add_yarn_repoObject

Deprecated.

Now part of the standard packaging of Ubuntu 18.04+



78
79
80
81
82
83
# File 'lib/vps_cli/setup.rb', line 78

def self.add_yarn_repo
  # yarn repo
  Rake.sh(%( curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -))
  Rake.sh(%(echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list))
  Rake.sh('sudo apt update')
end

.fullObject

Runs the full setup process

See Also:

  • #ufw_setup
  • #add_dejavu_sans_mono_font
  • this method is deprecated due to all packages being added to latest ubuntu 18.04+


21
22
23
24
25
26
27
# File 'lib/vps_cli/setup.rb', line 21

def self.full
  # this is here for compatibility purposes, no longer runs anything
  add_repos
  add_dejavu_sans_mono_font

  ufw_setup
end

.privileged_user?Boolean

checks if the user has sudo privileges via uid

Returns:

  • (Boolean)


7
8
9
# File 'lib/vps_cli/setup.rb', line 7

def self.privileged_user?
  Process.uid.zero?
end

.root?Boolean

checks if a user is root

Returns:

  • (Boolean)


12
13
14
# File 'lib/vps_cli/setup.rb', line 12

def self.root?
  privileged_user? && Dir.home == '/root'
end

.ufw_setupObject

Sets up ufw for you to be able to have certain firewalls in place Must be run after installing ufw via sudo apt install ufw



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/vps_cli/setup.rb', line 33

def self.ufw_setup
  Rake.sh('sudo ufw default deny incoming')
  Rake.sh('sudo ufw default allow outgoing')
  # allows ssh & mosh connections
  Rake.sh('sudo ufw allow 60000:61000/tcp')

  # Typical ssh port
  Rake.sh('sudo ufw allow 22')

  Rake.sh('yes | sudo ufw enable')
  Rake.sh('yes | sudo systemctl restart sshd')
end