[neon/neon/settings/Neon/release] /: remove calamares group fix
Harald Sitter
null at kde.org
Fri Mar 1 23:34:50 GMT 2024
Git commit de3e662cf82b64d5d7dea2412fb404b5c273a91c by Harald Sitter.
Committed on 01/03/2024 at 23:34.
Pushed by sitter into branch 'Neon/release'.
remove calamares group fix
it has been in place for 6 years, I'll argue it has fixed all that
needed fixing :)
also it awkwardly fails on systems that don't need fixing
D +0 -14 debian/neon-settings-2.neon-update-calamares-groups.service
M +0 -1 debian/rules
D +0 -2 test/data/neon-migrate-unstable-groups/var/log/installer/version
D +0 -41 test/neon-migrate-unstable-groups_test.rb
D +0 -97 usr/lib/neon_update/calamares_groups.rb
https://invent.kde.org/neon/neon/settings/-/commit/de3e662cf82b64d5d7dea2412fb404b5c273a91c
diff --git a/debian/neon-settings-2.neon-update-calamares-groups.service b/debian/neon-settings-2.neon-update-calamares-groups.service
deleted file mode 100644
index 408f9e1..0000000
--- a/debian/neon-settings-2.neon-update-calamares-groups.service
+++ /dev/null
@@ -1,14 +0,0 @@
-# SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
-# SPDX-FileCopyrightText: 2018 Harald Sitter <sitter at kde.org>
-
-[Unit]
-Description=Migrate UID 1000 from semi-wrong groups to correct ones.
-ConditionPathExists=!/var/lib/neon/update-calamares-groups
-After=network.target dbus.service
-
-[Service]
-Type=oneshot
-ExecStart=/usr/lib/neon_update/calamares_groups.rb
-
-[Install]
-WantedBy=graphical.target
diff --git a/debian/rules b/debian/rules
index 1fea3b7..78b681e 100755
--- a/debian/rules
+++ b/debian/rules
@@ -36,7 +36,6 @@ override_dh_installsystemd:
# "Legacy" services in debian/ rather than lib/
dh_installsystemd --name=neon-apt-clean.timer
- dh_installsystemd --no-start --name=neon-update-calamares-groups
dh_installsystemd --no-start --name=neon-flathub
dh_installsystemd --no-start --name=neon-packagekit-offline-update-policy
dh_installsystemd --no-start --name=neon-packagekit-online-update-policy
diff --git a/test/data/neon-migrate-unstable-groups/var/log/installer/version b/test/data/neon-migrate-unstable-groups/var/log/installer/version
deleted file mode 100644
index 8a44812..0000000
--- a/test/data/neon-migrate-unstable-groups/var/log/installer/version
+++ /dev/null
@@ -1,2 +0,0 @@
-calamares 2.21.37
-
diff --git a/test/neon-migrate-unstable-groups_test.rb b/test/neon-migrate-unstable-groups_test.rb
deleted file mode 100644
index 983daee..0000000
--- a/test/neon-migrate-unstable-groups_test.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-# SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
-# SPDX-FileCopyrightText: 2018 Harald Sitter <sitter at kde.org>
-
-require_relative 'test_helper'
-require_relative '../usr/lib/neon_update/calamares_groups'
-
-class NeonMigrateUnstableGroups < Minitest::Test
- def setup
- @datadir = File.realpath("#{__dir__}/data/neon-migrate-unstable-groups/")
- @tmpdir = Dir.mktmpdir
- @workdir = Dir.pwd
- Dir.chdir(@tmpdir)
- FileUtils.cp_r("#{@datadir}/.", '.')
- ENV['ROOT'] = @tmpdir
- end
-
- def teardown
- FileUtils.rm_r(@tmpdir)
- ENV.delete('ROOT')
- Dir.chdir(@workdir)
- end
-
- def test_run
- passwd = mock('passwd')
- passwd.expects(:name).returns('xme')
- Etc.expects(:getpwuid).returns(passwd)
- groups = Migrator::ADD_GROUPS.collect { |n| [Etc::Group.new(n, nil, nil, 'xme')] }
- groups += Migrator::REMOVE_GROUPS.collect { |n| [Etc::Group.new(n, nil, nil, 'xme')] }
- Etc.expects(:group).multiple_yields(*groups)
- Migrator::ADD_GROUPS.each do |g|
- Object.any_instance.expects(:system).with('adduser', 'xme', g).returns(true)
- end
- Migrator::REMOVE_GROUPS.each do |g|
- Object.any_instance.expects(:system).with('deluser', 'xme', g).returns(true)
- end
-
- Migrator.new.run
-
- assert File.exist?("#{@tmpdir}/var/lib/neon/update-calamares-groups")
- end
-end
diff --git a/usr/lib/neon_update/calamares_groups.rb b/usr/lib/neon_update/calamares_groups.rb
deleted file mode 100755
index d43efe8..0000000
--- a/usr/lib/neon_update/calamares_groups.rb
+++ /dev/null
@@ -1,97 +0,0 @@
-#!/usr/bin/env ruby
-# SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
-# SPDX-FileCopyrightText: 2018 Harald Sitter <sitter at kde.org>
-# frozen_string_literal: true
-
-require 'etc'
-require 'fileutils'
-
-# Helper class to edit group memberships.
-class Group
- def initialize(name)
- @name = name
- end
-
- def add(user)
- return if system('adduser', user, @name)
-
- raise "Failed to add #{user} to #{@name}"
- end
-
- def remove(user)
- return if system('deluser', user, @name)
-
- raise "Failed to drop #{user} from #{@name}"
- end
-end
-
-# Calamares for a whole while created users with wrong groups.
-# To mitigate this we automatically mangle UID 1000 to be in certain groups
-# and remove it from certain groups.
-class Migrator
- ADD_GROUPS = %w[cdrom dip plugdev].freeze
- REMOVE_GROUPS = %w[lp video network storage audio].freeze
-
- def initialize
- @root = ENV['ROOT']
- end
-
- def disable
- FileUtils.mkpath("#{@root}/var/lib/neon/")
- File.write("#{@root}/var/lib/neon/update-calamares-groups", '')
- end
-
- def installed_by_calamares
- # Calamares doesn't create the version marker, ubiquity does.
- # To be future save we'll also check the contents though.
- version_marker = "#{@root}/var/log/installer/version"
- if File.exist?(version_marker)
- data = File.read(version_marker)
- return data.downcase.include?('calamares')
- end
- true
- end
-
- def run
- unless installed_by_calamares
- puts 'System not installed by calamares. Nothing to fix.'
- disable
- return
- end
-
- user = Etc.getpwuid(1000).name
- unless user
- warn 'Could not resolve user 1000 to a name, assuming it does not exist'
- disable
- return
- end
-
- groups = {}
- Etc.group do |group|
- # NB: this will also step over the user's primary group, but we do not
- # want to mangle that in any case. (e.g. user 'me' with group 'me'
- # will not have `'me'.mem.include('me')==true`)
- next unless group.mem.include?(user)
-
- groups[group.name] = Group.new(group.name)
- end
-
- # These are defaults used by ubiquity.
- %w[cdrom dip plugdev].each do |name|
- next unless groups.include?(name)
-
- groups[name].add(user)
- end
-
- # These are not.
- %w[lp video network storage audio].each do |name|
- next unless groups.include?(name)
-
- groups[name].remove(user)
- end
-
- disable
- end
-end
-
-Migrator.new.run if $PROGRAM_NAME == __FILE__
More information about the Neon-commits
mailing list