Files
ubicloud/rhizome/common/bin/add_to_fstab
Jeremy Evans e59d71e2f6 Restore Ruby 3.2 syntax to rhizome
Ubuntu 22.04 VmHosts use Ruby 3.0, and Ubunutu 24.04 use Ruby 3.2,
so 3.4 syntax would break either.  This was theoretically an issue
before, but I'm guessing there were no significant syntax changes
between 3.0 and 3.2 that Rubocop's rewriting would break.

This commits a rhizome/.rubocop.yml file that inherits the default
configuration, and overrides TargetRubyVersion.
2025-04-26 08:34:47 +09:00

30 lines
798 B
Ruby
Executable File

#!/bin/env ruby
# frozen_string_literal: true
require "fileutils"
require_relative "../lib/util"
if ARGV.count != 6
fail "Wrong number of arguments. Expected 6, Given #{ARGV.count}"
end
device, dir, type, options, dump, fsck = ARGV
File.open("/etc/fstab", File::RDONLY) do |f|
f.flock(File::LOCK_EX)
content = f.read
rows = content.split("\n").reject { _1.start_with?("#") }
matches = rows.select { _1.match(/\A#{device}\s|\s#{dir}\s/) }
if matches.count == 0
content += "\n#{device} #{dir} #{type} #{options} #{dump} #{fsck}"
safe_write_to_file("/etc/fstab", content)
break
end
if matches.count > 1 || matches.first !~ /\A#{device}\s#{dir}\s#{type}\s#{options}\s#{dump}\s#{fsck}\z/
fail "device path and/or mount point already exist in /etc/fstab"
end
end