Bash Scripts

Setting up network configuration. By Creating some essential network files.

echo "Zirconium" > /etc/hostname
cat > /etc/systemd/network/10-ethernet-dhcp.network << "EOF"
[Match]
Name=enp*

[Network]
DHCP=ipv4

[DHCPv4]
UseDomains=true
EOF
[Note]

Note

To enable the network service, issue:systemctl enable systemd-networkd

cat > /etc/hosts << "EOF"
# Begin /etc/hosts

# Localhost (IPv4 and IPv6)
127.0.0.1   localhost
127.0.1.1   <hostname>

::1         localhost ip6-localhost ip6-loopback
ff02::1     ip6-allnodes
ff02::2     ip6-allrouters

# End /etc/hosts
EOF

To create a simple resolv.conf, issue:

cat > /etc/resolv.conf << "EOF"
# Begin /etc/resolv.conf

domain localdomain
nameserver 8.8.8.8
nameserver 8.8.4.4

search localdomain

# End /etc/resolv.conf
EOF
[Note]

Note

Or you can issue: systemctl enable systemd-resolved. To use systemd's own resolver.

The normal behavior for systemd is to clear the screen at the end of the boot sequence. If desired, this behavior may be changed by running the following command:

mkdir -pv /etc/systemd/system/getty@tty1.service.d/
cat > /etc/systemd/system/getty@tty1.service.d/noclear.conf << "EOF"
[Service]
TTYVTDisallocate=no
EOF

Create the /etc/adjtime file with the following contents if your hardware clock is set to local time:

cat > /etc/adjtime << "EOF"
0.0 0 0.0
0
LOCAL
EOF

Which configures the virtual console font and console keymap.

cat > /etc/vconsole.conf << "EOF"
KEYMAP=us
FONT=LatArCyrHeb-16
#FONT=LatGrkCyr-8x16
#FONT=Lat2-Terminus16
EOF

Testing Locale Setup

LC_ALL=en_US.UTF-8 locale language
LC_ALL=en_US.UTF-8 locale charmap
LC_ALL=en_US.UTF-8 locale int_curr_symbol
LC_ALL=en_US.UTF-8 locale int_prefix
cat > /etc/locale.conf << "EOF"
LANG=en_US.UTF-8
EOF

Setting Up System Profile Files, issue:

mkdir -pv /etc/profile.d

cat > /etc/profile << "EOF"
# Begin /etc/profile

