All posts by admin

Install Cockpit on CentOS 7/8

First, you need the might EPEL Release repo:

yum install epel-release
yum install cockpit

Then, you need to enable Cockpit with the systemctl

systemctl start cockpit
​systemctl enable cockpit.socket

Then add Cockpit to the firewall exceptions

sudo firewall-cmd --add-service=cockpit
​sudo firewall-cmd --add-service=cockpit --permanent
​sudo firewall-cmd --reload

Cockpit is located at port 9090

 

How To Install macOS Virtual Machine on Linux/Arch/Manjaro – Catalina, Mojave, or High Sierra! XCode working!

Linux users on Arch or Manjaro attempting to install macOS/OSX in VMWARE, or QEMU/KVM, will greatly benefit from this tutorial.

This tutorial is great for Linux users who want to use XCode 10 or 11 on Linux without Dual Booting!

How to Install macOS VM on Linux

Linux System Requirements:

  • an aur package manager, such as yay.
  • about 20-40gb of free space
  • Intel VT-x / AMD SVM: in your BIOS turn on “hardware virtualization” or similar

Suggestions:

  • highly recommend using an SSD
  • where you download and run the scripts will determine which drive the OSX image will be created on

If you don’t have yay (Arch User Repository package manager):

git clone https://aur.archlinux.org/yay.git
cd yay
makepkg -si

Next, we will need git & python as we will need to clone some repositories.

sudo pacman -R git python

You will need a MAC iso file, which is around 6GB downloaded.
Make sure you download the iso in the disk or device that you are going to run the VM from.
A great way to download OSX ISO files is using gibMacOS:

git clone https://github.com/corpnewt/gibMacOS.git
cd gibMacOS
./gibMacOS.command

This will run a small Python script that will allow you to download mac iso files from *.apple.com

The version that worked for me was Mojave 10.14.6

macOS Mojave 10.14.6 (18G103)

gibmacos Choose macOS ISO for Downloading on Linux
gibmacos Choose macOS ISO for Downloading on Linux

Next, you will need qemu & libvirt for virtualisation and emulation.
Also required during qemu installation:
dnsmasq for networking
virt-manager but not required
bridge-utils for additional networking Requirements

sudo pacman -S qemu libvirt dnsmasq virt-manager bridge-utils

Now, enable libvirt and virtlogd

  • libvirt is libraries required for virtualisation
  • virtlogd is logging of the qemu virtual instances
sudo systemctl enable libvirtd.service
sudo systemctl enable virtlogd.service

Additionally, you will require the following packages which are found only in the Arch User Repository.

Most of them are on Github if you want to compile them yourselves.
Installing these will take some time, so one-by-one install these:

yay uml-utilities
yay libguestfs
yay ebtables
yay firewalld
yay virsh
sudo firewalld

If you are on Debian or Ubuntu

1
sudo apt-get install qemu uml-utilities virt-manager dmg2img git wget libguestfs-tools

The following program qt-virt-manager is huge and takes a long time to compile but you might need it:

# yay qt-virt-manager

You should reboot now to apply kernel changes for qemu.

Next, download the OSX-KVM Repository:
This folder will be referred to as the OSX-KVM folder.

Your macOS disk will be created in the folder we are about to download.

Make sure you choose a disk with enough space.

git clone https://github.com/kholia/OSX-KVM.git
cd OSX-KVM
# if you didnt use gibMacOS to download the OSX ISO you can use: 
# ./fetch-macOS.py

Converting macOS BaseSystem.dmg into Disk Image

In the gibMacOS folder that you downloaded earlier, navigate into:
macOS Downloads > publicrelease, and then the folder of the OSX Version that you downloaded.

Inside the macOS version folder that you downloaded from gibMacOS, we will turn the .dmg into .img
Make sure you have enough disk space here!

Find BaseSystem.dmg inside the gibMacOS downloaded folder. It should be around 500mb.
Convert it to .img:

# do this inside gibMacOS/macOS Downloads/publicrelease/061-26589 - 10.14.6 macOS Mojave/

qemu-img convert BaseSystem.dmg -O raw BaseSystem.img

Now move the BaseSystem.img that you just created FROM the gibMacOS folder -> TO THE OSX-KVM FOLDER

Move BaseSystem to OSX-KVM Folder
Move BaseSystem to OSX-KVM Folder

Decide now how big you want the macOS disk size to be.

I want an 80GB macOS disk size so I run the command below.
Note: do not change “mac_hdd_ng.img” or it will break the scripts later.

qemu-img create -f qcow2 mac_hdd_ng.img 80G

The 80GB empty disk has been created.
The macOS image is ready.

