#!/bin/bash

root=`pwd`

# Setting base environment
echo "Setting base environment."

sudo apt update -y
sudo apt upgrade -y
sudo apt install gawk wget git diffstat unzip texinfo gcc build-essential \
chrpath socat cpio python3 python3-pip python3-pexpect python-is-python3 \
xz-utils debianutils iputils-ping python3-git python3-jinja2 libegl1-mesa \
libsdl1.2-dev python3-subunit mesa-common-dev zstd liblz4-tool file locales -y

sudo locale-gen en_US.UTF-8

mkdir -p ~/.cargo

echo '[source.ustc]' > ~/.cargo/config
echo 'registry = "git://mirrors.ustc.edu.cn/crates.io-index"' >> ~/.cargo/config

# Installing repo
echo "Installing repo."
mkdir -p ~/bin
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo > ~/bin/repo
chmod a+x ~/bin/repo

export PATH=~/bin:$PATH
export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo'

# init repository
read -p "plase input your project name: " projectname
mkdir -p $projectname
cd $projectname
repo init -u ssh://git@gitlab.veryark.cn:3399/developer/ark_ii/unit-box/unitbox-sys/unitbase-manifest -b main -m imx-6.1.36-2.1.0.xml
repo sync
cd $root
echo "Init yocto project successfully."
rm $0
exit 0
