welcome/welcome.rb

205 lines
6.0 KiB
Ruby
Raw Permalink Normal View History

2020-03-08 01:31:20 +00:00
#!/usr/bin/env ruby
2020-04-15 21:33:52 +00:00
require "etc"
2020-03-08 01:31:20 +00:00
require "tty-prompt"
require "tty-screen"
2024-05-21 20:44:24 +00:00
require "uri"
2020-03-08 01:31:20 +00:00
def sep
2020-11-27 23:14:19 +00:00
puts
puts "~" * TTY::Screen.width
puts
2020-03-08 01:31:20 +00:00
end
prompt = TTY::Prompt.new
2024-08-09 21:43:47 +00:00
shell = ""
2020-03-08 01:31:20 +00:00
system "clear"
# welcome
system "figlet -f slant tilde.club"
2020-03-08 01:31:20 +00:00
puts
puts "welcome to tilde.club!!"
2020-03-08 01:31:20 +00:00
puts
puts "we're glad you're here!"
puts "let's walk through some basic questions to get you set up"
prompt.keypress("ready? press enter to continue")
puts
# change your password
sep
puts "step 1:"
puts " first, let's change your shell password"
puts
puts " you'll find the temporary password in your welcome email"
puts " enter the current password once, followed by your new password twice"
success = false
until success do
success = system "passwd"
end
2020-03-08 01:31:20 +00:00
# select your shell
sep
puts "step 2:"
puts " now, let's pick your default shell"
puts
puts " a shell is a program that handles commands you type"
puts " bash is the most common shell and is a good place to start"
puts " note that the list of shells extends beyond one page"
puts
shells = File.readlines("/etc/shells")
2020-11-27 23:14:19 +00:00
.select { |line| !line.start_with?("#") }
.select { |line| File.basename(line).match?(/^(sh|bash|zsh|fish|csh|tcsh|ksh|mksh|dash|xonsh|powershell|elvish|rksh|rmksh|hx)$/) }
2020-11-27 23:14:19 +00:00
.map(&:chomp)
.map { |line| [File.basename(line), line] }
.to_h
2020-03-08 01:31:20 +00:00
shell = prompt.select(" which shell would you like to use?", shells, per_page: shells.count)
puts
puts " great, you've picked #{shell}!"
puts " in order to change your shell, you'll have to enter your password again"
success = false
retries = 3
until success || retries == 0 do
success = system "chsh -s #{shell}"
unless success
retries -= 1
puts " Error: Failed to change the shell. Please try again. (#{retries} retries left)"
end
end
if success
puts " Your default shell has been successfully changed to #{shell}."
else
puts " Failed to change the shell after multiple attempts. Please contact support."
end
2020-03-08 01:31:20 +00:00
# default text editor
2020-03-08 01:31:20 +00:00
sep
puts "step 3:"
puts " now, let's pick your default text editor"
puts
puts " You can change the default command-line text"
puts " editor used by various programs, such as crontab"
puts
editors = File.readlines("/etc/editors")
.select { |line| !line.start_with?("#") }
.map(&:chomp)
.map { |line| [File.basename(line), line] }
.to_h
editors = prompt.select(" which editor would you like to use?", editors, per_page: editors.count)
puts
puts " great, you've picked #{editors}!"
success = false
until success do
success = system "echo 'export EDITOR=#{editors}' >> #{Dir.home}/.bash_profile"
end
# byobu or not
sep
puts "step 4:"
2020-03-08 01:31:20 +00:00
puts " we recommend using a terminal multiplexer, which is a tool that allows you"
puts " to have tabs in your shell and even disconnect while leaving things running"
puts " as you left them."
puts
puts " the tool we recommend is byobu: https://superuser.com/a/423397/866501"
puts
2020-03-08 02:47:45 +00:00
puts " if you're not sure about this, decline for now. you can set it up at any time"
puts " later on by running 'byobu-enable' from your shell."
puts
2020-03-08 01:31:20 +00:00
enable_byobu = prompt.yes?(" would you like to set byobu to launch automatically when you log in?")
if enable_byobu
2020-11-27 23:14:19 +00:00
system "byobu-enable"
puts "our default configs will connect you to chat and open a mail client when you log in"
2020-03-08 01:31:20 +00:00
end
# tz
sep
puts "step 5:"
2020-03-08 01:31:20 +00:00
puts " great, let's set up your timezone!"
puts
tz = %x{tzselect}.chomp
2020-03-08 01:31:20 +00:00
puts
puts " you selected #{tz}, adding this to your profile now"
2024-08-09 21:49:30 +00:00
if File.basename(shell) == "zsh"
open("#{Dir.home}/.zshrc", "a") { |f| f.puts "export TZ='#{tz}'" }
puts " Timezone set in your .zshrc file for ZSH."
else
open("#{Dir.home}/.bash_profile", "a") { |f| f.puts "export TZ='#{tz}'" }
puts " Timezone set in your .bash_profile file."
end
puts " It might not take effect until you log out and back in."
2020-03-08 01:31:20 +00:00
2020-04-15 21:33:52 +00:00
# email forwarding
2020-03-08 01:31:20 +00:00
sep
puts "step 6:"
2020-04-15 21:33:52 +00:00
puts " tilde.club has a standard mailserver that you can use to send"
puts " and receive mail using #{Etc.getlogin}@tilde.club"
puts
if prompt.yes?(" would you like to forward your mail elsewhere?")
forward_addr = prompt.ask(" where would you like to forward your mail to?") do |q|
2024-05-21 20:44:24 +00:00
q.validate(URI::MailTo::EMAIL_REGEXP)
2020-04-15 21:33:52 +00:00
q.messages[:valid?] = "Invalid email address"
end
File.open("#{Dir.home}/.forward", "w") { |f| f.puts forward_addr }
puts " ok, your mail will now be sent off to #{forward_addr}"
puts " you can update this in your ~/.forward file"
puts " if you remove the file, you can use our mailserver as usual without forwarding"
2020-04-15 21:33:52 +00:00
else
puts " alright, your mail won't be forwarded anywhere."
puts " you can use any standard mail client with smtp and imap"
puts " to access your @tilde.club email"
puts " see the wiki page for more information: https://tilde.club/wiki/email.html"
puts
puts " if you decide to forward your mail in the future, you can do so"
puts " by putting the destination address in a file called ~/.forward"
puts " eg: echo \"me@example.com\" > ~/.forward"
2020-04-15 21:33:52 +00:00
end
puts
2020-04-15 21:33:52 +00:00
2020-04-15 21:46:55 +00:00
# 2fa
2020-04-15 21:33:52 +00:00
sep
puts "step 7:"
2020-04-15 21:46:55 +00:00
puts " tilde.club supports two factor authentication."
if prompt.yes?("would you like to set up 2fa now?")
system "setup-2fa"
else
puts " if you change your mind or need to make changes you can run"
puts " the 'setup-2fa' command"
puts " for additional info, see the wiki: https://tilde.club/wiki/2fa.html"
end
puts
# pronouns
sep
puts "step 8:"
2020-03-08 01:38:38 +00:00
pronouns = prompt.ask(" what are your preferred pronouns?")
2020-03-08 01:31:20 +00:00
puts " saving your pronouns to your ~/.pronouns file."
puts " feel free to update it as needed!"
2020-03-08 02:52:24 +00:00
open("#{Dir.home}/.pronouns", "w") { |f| f.puts pronouns }
2020-03-08 01:31:20 +00:00
# welcome completed
sep
puts "welcome to the ~club!"
2020-03-08 01:31:20 +00:00
puts
puts "please come stop by chat when you get a chance by running the 'chat' command" unless enable_byobu
puts "we're happy to help as needed and get you any information you're looking for"
puts "have a look at our wiki: https://tilde.club/wiki/ (ctrl-click will let you open that from here)"
puts "if you need to run this wizard again, you can do so with the `firstlogin` command"
2020-04-15 20:08:43 +00:00
File.delete("#{Dir.home}/.new_user")
2020-03-08 01:31:20 +00:00
if enable_byobu
2020-11-27 23:14:19 +00:00
exec "byobu"
2020-03-08 01:31:20 +00:00
end