Now, create the network for the OSX VM

If you have successfully installed all the AUR packages above, you should be able to run this:

Run these commands one-by-one:

sudo ip tuntap add dev tap0 mode tap
sudo ip link set tap0 up promisc on
sudo virsh net-start default
sudo virsh net-autostart default
sudo ip link set dev virbr0 up
sudo ip link set dev tap0 master virbr0
macOS VMWARE Virtual Networking
macOS VMWARE Virtual Networking

Mac is now ready to boot.

Inside the OSX-KVM folder, run the shell script run-diagnostics.sh

./run-diagnostics.sh

If everything looks okay, you are ready to boot macOS on Arch Linux.

macOS Run Diagnostics
macOS Run Diagnostics

Boot macOS

./boot-macOS-NG.sh

Boot and Installation Process

Hint: in QEMU, press Ctrl + Alt + G to gain control of your mouse again.

At the CLOVER Boot Manager screen, select:
Boot macOS Install from macOS Base System

macOS Clover Boot Linux AMD OSX
macOS Clover Boot Linux AMD OSX

After about a minute, the macOS recovery GUI will appear and you can select your language.

When you reach the macOS Utilities screen, seleck “Disk Utility”

macOS on Linux Disk Utility
macOS on Linux Disk Utility

In the top left, select “Show All Devices”. Not required to see the disk we are using, but helpful to visualize what is happening

Show All Devices OSX Disk Utility
Show All Devices OSX Disk Utility

Select the disk which has 80GB and is “Uninitialized”.

Uninitialized QEMU Disk for macOS on Linux
Uninitialized QEMU Disk for macOS on Linux

Click on “Erase” and erase the 90GB disk.

Do not change the Format or Scheme.

Erasing the disk here does nothing to your real computer. This is a virtual drive.

Erase Disk macOS Linux
Erase Disk macOS Linux

Create a new partition for macOS on your QEMU Drive

NOTE: YOU MUST REDUCE THE DISK SIZE BY A SMALL AMOUNT TO BE ABLE TO PRESS APPLY

After you have erased the disk, click “Partition”.

Partitioning QEMU Drive on Linux for macOS
Partitioning QEMU Drive on Linux for macOS
Change 85.6 to 85.5 and you will be able to press apply.
You Must Reduce the Partition Size by any amount
You Must Reduce the Partition Size by any amount.

Note: this will NOT steal 80GB straight away from your hard drive:  it’s just virtually allocating it from your host machine’s disk.

Create macOS partition for Arch Linux QEMU
Create macOS partition for Arch Linux QEMU

When that has finished, you can close the “Disk Utility”

Select Reinstall macOS.

Reinstall macOS on QEMU
Reinstall macOS on QEMU
Install macOS Mojave on Arch Linux
Install macOS Mojave on Arch Linux

Have fun using macOS on Linux with QEMU!

Install XCode on Arch Linux
Install XCode on Arch Linux

How To Setup VNC, XRDP, XDoTool on Ubuntu (Azure, Gcloud)

How To Setup VNC, XRDP, XDoTool on Ubuntu (Azure, Gcloud)

# update
sudo apt update -y

# install xdotool
sudo apt install xdotool -y

# prepare xfce desktop env
sudo apt install xfce4 xfce4-goodies -y

# vnc4server causes segmentation fault with xdotool so we will be using xrdp + vnc
sudo apt install vnc4server xrdp -y

# enable xrdp
sudo systemctl enable xrdp

# add ssl user
sudo adduser xrdp ssl-cert

# add startxfce4 to the startup
echo ""exec startxfce4"" | sudo tee -a /etc/xrdp/xrdp.ini

# restart xrdp
sudo systemctl restart xrdp

# if you are using REMMINA and your remote desktop server is xrdp you need to check
# "Relax Order Checks" on the Advanced Tab in the profile

# disable extra security
sudo apt install selinux-utils -y
setenforce 0

# start a big screen session
vncserver -geometry 1920x1080

# and kill it
vncserver -kill :1

# reload daemons
sudo systemctl daemon-reload

# enable vncserver
sudo systemctl enable --now [email protected]

# open the xrdp port and the vnc port
sudo ufw allow 5901
sudo ufw allow 3389

# if you are using RHEL/CENTOS
# sudo firewall-cmd --permanent –add-port=5901/tcp
# sudo firewall-cmd --permanent –add-port=3389/tcp
# sudo firewall-cmd –reload

# open some applicationsa
export DISPLAY=:1
xfwm4 &
xfce4-panel &
xdotool getmouselocation

Install XFCE CentOS 8

As CentOS is new, we need to add additional repos, namely epel-testing.

