Home Forums TrueRNG Hardware random number generator RedHat/CentOS install

This topic contains 4 replies, has 2 voices, and was last updated by  neoaeon 3 years, 5 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #539

    neoaeon
    Member

    The instructions for RedHat/CentOS were lacking a bit

    Here’s a script tested on 6, should work on 5

    
    #!/bin/sh
    
    # determine redhat version
    RHELVER=$(rpm -q --whatprovides /etc/redhat-release --queryformat "%{VERSION}\n")
    
    # check for pre-reqs
    if ! rpm -q wget &>/dev/null; then RPMS="${RPMS} wget"; fi
    if ! rpm -q unzip &>/dev/null; then RPMS="${RPMS} unzip"; fi
    if ! rpm -q rng-tools &>/dev/null; then RPMS="${RPMS} rng-tools"; fi
    
    # install pre-reqs
    if [ ! -z ${RPMS} ]; then yum -y install ${RPMS}; fi
    
    ## Install the udev rule
    # Grab the udev rules
    wget -nd http://ubld.it/wp-content/uploads/2014/02/TrueRNG-Linux-udev-rules.zip -O /tmp/TrueRNG-Linux-udev-rules.zip 
    # unzip the rules to /etc/udev/rules.d
    unzip /tmp/TrueRNG-Linux-udev-rules.zip -d /etc/udev/rules.d 
    # remove zip
    rm -fv /tmp/TrueRNG-Linux-udev-rules.zip 
    
    ## reload udev
    # reload udev rules and trigger them
    case ${RHELVER:0:1} in
      5)
        udevcontrol reload_rules
        udevtrigger
        ;;
      6)
        udevadm control --reload-rules 
        udevadm trigger 
        ;;
      *)
        echo "Unknown RHEL Version ${RHELVER}, could not reload udev. try the below:"
        echo "udevcontrol reload_rules; udevtrigger"
        echo "udevadm control --reload-rules; udev trigger"
        ;;
    esac
    
    ## activate rngd
    # add rng-device to rng config
    sed -i~ -e 's/EXTRAOPTIONS=""/EXTRAOPTIONS="--rng-device=\/dev\/TrueRNG"/' /etc/sysconfig/rngd 
    # start rngd
    if ! service rngd status &>/dev/null; then service rngd start; else service rngd restart; fi
    # set rngd to autostart 
    chkconfig rngd on 
    
    #540

    ubld.it
    Keymaster

    Nice script, much appreciated!

    #596

    neoaeon
    Member

    I wanted to give TrueRNG a shot on Fedora 20, so I rebuilt the script to support newer versions.
    Tested on CentOS 6 and Fedora 20.

    Should support CentOS, Red Hat Enterprise Linux, and Fedora. Untested support for Scientific Linux and Oracle Enterprise Linux.

    
    #!/bin/bash
    #
    # Installer for TrueRNG udev rules
    # currently supports CentOS / RHEL and Fedora
    # Alpha Scientific Linux and Oracle Enterprise support
    #
    # Nick Crawford (npc) <nick@null.net>
    #
    # v1 -npc 7 Mar 2014
    # - intial version
    # v2 -npc 28 Mar 2014
    # - move to bash
    # - check for root
    # - case match of fedora, centos and redhat
    #  others untested; scientific (sl) and oracle (oraclelinux enterprise)
    # - strip alpha's from ver instead of print left 1
    # - F18+ (rhel7) no longer has /etc/sysconfig/rngd or /etc/init.d/rngd.
    # - future releases will depreicate service start for systemctl start, moved
    # - functions for chkconfig/systemctl, service/systemctl, udevcontrol/udevadm
    #
    
    # check root
    if [ $UID -ne 0 -a $EUID -ne 0 ]; then echo "ERROR: need to run as root" 1>&2; exit 1; fi
    
    # determine redhat version and derivative type
    eval $(rpm -q --whatprovides /etc/redhat-release --queryformat "RHELTYPE=%{NAME}\nRHELVER=%{VERSION}\n")
    
    # check for pre-reqs
    if ! rpm -q wget &>/dev/null; then RPMS="${RPMS} wget"; fi
    if ! rpm -q unzip &>/dev/null; then RPMS="${RPMS} unzip"; fi
    if ! rpm -q rng-tools &>/dev/null; then RPMS="${RPMS} rng-tools"; fi
    
    # install pre-reqs
    if [ ! -z ${RPMS} ]; then yum -y install ${RPMS}; fi
    
    ## Install the udev rule
    # Grab the udev rules
    wget -nd http://ubld.it/wp-content/uploads/2014/02/TrueRNG-Linux-udev-rules.zip -O /tmp/TrueRNG-Linux-udev-rules.zip 
    # unzip the rules to /etc/udev/rules.d
    unzip /tmp/TrueRNG-Linux-udev-rules.zip -d /etc/udev/rules.d 
    # remove zip
    rm -fv /tmp/TrueRNG-Linux-udev-rules.zip 
    
    ## udev, rehash rules and trigger hot plug events
    # func old udevcontrol
    udev_control() {
      udevcontrol reload_rules
      udevtrigger
    }
    # func new udevadm
    udev_adm() {
      udevadm control --reload-rules 
      udevadm trigger 
    }
    
    ## add rng-device to rng config
    # func old sysconfig
    rngd_sysconfig() {
      sed -i~ -e 's/EXTRAOPTIONS=""/EXTRAOPTIONS="--rng-device=\/dev\/TrueRNG"/' /etc/sysconfig/rngd 
    }
    # func new systemd
    rngd_systemd() {
      cp -p /usr/lib/systemd/system/rngd.service /etc/systemd/system/rngd.service
      sed -i~ -e 's/ExecStart=.*/ExecStart=\/sbin\/rngd -f -o \/dev\/TrueRNG/' /etc/systemd/system/rngd.service
      systemctl daemon-reload
    }
    
    ## start rngd and turn service on
    # func old chkconfig
    rngd_chkconfig() {
      chkconfig rngd on
      if ! service rngd status &>/dev/null; then service rngd start; else service rngd restart; fi
    }
    # func new systemctl
    rngd_systemctl() {
      systemctl enable rngd
      if ! systemctl status rngd &>/dev/null; then systemctl start rngd; else systemctl restart rngd; fi
    }
    
    # Process RHEL type and version, execute functions based on results
    case ${RHELTYPE} in
      redhat-* | centos-* | enterprise-* | oraclelinux-* | sl-*)
        if [ ${RHELVER//[!0-9]/} -le 5 ]; then
          udev_control
          rngd_sysconfig
          rngd_chkconfig
        elif [ ${RHELVER//[!0-9]/} -gt 5 -a ${RHELVER//[!0-9]/} -lt 7 ]; then
          udev_adm
          rngd_sysconfig
          rngd_chkconfig
        elif [ ${RHELVER//[!0-9]/} -ge 7 ]; then
          udev_adm
          rngd_systemd
          rngd_systemctl
        else
          udev_adm
          rngd_systemd
          rngd_systemctl
        fi
      ;;
      fedora*)
        if [ ${RHELVER//[!0-9]/} -le 8 ]; then
          udev_control
          rngd_sysconfig
          rngd_chkconfig
        elif [ ${RHELVER//[!0-9]/} -gt 8 -a ${RHELVER//[!0-9]/} -lt 18 ]; then
          udev_adm
          rngd_sysconfig
          rngd_chkconfig
        elif [ ${RHELVER//[!0-9]/} -ge 18 ]; then
          udev_adm
          rngd_systemd
          rngd_systemctl
        else
          udev_adm
          rngd_systemd
          rngd_systemctl
        fi
      ;;
      *)
        echo "ERROR: Unknown RedHat derivative ${RHELTYPE} ${RHELVER}." 1>&2
        echo "WARNING: Could not install services." 1>&2
        exit 1
      ;;
    esac
    
    • This reply was modified 3 years, 8 months ago by  neoaeon. Reason: extra lf
    #601

    ubld.it
    Keymaster

    Once again I want to thank you for your contributions and making installation easier for other users. We appreciate this behavior. In the future we may update the TrueRNG with more features, if and when we do we, we will be happy to send you an early release for your troubles. Thanks again.

    #760

    neoaeon
    Member

    Reviewer jwoude pointed out an error in v2 on systemd devices. TrueRNG was selected as the output device not the source hwrng device.

    Review #628 by jwoude

    My sincere apologies to anyone affected.

    Simply re-running the install script should fix the error.

    script v3:

    
    #!/bin/bash
    #
    # Installer for TrueRNG udev rules
    # currently supports CentOS / RHEL and Fedora
    # Alpha Scientific Linux and Oracle Enterprise support
    #
    # Nick Crawford (npc) <nick@null.net>
    #
    # v1 -npc 7 Mar 2014
    # - intial version
    # v2 -npc 28 Mar 2014
    # - move to bash
    # - check for root
    # - case match of fedora, centos and redhat
    #  others untested; scientific (sl) and oracle (oraclelinux enterprise)
    # - strip alpha's from ver instead of print left 1
    # - F18+ (rhel7) no longer has /etc/sysconfig/rngd or /etc/init.d/rngd.
    # - future releases will depreicate service start for systemctl start, moved
    # - functions for chkconfig/systemctl, service/systemctl, udevcontrol/udevadm
    # v3 -npc 23 Jun 2014
    # - update rngd_systemd, fix from jwoude
    #  replace rngd call with proper -r option
    #  review 628 by jwoude:
    #  https://www.tindie.com/products/ubldit/truerng-hardware-random-number-generator/?#tab-product-reviews
    # - update rngd_sysconfig to support update of options via re-run
    #
    
    # check root
    if [ $UID -ne 0 -a $EUID -ne 0 ]; then echo "ERROR: need to run as root" 1>&2; exit 1; fi
    
    # determine redhat version and derivative type
    eval $(rpm -q --whatprovides /etc/redhat-release --queryformat "RHELTYPE=%{NAME}\nRHELVER=%{VERSION}\n")
    
    # check for pre-reqs
    if ! rpm -q wget &>/dev/null; then RPMS="${RPMS} wget"; fi
    if ! rpm -q unzip &>/dev/null; then RPMS="${RPMS} unzip"; fi
    if ! rpm -q rng-tools &>/dev/null; then RPMS="${RPMS} rng-tools"; fi
    
    # install pre-reqs
    if [ ! -z ${RPMS} ]; then yum -y install ${RPMS}; fi
    
    ## Install the udev rule
    # Grab the udev rules
    wget -nd http://ubld.it/wp-content/uploads/2014/02/TrueRNG-Linux-udev-rules.zip -O /tmp/TrueRNG-Linux-udev-rules.zip 
    # unzip the rules to /etc/udev/rules.d
    unzip /tmp/TrueRNG-Linux-udev-rules.zip -d /etc/udev/rules.d 
    # remove zip
    rm -fv /tmp/TrueRNG-Linux-udev-rules.zip 
    
    ## udev, rehash rules and trigger hot plug events
    # func old udevcontrol
    udev_control() {
      udevcontrol reload_rules
      udevtrigger
    }
    # func new udevadm
    udev_adm() {
      udevadm control --reload-rules 
      udevadm trigger 
    }
    
    ## add rng-device to rng config
    # func old sysconfig
    rngd_sysconfig() {
      sed -i~ -e 's/EXTRAOPTIONS=.*/EXTRAOPTIONS="--rng-device=\/dev\/TrueRNG"/' /etc/sysconfig/rngd 
    }
    # func new systemd
    rngd_systemd() {
      cp -p /usr/lib/systemd/system/rngd.service /etc/systemd/system/rngd.service
      sed -i~ -e 's/ExecStart=.*/ExecStart=\/sbin\/rngd -f -r \/dev\/TrueRNG/' /etc/systemd/system/rngd.service
      systemctl daemon-reload
    }
    
    ## start rngd and turn service on
    # func old chkconfig
    rngd_chkconfig() {
      chkconfig rngd on
      if ! service rngd status &>/dev/null; then service rngd start; else service rngd restart; fi
    }
    # func new systemctl
    rngd_systemctl() {
      systemctl enable rngd
      if ! systemctl status rngd &>/dev/null; then systemctl start rngd; else systemctl restart rngd; fi
    }
    
    # Process RHEL type and version, execute functions based on results
    case ${RHELTYPE} in
      redhat-* | centos-* | enterprise-* | oraclelinux-* | sl-*)
        if [ ${RHELVER//[!0-9]/} -le 5 ]; then
          udev_control
          rngd_sysconfig
          rngd_chkconfig
        elif [ ${RHELVER//[!0-9]/} -gt 5 -a ${RHELVER//[!0-9]/} -lt 7 ]; then
          udev_adm
          rngd_sysconfig
          rngd_chkconfig
        elif [ ${RHELVER//[!0-9]/} -ge 7 ]; then
          udev_adm
          rngd_systemd
          rngd_systemctl
        else
          udev_adm
          rngd_systemd
          rngd_systemctl
        fi
      ;;
      fedora*)
        if [ ${RHELVER//[!0-9]/} -le 8 ]; then
          udev_control
          rngd_sysconfig
          rngd_chkconfig
        elif [ ${RHELVER//[!0-9]/} -gt 8 -a ${RHELVER//[!0-9]/} -lt 18 ]; then
          udev_adm
          rngd_sysconfig
          rngd_chkconfig
        elif [ ${RHELVER//[!0-9]/} -ge 18 ]; then
          udev_adm
          rngd_systemd
          rngd_systemctl
        else
          udev_adm
          rngd_systemd
          rngd_systemctl
        fi
      ;;
      *)
        echo "ERROR: Unknown RedHat derivative ${RHELTYPE} ${RHELVER}." 1>&2
        echo "WARNING: Could not install services." 1>&2
        exit 1
      ;;
    esac
    

    diff:

    *** truerng-install.sh.orig	2014-06-23 17:07:25.152096057 -0400
    --- truerng-install.sh	2014-06-23 17:06:51.345818466 -0400
    ***************
    *** 17,22 ****
    --- 17,28 ----
      # - F18+ (rhel7) no longer has /etc/sysconfig/rngd or /etc/init.d/rngd.
      # - future releases will depreicate service start for systemctl start, moved
      # - functions for chkconfig/systemctl, service/systemctl, udevcontrol/udevadm
    + # v3 -npc 23 Jun 2014
    + # - update rngd_systemd, fix from jwoude
    + #  replace rngd call with proper -r option
    + #  review 628 by jwoude:
    + #  https://www.tindie.com/products/ubldit/truerng-hardware-random-number-generator/?#tab-product-reviews
    + # - update rngd_sysconfig to support update of options via re-run
      #
      
      # check root
    ***************
    *** 56,67 ****
      ## add rng-device to rng config
      # func old sysconfig
      rngd_sysconfig() {
    !   sed -i~ -e 's/EXTRAOPTIONS=""/EXTRAOPTIONS="--rng-device=\/dev\/TrueRNG"/' /etc/sysconfig/rngd 
      }
      # func new systemd
      rngd_systemd() {
        cp -p /usr/lib/systemd/system/rngd.service /etc/systemd/system/rngd.service
    !   sed -i~ -e 's/ExecStart=.*/ExecStart=\/sbin\/rngd -f -o \/dev\/TrueRNG/' /etc/systemd/system/rngd.service
        systemctl daemon-reload
      }
      
    --- 62,73 ----
      ## add rng-device to rng config
      # func old sysconfig
      rngd_sysconfig() {
    !   sed -i~ -e 's/EXTRAOPTIONS=.*/EXTRAOPTIONS="--rng-device=\/dev\/TrueRNG"/' /etc/sysconfig/rngd 
      }
      # func new systemd
      rngd_systemd() {
        cp -p /usr/lib/systemd/system/rngd.service /etc/systemd/system/rngd.service
    !   sed -i~ -e 's/ExecStart=.*/ExecStart=\/sbin\/rngd -f -r \/dev\/TrueRNG/' /etc/systemd/system/rngd.service
        systemctl daemon-reload
      }
      
    
    • This reply was modified 3 years, 5 months ago by  neoaeon.
    • This reply was modified 3 years, 5 months ago by  neoaeon. Reason: label script
Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.