Created
June 17, 2020 16:49
-
-
Save MrCyjaneK/9be6ee4b59ab6a18931b232cb360a1e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
time1="$( date +"%r" )" | |
install_ubuntu () { | |
directory=ubuntu-fs | |
UBUNTU_VERSION=20.04 | |
if [ -d "$directory" ]; | |
then | |
first=1 | |
echo "[${time1}] [WARNING]: Skipping the download and the extraction, remove $directory to reinstall" | |
elif [ -z "$(command -v proot)" ]; | |
then | |
echo "[${time1}] [ERROR]: Please install proot." | |
echo "" | |
exit 1 | |
elif [ -z "$(command -v wget)" ]; | |
then | |
echo "[${time1}] [ERROR]: Please install wget." | |
echo "" | |
exit 1 | |
fi | |
if [ "$first" != 1 ]; | |
then | |
if [ -f "ubuntu.tar.gz" ]; | |
then | |
echo "# rm -rf ubuntu.tar.gz" | |
fi | |
if [ ! -f "ubuntu.tar.gz" ];then | |
echo "[${time1}] [Installer thread/INFO]: Downloading the ubuntu rootfs, please wait..." | |
ARCHITECTURE=$(dpkg --print-architecture) | |
case "$ARCHITECTURE" in | |
aarch64) ARCHITECTURE=arm64;; | |
arm) ARCHITECTURE=armhf;; | |
armhf) ARCHITECTURE=armhf;; | |
amd64|x86_64) ARCHITECTURE=amd64;; | |
*) | |
echo "[${time1}] [ERROR]: Unknown architecture :- $ARCHITECTURE" | |
exit 1 | |
;; | |
esac | |
wget http://cdimage.ubuntu.com/ubuntu-base/releases/${UBUNTU_VERSION}/release/ubuntu-base-${UBUNTU_VERSION}-base-${ARCHITECTURE}.tar.gz -O ubuntu.tar.gz 2>&1 | cat | grep "%" | tr "\n" "\r" | |
echo "[${time1}] [Installer thread/INFO]: Download complete!" | |
fi | |
cur=`pwd` | |
mkdir -p $directory | |
cd $directory | |
echo "[${time1}] [Installer thread/INFO]: Decompressing the ubuntu rootfs, please wait..." | |
tar -zxf $cur/ubuntu.tar.gz --exclude='dev'||: | |
echo "[${time1}] [Installer thread/INFO]: The ubuntu rootfs have been successfully decompressed!" | |
echo "[${time1}] [Installer thread/INFO]: Fixing the resolv.conf, so that you have access to the internet" | |
echo -n -e "nameserver 8.8.8.8\nnameserver 8.8.4.4\n" > etc/resolv.conf | |
cd $cur | |
fi | |
bin=startubuntu.sh | |
echo "[${time1}] [Installer thread/INFO]: Creating the start script, please wait...\n" | |
echo '#!/bin/bash' > $bin | |
# echo 'set -x' >> $bin | |
echo 'if [ "$EUID" -ne 0 ]' >> $bin | |
echo ' then echo "Please run as root"' >> $bin | |
echo ' exit' >> $bin | |
echo 'fi' >> $bin | |
echo '' >> $bin | |
echo 'dir="`pwd`/ubuntu-fs"' >> $bin | |
echo 'mkdir -p "$dir/dev/shm" 2>/dev/null' >> $bin | |
echo 'trap "umount \"$dir\"/tmp \"${dir}\"/dev/shm" EXIT INT TERM HUP PIPE &&' >> $bin | |
echo ' mount --bind /tmp "${dir}/tmp" && \' >> $bin | |
echo ' mount --bind /dev/shm "${dir}/dev/shm" && \' >> $bin | |
echo ' echo "Starting chroot!" && \' >> $bin | |
echo ' chroot "$dir"' >> $bin | |
echo 'umount \"$dir\"/tmp \"${dir}\"/dev/shm' >> $bin | |
echo "[${time1}] [Installer thread/INFO]: The start script has been successfully created!" | |
echo "[${time1}] [Installer thread/INFO]: Making startubuntu.sh executable please wait..." | |
chmod +x $bin | |
echo "[${time1}] [Installer thread/INFO]: Successfully made startubuntu.sh executable" | |
echo "[${time1}] [Installer thread/INFO]: Cleaning up please wait..." | |
rm ubuntu.tar.gz -rf | |
echo "[${time1}] [Installer thread/INFO]: Successfully cleaned up!" | |
echo "[${time1}] [Installer thread/INFO]: The installation has been completed! You can now launch Ubuntu with ./startubuntu.sh" | |
echo "" | |
} | |
if [ "$1" = "-y" ];then | |
install | |
elif [ "$1" = "" ];then | |
printf "[${time1}] [QUESTION]: Do you want to install ubuntu-in-ubtouch? [Y/n] " | |
read cmd1 | |
if [ "$cmd1" = "y" ];then | |
install_ubuntu | |
elif [ "$cmd1" = "Y" ];then | |
install_ubuntu | |
else | |
echo "[${time1}] [ERROR]: Installation aborted." | |
echo "" | |
exit | |
fi | |
else | |
echo "[${time1}] [ERROR]: Installation aborted." | |
echo "" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment