Files
chromebrew/packages/crew_profile_base.rb
Satadru Pramanik, DO, MPH, MEng 66ca77930b Add libc version and chromeos milestone to container bash prompts (#10335)
* Use agree_to_remove in ruby_pry.rb.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Add cmake options for build_relative_dir

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Adjust cmake buildsystems.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Alphabetize properties in buildsystems/python.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Add updated crew_profile_base.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Add missing filelists, add glibc fallback to gcc packages.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Add milestone to container git prompt.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Use more heredocs for the git commands.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Adjust git postinstall.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Add binaries.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Adjust unit test to do build test right after crew upgrade.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* lint

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Suggested changes.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

---------

Signed-off-by: Satadru Pramanik <satadru@gmail.com>
2024-08-22 21:26:03 -05:00

96 lines
3.2 KiB
Ruby

require 'package'
class Crew_profile_base < Package
description 'Crew-profile-base sets up Chromebrew\'s environment capabilities.'
homepage 'https://github.com/chromebrew/crew-profile-base'
version '0.0.22'
license 'GPL-3+'
compatibility 'all'
source_url "https://github.com/chromebrew/crew-profile-base/archive/refs/tags/#{version}.tar.gz"
source_sha256 'e3a1c2d8b4c532f46e18e0feccc10e51e8e693e1d996099a6d349a03370eac00'
no_compile_needed
print_source_bashrc
def self.install
FileUtils.mkdir_p "#{CREW_DEST_PREFIX}/etc/"
FileUtils.mkdir_p "#{CREW_DEST_PREFIX}/etc/env.d"
FileUtils.mkdir_p "#{CREW_DEST_PREFIX}/etc/profile.d"
# Don't overwrite custom changes
%w[01-locale 02-editor 03-pager 99-custom].each do |custom_files|
FileUtils.rm "./src/env.d/#{custom_files}" if File.exist?("#{CREW_PREFIX}/etc/env.d/#{custom_files}")
end
FileUtils.cp_r Dir['./src/*'], "#{CREW_DEST_PREFIX}/etc/"
end
def self.postinstall
# Write our rc files
crew_rc_source_line = "source #{CREW_PREFIX}/etc/profile"
crew_rcfile = <<~CREW_PROFILE_EOF
# DO NOT DELETE THIS LINE
# See #{CREW_PREFIX}/etc/profile for further details
#{crew_rc_source_line}
# Put your stuff under this comment
CREW_PROFILE_EOF
# append our #{crew_rcfile} to shell rc files (if exist)
['.bashrc', '.zshrc'].each do |rc|
rc_path = File.join(HOME, rc)
FileUtils.touch rc_path
# next unless File.exist?(rc_path)
rc_file = File.readlines(rc_path, chomp: true)
# remove duplicated `source` lines (if any)
if rc_file.count(crew_rc_source_line) > 1
puts "Removing duplicated `source` lines in #{rc_path}...".yellow
first_source_line_index = rc_file.find_index(crew_rc_source_line)
# delete all `source` lines
rc_file.delete(crew_rc_source_line)
# re-add the first `source` line
rc_file.insert(first_source_line_index, crew_rc_source_line)
end
# append our rc string to the beginning of the rc file (if not exist)
if rc_file.none? { |line| line == "source #{CREW_PREFIX}/etc/profile" }
puts "Appending `#{crew_rc_source_line}` to the beginning of #{rc_path}...".yellow
rc_file.unshift(crew_rcfile.lines(chomp: true))
end
# save changes
File.write rc_path, rc_file.join("\n")
end
puts 'Choose your default pager:'.yellow
@pager_options = [
{ value: 'most', description: 'Most Pager' },
{ value: 'more', description: 'More Pager' },
{ value: 'less', description: 'Less Pager' }
]
@pager_default = Selector.new(@pager_options).show_prompt
Dir.chdir CREW_DEST_DIR do
File.write 'pagerenv', <<~PAGER_ENV_EOF
# The user's preferred pager is set here by the crew_profile_base
# postinstall.
# PAGER from container PAGER variable is passed through into the
# CONTAINER_PAGER variable.
if [ -z "$CONTAINER_PAGER" ]; then
PAGER="#{@pager_default}"
else
PAGER="$CONTAINER_PAGER"
fi
PAGER_ENV_EOF
FileUtils.install 'pagerenv', "#{CREW_PREFIX}/etc/env.d/03-pager", mode: 0o644
end
puts "The default PAGER has been set to #{@pager_default}.".lightblue
end
end