First, install yum utils to get yum-config-manager

1
2
yum install yum-utils -y
dnf install yum-utils -y

Then, enable EPEL testing which has all the missing packages from CentOS 7 in CentOS 8.

1
yum-config-manager --enable epel-testing

Bare minimum desktop:

1
yum install xfce4-panel Thunar xfce4-appfinder xfdesktop -y

All the extras:

1
2
3
4
dnf --enablerepo=epel-testing install xfce4-panel Thunar thunar-volman tumbler tumbler-extras   \
                                  xfce4-appfinder xfce4-power-manager xfce4-settings       \
                                  xfdesktop xfce4-session parole xfce4-terminal xfburn     \
                                  xfce4-notifyd


Install Python 3.8 on CentOS 7 or 8

Here is a one block automated install for Python3.8 on CentOS:

1
2
3
4
5
6
7
8
9
10
yum install make gcc openssl-devel bzip2-devel libffi-devel -y
cd /opt
wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz
tar xzf Python-3.8.0.tgz
cd Python-3.8.0
./configure --enable-optimizations
make altinstall
rm Python-3.8.0.tgz
python3.8 --version
cd /root

Selenium Stopped Working 2019 Python Selenium Geckodriver Sock Error: Cannot Connect/Create Connection to Browser

I recently upgraded Firefox to the latest build.

Then, my geckodriver binary stopped working in Python.

1
2
3
4
5
6
7
8
firefox --version
Mozilla Firefox 71.0

python --version
Python 3.8.0

/bin/geckodriver --version
geckodriver 0.24.0

The main problem, I had an outdated Geckodriver version (from the distro repo)

1
2
3
sudo pacman -R geckodriver
/bin/geckodriver --version
bash: /bin/geckodriver: No such file or directory

Find the latest version

https://github.com/mozilla/geckodriver/releases/

1
2
3
4
5
6
7
8
9
10
cd /opt
sudo wget https://github.com/mozilla/geckodriver/releases/download/v0.26.0/geckodriver-v0.26.0-linux64.tar.gz

sudo tar -xzvf geckodriver.tar.gz && rm -f geckodriver.tar.gz

sudo chmod +x geckodriver

sudo chmod 755 geckodriver

sudo cp geckodriver /bin/geckodriver

Geckordriver should be updated to the latest version:

geckodriver --version
geckodriver 0.26.0

OneLiner: Upgrade All PIP and PIP3 Python Packages to Latest Version

“pip3 list –outdated” shows us all installed packages that are currently out of date.

1
pip3 list --outdated

Sample Output

1
2
3
4
5
6
7
8
Package
------------------
certifi
h11
httpcore
importlib-metadata
lit
...

xargs –update, excluding the “Packages” and “——…” header lines

1
2
3
4
sudo pip3 list --outdated | \
awk -F" " '{ print $1 }' | \
grep -v "Package\|------------------" | \
xargs sudo pip3 install --upgrade

And as a one-liner:

1
sudo pip3 list --outdated | awk -F" " '{ print $1 }' | grep -v "Package\|------------------" | xargs sudo pip3 install --upgrade
Auto Upgrade Python PIP Modules Libraries
Auto Upgrade Python PIP Modules Libraries

Install Docker on CentOS 8 – Automatically!

Docker doesn’t come with “stock” repos on CentOS, some variations of alias programs are installations like podman.

These lack many of the core commands of the “real” Docker.

Here is a guide to install Docker Latest Version on CentOS.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
yum clean all -y
yum update -y
yum upgrade -y

dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo

DOCKERVERSION=$(dnf list docker-ce --showduplicates | \
sort -r | \
grep "docker-ce.x86_64" -m1 | \
sed -e 's/docker\-ce\.x86\_64//g' -e 's/docker\-ce\-stable//g' | \
tr -d [:space:])

echo "Installing docker-ce-$DOCKERVERSION"

# remove this line in auto environments
read -p "Does this look right? Ctrl C to stop."

dnf install containerd -y

dnf install docker-ce-$DOCKERVERSION -y

# if the above fails, try the latest compatible via
dnf --nobest install docker-ce-$DOCKERVERSION --nobest -y

Generate Random Numbers on Bash or Shell Using Builtins $random

As we all know, the shell builtin variable $RANDOM is a pseudo random number generator.

Today, we will be looking at some creative ways to generate psuedo random numbers, trying to use shell builtins as much as possible.

The Best Solution is shuf (not exactly builtin though)

1
2
3
4
# Shuffle and return n'th line of range
shuf --head-count="1" --input-range="1-10000"
shuf -n1 -i1-10000
9523

Ways to generate various strings of numbers in BASH

