mirror of
https://github.com/genebean/dots.git
synced 2026-03-27 09:27:44 -04:00
Update repo structure as part of nixification
This commit is contained in:
parent
49e67c64fb
commit
cc0efcfdde
56 changed files with 181 additions and 154 deletions
27
legacy/bin/bootstrap.sh
Executable file
27
legacy/bin/bootstrap.sh
Executable file
|
|
@ -0,0 +1,27 @@
|
|||
#!/bin/bash
|
||||
echo 'This script takes care of getting dots ready to use'
|
||||
echo 'Enter the number of the task you want to perform:'
|
||||
|
||||
PS3='Task: '
|
||||
select TASK in 'Mac setup' 'EL setup' 'Mint setup' 'Quit';
|
||||
do
|
||||
case $TASK in
|
||||
'Mac setup' )
|
||||
~/.dotfiles/bin/bootstrap/bootstrap_mac.sh now
|
||||
;;
|
||||
'EL setup' )
|
||||
~/.dotfiles/bin/bootstrap/bootstrap_el.sh now
|
||||
;;
|
||||
'Mint setup' )
|
||||
~/.dotfiles/bin/bootstrap/bootstrap_mint.sh now
|
||||
;;
|
||||
'Quit' )
|
||||
echo 'Exiting'
|
||||
exit 0
|
||||
;;
|
||||
* )
|
||||
echo 'Invalid selection, quitting.'
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
22
legacy/bin/bootstrap/bootstrap_el.sh
Executable file
22
legacy/bin/bootstrap/bootstrap_el.sh
Executable file
|
|
@ -0,0 +1,22 @@
|
|||
#!/bin/bash
|
||||
|
||||
if [[ $1 == 'now' ]]; then
|
||||
# Install dot's dependencies
|
||||
sudo yum install -y centos-release-scl-rh.noarch
|
||||
sudo yum install rh-ruby26 rh-ruby26-ruby-devel rh-ruby26-rubygem-bundler rh-ruby26-rubygem-rake cmake gcc
|
||||
|
||||
# Make dot usable
|
||||
cd ~/.dotfiles
|
||||
cat bin/sclbundle|sudo tee /usr/local/bin/dotbundle > /dev/null
|
||||
sudo chmod a+x /usr/local/bin/dotbundle
|
||||
cat bin/sclruby|sudo tee /usr/local/bin/dotruby > /dev/null
|
||||
sudo chmod a+x /usr/local/bin/dotruby
|
||||
/usr/local/bin/dotbundle install
|
||||
|
||||
# Install Puppet modules
|
||||
/usr/local/bin/dotbundle exec rake dots:run_r10k
|
||||
|
||||
# Display tasks that can be run
|
||||
echo 'These are the task that can now be executed:'
|
||||
/usr/local/bin/dotbundle exec rake -T |grep --color=never 'rake dots'
|
||||
fi
|
||||
21
legacy/bin/bootstrap/bootstrap_mac.sh
Executable file
21
legacy/bin/bootstrap/bootstrap_mac.sh
Executable file
|
|
@ -0,0 +1,21 @@
|
|||
#!/bin/bash
|
||||
|
||||
if [[ $1 == 'now' ]]; then
|
||||
# Install Homebrew
|
||||
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
|
||||
|
||||
# Install dot's dependencies
|
||||
/usr/local/bin/brew install ruby@2.7 cmake pkg-config
|
||||
/usr/local/bin/gem install --no-ri --no-rdoc bundler
|
||||
|
||||
# Make dot usable
|
||||
cd ~/.dotfiles
|
||||
/usr/local/bin/bundle install
|
||||
|
||||
# Install Puppet modules
|
||||
/usr/local/bin/bundle exec rake dots:run_r10k
|
||||
|
||||
# Display tasks that can be run
|
||||
echo 'These are the task that can now be executed:'
|
||||
/usr/local/bin/bundle exec rake -T |grep --color=never 'rake dots'
|
||||
fi
|
||||
21
legacy/bin/bootstrap/bootstrap_mint.sh
Executable file
21
legacy/bin/bootstrap/bootstrap_mint.sh
Executable file
|
|
@ -0,0 +1,21 @@
|
|||
#!/bin/bash
|
||||
|
||||
if [[ $1 == 'now' ]]; then
|
||||
# Install dot's dependencies
|
||||
sudo apt-add-repository ppa:brightbox/ruby-ng
|
||||
sudo apt-get update
|
||||
sudo apt-get install ruby2.4 ruby2.4-dev ruby-switch cmake build-essential
|
||||
sudo ruby-switch --set ruby2.4
|
||||
sudo gem install --no-ri --no-rdoc bundler
|
||||
|
||||
# Make dot usable
|
||||
cd ~/.dotfiles
|
||||
bundle install
|
||||
|
||||
# Install Puppet modules
|
||||
bundle exec rake dots:run_r10k
|
||||
|
||||
# Display tasks that can be run
|
||||
echo 'These are the task that can now be executed:'
|
||||
bundle exec rake -T |grep --color=never 'rake dots'
|
||||
fi
|
||||
1
legacy/bin/casks.sh
Executable file
1
legacy/bin/casks.sh
Executable file
|
|
@ -0,0 +1 @@
|
|||
brew install --cask adobe-acrobat-reader boinc virtualbox virtualbox-extension-pack vagrant
|
||||
82
legacy/bin/dots.rb
Executable file
82
legacy/bin/dots.rb
Executable file
|
|
@ -0,0 +1,82 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'open3'
|
||||
require 'os'
|
||||
require 'tty-command'
|
||||
require 'tty-file'
|
||||
require 'tty-prompt'
|
||||
require_relative 'dotutils'
|
||||
|
||||
cmd = TTY::Command.new
|
||||
@prompt = TTY::Prompt.new(help_color: :magenta)
|
||||
|
||||
@home = File.expand_path('~')
|
||||
@dotroot = File.dirname(File.dirname(File.expand_path($PROGRAM_NAME)))
|
||||
@excludes = %w[linux mac nix ssh]
|
||||
@files_copy = Dir.glob("#{@dotroot}/copy/*")
|
||||
@files_link = Dir.glob("#{@dotroot}/link/*")
|
||||
@ssh_link = Dir.glob("#{@dotroot}/link/ssh/*")
|
||||
|
||||
if OS.posix?
|
||||
@files_copy.concat Dir.glob("#{@dotroot}/copy/nix/*")
|
||||
@files_link.concat Dir.glob("#{@dotroot}/link/nix/*")
|
||||
end
|
||||
|
||||
if OS.windows?
|
||||
puts 'It seems you are on Windows'
|
||||
|
||||
elsif OS.mac?
|
||||
mac_vers
|
||||
|
||||
@files_copy.concat Dir.glob("#{@dotroot}/copy/mac/*")
|
||||
@files_link.concat Dir.glob("#{@dotroot}/link/mac/*")
|
||||
|
||||
elsif OS.linux?
|
||||
@files_link.concat Dir.glob("#{@dotroot}/link/linux/*")
|
||||
|
||||
else
|
||||
abort("I'm not sure what to do with this OS...") unless OS.posix?
|
||||
end
|
||||
|
||||
task = @prompt.select('What would you like to do?', %w[copy link install exit])
|
||||
case task
|
||||
when 'copy'
|
||||
if @prompt.yes?('Are you sure you want to copy these files?')
|
||||
@files_copy.each do |file|
|
||||
unless @excludes.include?(File.basename(file))
|
||||
puts "Copying #{file} to #{@home}/.#{File.basename(file)}"
|
||||
copy_file(file, "#{@home}/.#{File.basename(file)}")
|
||||
end
|
||||
end
|
||||
else
|
||||
puts 'not copying'
|
||||
end
|
||||
|
||||
when 'link'
|
||||
if @prompt.yes?('Are you sure you want to link your dot files?')
|
||||
@files_link.each do |file|
|
||||
unless @excludes.include?(File.basename(file))
|
||||
# puts "Linking #{@home}/.#{File.basename(file)} to #{file}"
|
||||
link_file(file, "#{@home}/.#{File.basename(file)}")
|
||||
end
|
||||
end
|
||||
|
||||
# rubocop:disable Style/NumericLiteralPrefix
|
||||
Dir.mkdir("#{@home}/.ssh", 0700) unless File.directory?("#{@home}/.ssh")
|
||||
# rubocop:enable Style/NumericLiteralPrefix
|
||||
@ssh_link.each do |file|
|
||||
link_file(file, "#{@home}/.ssh/#{File.basename(file)}")
|
||||
end
|
||||
else
|
||||
puts 'not linking'
|
||||
end
|
||||
|
||||
when 'install'
|
||||
if @prompt.yes?('Are you sure you want to install your base packages?')
|
||||
cmd.run('bundle exec rake dots:run_puppet')
|
||||
cmd.run('bundle exec rake dots:vim_plugins')
|
||||
end
|
||||
|
||||
when 'exit'
|
||||
exit
|
||||
end # end of the case statement
|
||||
76
legacy/bin/dotutils.rb
Normal file
76
legacy/bin/dotutils.rb
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
def existing_symlink(source, destination)
|
||||
return if File.readlink(destination).eql?(source)
|
||||
|
||||
# rubocop:disable Layout/LineLength
|
||||
if @prompt.yes?("#{destination} currently points to #{File.readlink(destination)}, do you want point it at #{source}?")
|
||||
File.unlink(destination)
|
||||
puts "Linking #{destination} to #{source}"
|
||||
File.symlink(source, destination)
|
||||
puts 'link replaced'
|
||||
else
|
||||
puts "#{destination} is unchanged"
|
||||
end
|
||||
# rubocop:enable Layout/LineLength
|
||||
end
|
||||
|
||||
# rubocop:disable Metrics/MethodLength
|
||||
def rename_file(source, destination, action)
|
||||
puts "#{destination} exists, renaming to #{destination}.predots"
|
||||
File.rename(destination, "#{destination}.predots")
|
||||
case action
|
||||
when 'link'
|
||||
puts "Linking #{destination} to #{source}"
|
||||
File.symlink(source, destination)
|
||||
when 'copy'
|
||||
puts "Copying #{destination} to #{source}"
|
||||
FileUtils.cp_r(source, destination)
|
||||
else
|
||||
raise ArgumentError, "'#{action}' is not a valid action", backtrace
|
||||
end
|
||||
end
|
||||
# rubocop:enable Metrics/MethodLength
|
||||
|
||||
def copy_file(source, destination)
|
||||
if File.exist?(destination)
|
||||
if @prompt.yes?("#{destination} exists, do you want to replace it?")
|
||||
rename_file(source, destination, 'copy')
|
||||
else
|
||||
puts "#{destination} is unchanged"
|
||||
end
|
||||
else
|
||||
FileUtils.cp_r(source, destination)
|
||||
end
|
||||
end
|
||||
|
||||
def link_file(source, destination)
|
||||
if File.exist?(destination) && File.symlink?(destination)
|
||||
existing_symlink(source, destination)
|
||||
elsif File.exist?(destination)
|
||||
# this catches anything that is not a symlink
|
||||
rename_file(source, destination, 'link')
|
||||
else
|
||||
puts "Linking #{destination} to #{source}"
|
||||
File.symlink(source, destination)
|
||||
end
|
||||
end
|
||||
|
||||
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
||||
def mac_vers
|
||||
stdout, _stderr, _status = Open3.capture3('sw_vers -productVersion')
|
||||
if Integer(stdout.strip.split('.')[0]) == 10
|
||||
if Integer(stdout.strip.split('.')[1]) >= 12
|
||||
puts "It seems you are on macOS #{stdout.strip}"
|
||||
else
|
||||
puts "It seems you are on OX X #{stdout.strip}"
|
||||
end
|
||||
|
||||
elsif Integer(stdout.strip.split('.')[0]) < 10
|
||||
puts "Wow... you're sure running an old os (#{stdout.strip} to be exact)"
|
||||
else
|
||||
abort("It seems you are on a Mac but I don't know what to do on \
|
||||
v#{stdout.strip}")
|
||||
end
|
||||
end
|
||||
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
|
||||
42
legacy/bin/rake_tasks.rb
Normal file
42
legacy/bin/rake_tasks.rb
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
desc 'Run dots'
|
||||
task :dots do
|
||||
ruby 'bin/dots.rb'
|
||||
end
|
||||
|
||||
# rubocop:disable Metrics/BlockLength
|
||||
namespace 'dots' do
|
||||
cmd = TTY::Command.new
|
||||
|
||||
desc 'Run r10k'
|
||||
task :run_r10k do
|
||||
command = 'bundle exec r10k puppetfile install \
|
||||
--puppetfile ~/.dotfiles/puppet/production/Puppetfile -v'
|
||||
cmd.run(command)
|
||||
end
|
||||
|
||||
desc 'Run Puppet'
|
||||
task :run_puppet do
|
||||
command = 'bundle exec puppet apply \
|
||||
--environmentpath ~/.dotfiles/puppet \
|
||||
~/.dotfiles/puppet/production/manifests/site.pp'
|
||||
cmd.run(command)
|
||||
end
|
||||
|
||||
desc 'Run Puppet (noop)'
|
||||
task :run_puppet_noop do
|
||||
command = 'bundle exec puppet apply \
|
||||
--environmentpath ~/.dotfiles/puppet \
|
||||
~/.dotfiles/puppet/production/manifests/site.pp --noop'
|
||||
cmd.run(command)
|
||||
end
|
||||
|
||||
desc 'Install Vundle Plugins'
|
||||
task :vim_plugins do
|
||||
# running this command from bundler refuses to work
|
||||
command = 'vim +PluginInstall! +qall'
|
||||
puts "Run '#{command}' to get your Vundle plugins installed and/or updated"
|
||||
end
|
||||
end
|
||||
# rubocop:enable Metrics/BlockLength
|
||||
2
legacy/bin/sclbundle
Executable file
2
legacy/bin/sclbundle
Executable file
|
|
@ -0,0 +1,2 @@
|
|||
source /opt/rh/rh-ruby24/enable
|
||||
bundle "$@"
|
||||
2
legacy/bin/sclruby
Executable file
2
legacy/bin/sclruby
Executable file
|
|
@ -0,0 +1,2 @@
|
|||
source /opt/rh/rh-ruby24/enable
|
||||
ruby "$@"
|
||||
26
legacy/bin/shell-setup.sh
Executable file
26
legacy/bin/shell-setup.sh
Executable file
|
|
@ -0,0 +1,26 @@
|
|||
#!/bin/bash
|
||||
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "usage: sudo $0 username"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
user=$1
|
||||
zsh_path='/usr/local/bin/zsh'
|
||||
|
||||
if [ "$(id -u)" != "0" ]; then
|
||||
echo "Editing your shell requires admin rights. Run via 'sudo $0'"
|
||||
exit 1
|
||||
else
|
||||
if [ -f "$zsh_path" ]; then
|
||||
shell_check=$(dscl localhost -read /Local/Default/Users/gene UserShell |grep -c $zsh_path)
|
||||
if [ $shell_check -eq 0 ]; then
|
||||
echo "setting shell via dscl"
|
||||
dscl localhost -change /Local/Default/Users/$user UserShell /bin/bash $zsh_path
|
||||
fi
|
||||
else
|
||||
echo "$zsh_path doesn't exist yet, run Puppet."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue