#!/usr/bin/env ruby Dir.glob("../scripts/*.rb").each { |file| require file } require 'fileutils' require 'rbconfig' class SolaraSetup def initialize @aliases_file = FilePath.solara_aliases_sh @setup_dir = File.join(ENV['HOME'], '.solara') @unix_setup_file = File.join(@setup_dir, 'setup.sh') @windows_setup_file = File.join(@setup_dir, 'setup.bat') end def run create_setup_directory create_unix_setup_script create_windows_setup_script case RbConfig::CONFIG['host_os'] when /mswin|mingw|cygwin/ setup_windows when /darwin|mac os|linux/ setup_unix else Solara.logger.fatal("Unsupported operating system. Please set up manually.") end end private def create_setup_directory FileUtils.mkdir_p(@setup_dir) end def create_unix_setup_script File.open(@unix_setup_file, 'w') do |file| file.puts <<~SCRIPT #!/bin/bash source "#{@aliases_file}" SCRIPT end FileUtils.chmod(0755, @unix_setup_file) end def create_windows_setup_script File.open(@windows_setup_file, 'w') do |file| file.puts <<~SCRIPT @echo off call "#{@aliases_file.gsub('/', '\\')}" SCRIPT end end def setup_unix shell_config_file = determine_shell_config_file setup_line = "source #{@unix_setup_file}" if File.exist?(shell_config_file) content = File.read(shell_config_file) unless content.include?(setup_line) File.open(shell_config_file, 'a') do |file| file.puts "\n# Solara Setup" file.puts setup_line end Solara.logger.debug("Configuration added to #{shell_config_file}") Solara.logger.success("Please restart your terminal or run 'source #{shell_config_file}' to apply changes.") else Solara.logger.debug("Configuration already exists in #{shell_config_file}") end else Solara.logger.failure("Shell configuration file not found. Please add the following line manually to your shell configuration:") Solara.logger.failure(setup_line) end end def setup_windows require 'win32/registry' begin Win32::Registry::HKEY_CURRENT_USER.create('Software\Microsoft\Command Processor') do |reg| reg['AutoRun', Win32::Registry::REG_EXPAND_SZ] = @windows_setup_file end Solara.logger.success("Windows AutoRun registry key set up successfully.") pSolara.logger.warn("Please restart your Command Prompt to apply changes.") rescue Win32::Registry::Error => e Solara.logger.failure("Failed to set up Windows registry: #{e.message}") Solara.logger.failure("Please add the following file path to your AutoRun registry key manually:") Solara.logger.failure(@windows_setup_file) end end def determine_shell_config_file if ENV['SHELL'] =~ /zsh/ File.expand_path('~/.zshrc') elsif ENV['SHELL'] =~ /bash/ File.expand_path('~/.bashrc') else File.expand_path('~/.profile') end end end