1
2
3
# Generate a number between 0 - 32767
echo $RANDOM
7469

$RANDOM Caveats

From the 2 above scenarios, we analyse the distribution of the digits and find out the frequency of each value in order to see how random they really are:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Count the frequency of numbers in a 10000 samples
# cut -c1 chops the first digit from our variable

for i in $(seq 1 1000); do
    RNUMS+=($(cut -c1 <<< $RANDOM))
done

### OR

while [[ $COUNTER -le 1000 ]]; do
     RNUMS+=($(cut -c1 <<< $RANDOM))
     COUNTER=$COUNTER+1
done

# show RNUMS array length, should be 1000
echo ${#RNUMS[@]}

Now, we want to test the frequency of each digit:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
for n in ${RNUMS[@]}; do
    case $n in
        1 ) ((ones++))
            ;;
        2 ) ((twos++))
            ;;
        3 ) ((three++))
            ;;
        4 ) ((fours++))
            ;;
        5 ) ((fives++))
            ;;
        6 ) ((sixes++))
            ;;
        7 ) ((sevens++))
            ;;
        8 ) ((eights++))
            ;;
        9 ) ((nines++))
            ;;
        0 ) ((zeros++))
            ;;
    esac
done

echo $ones $twos $threes $fours $fives $sixes $sevens $eights $nines $zeros

Strangely, the output expected should be ~100, ~100, ~100…

However, the output is totally different:

330 367 108 22 41 28 30 42 33

Creative Ways To Generate Bad Random Numbers In Bash

The second digit from $RANDOM$RANDOM

cut -c2 <<< $RANDOM$RANDOM

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# cut the 2nd digit from RANDOMRANDOM
# $RANDOM's minimum value is 1 therefore the second digit should always be there
# Do not use this value on its own though, as it clearly is not random
while [[ $COUNTER -le 1000 ]]; do
     RNUMS+=($(cut -c2 &lt;&lt;&lt; $RANDOM$RANDOM))
     COUNTER=$COUNTER+1
done
# frequency test
111 114 92 97 86 87 89 95 105 125

# again
120 100 108 93 100 97 78 83 97 125

# CLEARLY NOT RANDOM

A digit from $(date +%N)

cut -c9 <<< $(date +%N)

1
2
3
4
# Print the time in nanoseconds of the current moment
# Do not use this value on its own though, as it clearly is not random
date +%N
277936336
1
2
3
4
5
6
7
while [[ $COUNTER -le 1000 ]]; do
     RNUMS+=($(cut -c9 &lt;&lt;&lt; $(date +%N)))
     COUNTER=$COUNTER+1
done
# frequency test
103 89 105 92 102 104 100 106 91 109
# DECENTLY RANDOM

A digit from cksum <<< $RANDOM$RANDOM

cut -c2 <<< $(cksum <<< $RANDOM$RANDOM)

1
2
3
# Checksum $RANDOM$RANDOM
echo $(cksum &lt;&lt;&lt; $RANDOM$RANDOM)
277936336
1
2
3
4
5
6
7
8
9
10
11
while [[ $COUNTER -le 1000 ]]; do
     RNUMS+=($(cut -c2 &lt;&lt;&lt; $(cksum &lt;&lt;&lt; $RANDOM$RANDOM)))
     COUNTER=$COUNTER+1
done
# frequency test
128 123 91 78 101 95 85 86 92 122
# again
124 111 110 79 82 91 100 103 84 117
# and again
126 118 104 92 101 85 88 87 86 114
# CLEARLY NOT RANDOM!

A digit from cksum <<< $(($RANDOM*$RANDOM))

cut -c2 <<< $(cksum <<< $(($RANDOM*$RANDOM)))

1
2
3
4
5
6
7
8
9
# Checksum $RANDOM x $RANDOM
while [[ $COUNTER -le 1000 ]]; do
     RNUMS+=($(cut -c2 &lt;&lt;&lt; $(cksum &lt;&lt;&lt; $(($RANDOM*$RANDOM)))))
     COUNTER=$COUNTER+1
done
# and analysis
112 127 107 103 88 84 106 85 81 108
126 106 97 99 85 99 88 83 105 113
# CLEARY NOT RANDOM!

Shuf 1-10

shuf -n1 -i1-10

1
2
3
4
5
6
7
8
9
# Shuffle 1-10
while [[ $COUNTER -le 1000 ]]; do
     RNUMS+=($(shuf -n1 -i1-10))
     COUNTER=$COUNTER+1
done
# and analysis
95 107 76 93 113 88 116 109 110
101 95 116 100 107 109 83 91 103
# GREAT RANDOM NUMBER GENERATOR