Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 42 additions & 9 deletions bin/yupdate
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ module YUpdate
# version of the script
class Version
MAJOR = 0
MINOR = 1
PATCH = 3
MINOR = 2
PATCH = 0

STRING = "#{MAJOR}.#{MINOR}.#{PATCH}".freeze
end
Expand Down Expand Up @@ -109,10 +109,16 @@ module YUpdate
# a simple /etc/install.inf parser/writer,
# we need to disable the YaST self-update feature to avoid conflicts
class InstallInf
PATH = "/etc/install.inf".freeze

attr_reader :path

def self.exist?(path = PATH)
File.exist?(path)
end

# read the file
def initialize(path = "/etc/install.inf")
def initialize(path = PATH)
@path = path
@values = File.read(path).lines.map(&:chomp)
end
Expand Down Expand Up @@ -476,7 +482,10 @@ module YUpdate

src_dir = File.dirname(rakefile)
Dir.chdir(src_dir) do
`rake install DESTDIR=#{target.shellescape} 2> /dev/null`
redir = ENV["VERBOSE"] == "1" ? "" : " > /dev/null 2>&1"
unless system("rake install DESTDIR=#{target.shellescape} #{redir}")
raise "rake install failed"
end
end
end

Expand Down Expand Up @@ -566,17 +575,20 @@ module YUpdate
end
end

# inst-sys test
class InstSys
# inst-sys or live medium test
class System
# check if the script is running in the inst-sys,
# the script might not work as expected in an installed system
# and using OverlayFS is potentially dangerous
def self.check!
# the inst-sys contains the /.packages.initrd file with a list of packages
return if File.exist?("/.packages.initrd")

# live medium uses overlay FS for the root
return if `mount`.match?(/^\w+ on \/ type overlay/)

# exit immediately if running in an installed system
warn "ERROR: This script can only work in the installation system (inst-sys)!"
warn "ERROR: This script can only work in the installation system (inst-sys) or Live medium!"
exit 1
end
end
Expand All @@ -590,10 +602,10 @@ module YUpdate
when "version"
VersionCommand.new
when "overlay"
InstSys.check!
System.check!
OverlayCommand.new(argv)
when "patch"
InstSys.check!
System.check!
PatchCommand.new(argv)
when "servers"
ServersCommand.new(argv)
Expand Down Expand Up @@ -700,10 +712,29 @@ module YUpdate
g.install_required_gems
end

def run_pre_script(download_dir)
script = File.join(download_dir, ".yupdate.pre")
run_script(script)
end

def run_post_script(download_dir)
script = File.join(download_dir, ".yupdate.post")
run_script(script)
end

def run_script(script)
return unless File.exist?(script)

puts "Running script #{File.basename(script)}..."
raise "Script #{File.basename(script)} failed" unless system(script)
end

def install_tar(downloader)
Dir.mktmpdir do |download_dir|
downloader.extract_to(download_dir)
run_pre_script(download_dir)
install_sources(download_dir)
run_post_script(download_dir)
end
end

Expand All @@ -712,6 +743,8 @@ module YUpdate

# disable the self update in the install.inf file
def disable_self_update
return unless InstallInf.exist?

inf = InstallInf.new
return if inf[SELF_UPDATE_KEY] == "0"

Expand Down
22 changes: 22 additions & 0 deletions doc/yupdate.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,28 @@ state.
AutoYaST second stage cannot be fixed by `yupdate`, you need to build
a DUD, see below.

## Hooks

The source code might contain several callback scripts which are executed
at specific points. The goal is to allow adjusting the target system before
or after installing new files.

- `.yupdate.pre` - This script is executed *before* installing the package (before
running `rake install`). It can prepare the system for installation, install
required packages.
- `.yupdate.post` - This script is executed *after* installing the package (after
running `rake install`). It can activate the changes, restart services.

When a hook script fails then yupdate aborts the update process immediately.

## Environment Variables

The yupdate script uses these environment variables:

- `VERBOSE` - When set to `1` the output of the `rake install` command is
displayed in the terminal. By default it is hidden because the output is too
long and verbose. Use this option for debugging installation problems.

## Alternative

1. For all repos, run `rake osc:build`
Expand Down
7 changes: 7 additions & 0 deletions package/yast2-installation.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Fri Jan 6 12:33:29 UTC 2023 - Ladislav Slezák <lslezak@suse.com>

- yupdate - added suport for patching the D-Installer
(bsc#1206927)
- 4.5.12

-------------------------------------------------------------------
Mon Dec 5 10:13:28 UTC 2022 - Stefan Hundhammer <shundhammer@suse.com>

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-installation.spec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#

Name: yast2-installation
Version: 4.5.11
Version: 4.5.12
Release: 0
Summary: YaST2 - Installation Parts
License: GPL-2.0-only
Expand Down
20 changes: 18 additions & 2 deletions test/yupdate/inst_sys_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
require_relative "../test_helper"
require_yupdate

describe YUpdate::InstSys do
describe YUpdate::System do
let(:file) { "/.packages.initrd" }

before do
allow(File).to receive(:exist?).with(file).and_return(false)
allow(described_class).to receive(:`).with("mount").and_return("")
end

describe ".check!" do
context "when running in an inst-sys" do
before do
Expand All @@ -18,9 +23,20 @@
end
end

context "when running on a live medium" do
before do
expect(described_class).to receive(:`).with("mount")
.and_return("LiveOS_rootfs on / type overlay (rw,relatime)")
end

it "does not exit" do
expect(described_class).to_not receive(:exit)
described_class.check!
end
end

context "when running in a normal system" do
before do
expect(File).to receive(:exist?).with(file).and_return(false)
allow(described_class).to receive(:exit).with(1)
end

Expand Down