#!/bin/bash
# - bof - #



<<'comment'

bash <(curl -s https://www.education.isdevelopment.us/Arch.Ins/Software.Ins/BashFiles.Ins/uZRam.sh)


# - Method   # 1 - #
cd ~/; rm -rf ~/uZram.sh; nvim ~/uZram.sh;
copy & paste this content
chmod +x ~/uZram.sh; ~/./uZram.sh;



# - Configured - #

# -  - #
# - Vim commands - #
https://vim.rtorr.com/

rm -rf ~/.bashrc;
nvim ~/.bashrc;

rm -rf ~/.zshrc;
nvim ~/.zshrc;

ssh-keygen -R 192.168.1.1

# - On client - #
cd ~/.ssh;
ssh-keygen -t rsa;

cat ~/.ssh/id_rsa.pub;

# - On server - #
nvim ~/.ssh/authorized_keys;

sudo apt install curl git htop inxi net-tools ntp neovim tree -y;
sudo pacman -S curl git htop inxi net-tools ntp neovim tree --noconfirm --needed;


# -  - #
# - Remove swap file - #
sudo swapoff -v /swap.img;
sudo rm -rf /swap.img;
free -h;

comment



# -  - #
# - create_uZRam_ - #
function create_uZRam_(){
  local zRamCnf_=/usr/bin/init-zram-swapping \
        tzRamCnf_=~/tzRamCnf_.tmp;
  echo -e "\n\nInstall zram...";

  sudo apt install util-linux zram-config -y;

  if [ -f "$zRamCnf_" ]; then
    echo "$zRamCnf_ already exists..."
  else
    touch $tzRamCnf_;
    echo "#\!/bin/sh" > $tzRamCnf_;
    echo "modprobe zram\n" >> $tzRamCnf_;
    echo "# Calculate memory to use for zram (1/2 of ram)" >> $tzRamCnf_;
    echo "totalmem=\`LC_ALL=C free | grep -e \"^Mem:\" | sed -e 's/^Mem: *//' -e 's/  *.*//'\`" >> $tzRamCnf_;
    echo "mem=\$((totalmem / 2 * 1024))\n" >> $tzRamCnf_;
    echo "# initialize the devices" >> $tzRamCnf_;
    echo "echo \$mem > /sys/block/zram0/disksize" >> $tzRamCnf_;
    echo "mkswap /dev/zram0" >> $tzRamCnf_;
    echo "swapon -p 5 /dev/zram0" >> $tzRamCnf_;

    sudo mv $tzRamCnf_ $zRamCnf_;

    echo -e "\n\n$zRamCnf_ details...\n";
    cat $zRamCnf_;

  fi;
  echo -e "\nDONE! ZRAM installed successfully...";
  echo -e "Run -> free -h\n";
  echo -e "\n\nThe system will reboot now so changes can take effect...\n";
  sleep 15;

  rm -rf ~/uZram.sh;
  sudo reboot now;
}



clear;
create_uZRam_;



<<'comment'
cd ~/; rm -rf ~/uZram.sh; nvim ~/uZram.sh;
copy & paste this content
chmod +x ~/uZram.sh; ~/./uZram.sh;
comment



# - eof - #