# Source the /etc/profile.d/scripts
for script in /etc/profile.d/*.sh ; do
    if [ -r $script ] ; then
        . $script
    fi
done

unset script

# Set up some environment variables.
export HISTSIZE=1000
export HISTIGNORE="&:[bf]g:exit"

# Set some defaults for graphical systems
export XDG_DATA_DIRS=${XDG_DATA_DIRS:-/usr/share}
export XDG_CONFIG_DIRS=${XDG_CONFIG_DIRS:-/etc/xdg}
export XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR:-/tmp/xdg-$USER}

# End /etc/profile
EOF

Below is a generic global inputrc along with comments to explain what the various options do. Note that comments cannot be on the same line as commands. Create the file using the following command:

cat > /etc/inputrc << "EOF"
# Begin /etc/inputrc

# Allow the command prompt to wrap to the next line
set horizontal-scroll-mode Off

# Enable 8-bit input
set meta-flag On
set input-meta On

# Turns off 8th bit stripping
set convert-meta Off

# Keep the 8th bit for display
set output-meta On

# none, visible or audible
set bell-style none

# All of the following map the escape sequence of the value
# contained in the 1st argument to the readline specific functions
"\eOd": backward-word
"\eOc": forward-word

# for linux console
"\e[1~": beginning-of-line
"\e[4~": end-of-line
"\e[5~": beginning-of-history
"\e[6~": end-of-history
"\e[3~": delete-char
"\e[2~": quoted-insert

# for xterm
"\eOH": beginning-of-line
"\eOF": end-of-line

# for Konsole
"\e[H": beginning-of-line
"\e[F": end-of-line

# End /etc/inputrc
EOF

It is a requirement for applications such as GDM which does not populate the face browser if it can't find /etc/shells, or FTP daemons which traditionally disallow access to users with shells not included in this file.

cat > /etc/shells << "EOF"
# Begin /etc/shells

/bin/sh
/bin/bash

# End /etc/shells
EOF

This script sets up the default inputrc configuration file. If the user does not have individual settings, it uses the global file.

cat > /etc/profile.d/readline.sh << "EOF"
# Set up the INPUTRC environment variable.
if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ] ; then
        INPUTRC=/etc/inputrc
fi
export INPUTRC
EOF

Here the default group write permissions are turned off for system users and when the user name and group name are not the same.

cat > /etc/profile.d/umask.sh << "EOF"
# By default, the umask should be set.
if [ "$(id -gn)" = "$(id -un)" -a $EUID -gt 99 ] ; then
  umask 002
else
  umask 022
fi
EOF

This script sets an environment variable necessary for native language support.

cat > /etc/profile.d/i18n.sh << "EOF"
# Begin of /etc/profile.d/i18n.sh

for i in $(locale); do
  unset ${i%=*}
done

if [[ "$TERM" = linux ]]; then
    export LANG=C.UTF-8
else
    source /etc/locale.conf

    for i in $(locale); do
        key=${i%=*}
        if [[ -v $key ]]; then
            export $key
        fi
    done
fi

# End of /etc/profile.d/i18n.sh
EOF

Here is a base /etc/bashrc. Comments in the file should explain everything you need.

cat > /etc/bashrc << "EOF"
# Begin /etc/bashrc

alias ls='ls --color=auto'
alias ll='ls -l '
alias grep='grep --color=auto'
alias EXEC='chmod -v +x '

mcd() {
    mkdir -v "$1"
    cd "$1"
}

export -f mcd

NORMAL="\[\e[0m\]"
RED="\[\e[1;31m\]"
GREEN="\[\e[1;32m\]"
if [[ $EUID == 0 ]] ; then
  PS1="$RED($?)\u [ $NORMAL\w$RED ]# $NORMAL"
else
  PS1="$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL"
fi

unset RED GREEN NORMAL
# GnuPG wants this or it'll fail with pinentry-curses under some
# circumstances (for example signing a Git commit)
#tty -s && export GPG_TTY=$(tty)

# End /etc/bashrc
EOF

If you want to use the dircolors capability, then run the following command.

cat > /etc/profile.d/dircolors.sh << "EOF"
# Setup for /bin/ls and /bin/grep to support color, the alias is in /etc/bashrc.
if [ -f "/etc/dircolors" ] ; then
        eval $(dircolors -b /etc/dircolors)
fi

if [ -f "$HOME/.dircolors" ] ; then
        eval $(dircolors -b $HOME/.dircolors)
fi
EOF

dircolors -p > /etc/dircolors

To setup the /etc/skel/ home directories for regular users and for the root user, Issue:

mkdir -pv /etc/skel
cat > /etc/skel/.bash_profile << "EOF"
# Begin /etc/skel/.bash_profile

if [ -f "$HOME/.bashrc" ] ; then
    source $HOME/.bashrc
fi

if [ -d "$HOME/bin" ] ; then
    pathprepend $HOME/bin
fi

# End /etc/skel/.bash_profile
EOF
cp -v /etc/skel/.bash_profile ~/.bash_profile

cat > /etc/skel/.profile << "EOF"
# Begin /etc/skel/.profile
# Personal environment variables and startup programs.

if [ -d "$HOME/bin" ] ; then
    pathprepend $HOME/bin
fi

#    Set up user specific i18n variables
#   export LANG=<ll>_<CC>.<charmap><@modifiers>

# End /etc/skel/.profile
EOF

cp -v /etc/skel/.profile ~/.profile

cat > /etc/skel/.bashrc << "EOF"
# Begin /etc/skel/.bashrc

if [ -f "/etc/bashrc" ] ; then
  source /etc/bashrc
fi

#    Set up user specific i18n variables
#   export LANG=<ll>_<CC>.<charmap><@modifiers>

# End /etc/skel/.bashrc
EOF
cp -v /etc/skel/.bashrc ~/.bashrc

cat > /etc/skel/.bash_logout << "EOF"
# Begin /etc/skel/.bash_logout

printf "\n\n Good Bye \n\n"

# End /etc/skel/.bash_logout
EOF

cp -v /etc/skel/.bash_logout ~/.bash_logout