Sha256: bfc762fe40546e8300f7303273a6a814a07e61db367e5dc11bc19bbf3872671c

Contents?: true

Size: 1.56 KB

Versions: 3

Compression:

Stored size: 1.56 KB

Contents

module Getch
  module FileSystem
    module Clean
      def self.clean_hdd(disk)
        return if ! disk
        raise ArgumentError, "Disk #{disk} is no found." if ! File.exist? "/dev/#{disk}"
        puts
        print "Cleaning data on #{disk}, can be long, avoid this on Flash Memory (SSD,USB,...) ? [y,N] "
        case gets.chomp
        when /^y|^Y/
          bloc=`blockdev --getbsz /dev/#{disk}`.chomp
          Helpers::sys("dd if=/dev/urandom of=/dev/#{disk} bs=#{bloc} status=progress")
        else
          return
        end
      end

      def self.clean_struct(disk)
        return if ! disk
        raise ArgumentError, "Disk #{disk} is no found." if ! File.exist? "/dev/#{disk}"
        Helpers::sys("sgdisk -Z /dev/#{disk}")
        Helpers::sys("wipefs -a /dev/#{disk}")
      end

      def self.hdd(*disks)
        disks.each { |d| clean_hdd(d) }
      end
      # See https://wiki.archlinux.org/index.php/Solid_state_drive/Memory_cell_clearing
      # for SSD
      def self.sdd
      end

      def self.struct(*disks)
        disks.each { |d| clean_struct(d) }
      end

      def self.old_vg(disk, vg)
        oldvg = `vgdisplay | grep #{vg}`.chomp
        Helpers::sys("vgremove -f #{vg}") if oldvg != ''
        Helpers::sys("pvremove -f #{disk}") if oldvg != '' and File.exist? disk
      end

      def self.old_zpool
        oldzpool = `zpool status | grep pool:`.gsub(/pool: /, '').delete(' ').split("\n")
        if oldzpool[0] != "" and $?.success?
          oldzpool.each { |p| Helpers::sys("zpool destroy #{p}") if p }
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
getch-0.1.3 lib/getch/filesystem/clean.rb
getch-0.1.2 lib/getch/filesystem/clean.rb
getch-0.1.1 lib/getch/filesystem/clean.rb