Login

AUTOVM Blog > News > Add Ubuntu 22.…

Add Ubuntu 22.04 and Debian 11 on AutoVM

By Alireza Mahdavi | 21 October 2022 | 1486 views

Add Ubuntu 22.04 and Debian 11 on AutoVM

Ubuntu 22.04 and Debian 11 has been released for AutoVM platform.

Download and deploy OVA templates into your servers. Ubuntu and Debian link.

Then go to “AutoVM admin area > Template > Template > Create” and enter the following details:

Name: Debian 11 64
Username: root
Password: 123QWEqwe
Clue: debian_11_64
Icon: Debian

Click on save and click on Create icon again and enter the following details for Ubuntu:

Name: ubuntu 22.04 64
Username: root
Password: 123QWEqwe
Clue: ubuntu_22_64
Icon: Ubuntu

Click on save and go to “Template > Script > Create” and enter the following details for Debian:

Name: Setup
Template: Debian 11 64
Type: Setup
Where is program: /bin/bash
Where to upload: /home/setup.sh
How to execute: /home/setup.sh

Enter the following code into the “Content” part:

#!/bin/bash

# FIND DETAILS
details=$(cat /etc/os-release)

# FIND DIST
dist=$(echo "$details" | grep ^ID= | grep -Eo [a-z]+)

# FIND VERSION
version=$(echo "$details" | grep ^VERSION= | grep -Eo [0-9]+ | head -n 1)

# FIND NAME
name=$(ls /sys/class/net | head -n 1)

# NETMASK SCRIPT
cat <<EOF > /etc/cidr.py

import argparse

parser = argparse.ArgumentParser()
parser.add_argument('netmask')
args = parser.parse_args()

cidr = 0

for bits in args.netmask.split('.'):

    bits = bin(int(bits)).count('1')

    cidr = cidr + bits

print(cidr)

EOF


# DEBIAN
function debianIP {

cat <<EOF > /etc/network/interfaces
auto lo
iface lo inet loopback
auto $name
iface $name inet static
address @address
netmask @netmask
gateway @gateway
dns-nameservers 4.2.2.4 8.8.4.4
EOF

# START
ifdown $name
ifup $name

}

# DEBIAN
function debianIPWithRoute {

cat <<EOF > /etc/network/interfaces
auto lo
iface lo inet loopback
auto $name
iface $name inet static
address @address
netmask @netmask
broadcast @address
post-up route add @gateway dev $name
post-up route add default gw @gateway
pre-down route del @gateway dev $name
pre-down route del default gw @gateway
dns-nameservers 4.2.2.4 8.8.4.4
EOF

# START
ifdown $name
ifup $name
}

if [ $cidr == 32 ]; then
    debianIPWithRoute
else
    debianIP
fi


# RESIZE PARTITION
function commonPartition {

    # RESIZE PARTITION
    (echo d; echo n; echo p; echo ; echo ; echo ; echo N; echo w) | fdisk /dev/sda

    # RESIZE FILESYSTEM
    resize2fs /dev/sda1
}

commonPartition


# PUBLIC KEY
if [ ! -z "@publicKey" ]; then

    # SSH DIRECTORY
    mkdir -p $HOME/.ssh

    # PUBLIC KEY
    echo "@publicKey" > $HOME/.ssh/authorized_keys
fi

# PASSWORD
(echo "@password"; echo "@password") | passwd @username

# HOSTNAME
if [ ! -z "@name" ]; then

    hostnamectl set-hostname "@name"
fi

# DELETE FILE
rm /home/setup.sh

Click on “Save” and click on “Create” to add Ubuntu script and enter the following details:

Name: Setup
Template: Ubuntu 22 64
Type: Setup
Where is program: /bin/bash
Where to upload: /home/setup.sh
How to execute: /home/setup.sh

Enter the following code into the “Content” part:

#!/bin/bash

# FIND interface NAME
interface=$(ls /sys/class/net | head -n 1)

# NETMASK SCRIPT
cat <<EOF > /etc/cidr.py

import argparse

parser = argparse.ArgumentParser()
parser.add_argument('netmask')
args = parser.parse_args()

cidr = 0

for bits in args.netmask.split('.'):

    bits = bin(int(bits)).count('1')

    cidr = cidr + bits

print(cidr)

EOF


# NETMASK TO CIDR
if which python3; then

    cidr=$(python3 /etc/cidr.py @netmask)
else

    cidr=$(python /etc/cidr.py @netmask)
fi

# NETPLAN
function netplanIP {

cat <<EOF > /etc/netplan/config.yaml
network:
  version: 2
  renderer: networkd
  ethernets:
    $interface:
      dhcp4: no
      addresses: [@address/$cidr]
      routes:
      - to: default
        via: @gateway
      nameservers:
        addresses: [4.2.2.4, 8.8.4.4]
EOF

# START
netplan apply

}

# NETPLAN
function netplanIPWithRoute {

cat <<EOF > /etc/netplan/config.yaml
network:
  version: 2
  renderer: networkd
  ethernets:
    $interface:
      addresses: [@address/$cidr]
      dhcp4: no
      nameservers:
        addresses: [4.2.2.4, 8.8.4.4]
      routes:
      - to: 0.0.0.0/0
        via: @gateway
        on-link: true
EOF

# START
netplan apply

}

# NETPLAN
if [ -d /etc/netplan ]; then

    if [ $cidr == 32 ]; then
        netplanIPWithRoute
    else
        netplanIP
    fi
fi


# RESIZE PARTITION
function commonPartition {

    # RESIZE PARTITION
    (echo d; echo 2; echo n; echo 2; echo ; echo ; echo N; echo w) | fdisk /dev/sda

    # RESIZE FILESYSTEM
    partprobe && resize2fs /dev/sda2
}



commonPartition


# PUBLIC KEY
if [ ! -z "@publicKey" ]; then

    # SSH DIRECTORY
    mkdir -p $HOME/.ssh

    # PUBLIC KEY
    echo "@publicKey" > $HOME/.ssh/authorized_keys
fi

# PASSWORD
(echo "@password"; echo "@password") | passwd @username

# HOSTNAME
if [ ! -z "@name" ]; then

    hostnamectl set-hostname "@name"
fi

# DELETE FILE
rm /home/setup.sh

Related Blogs

New AutoVM WHMCS module client area

The new AutoVM WHMCS module will be released soon with enormous updates regarding the client area interface. Take a look at our new UI […]

Subscription for email

Future-proof your business by moving to AutoVM