From 83f9a2f51236ee3c82bf3d21d8a806f2bf9df765 Mon Sep 17 00:00:00 2001 From: yuk7 Date: Thu, 10 Feb 2022 00:34:07 +0900 Subject: [PATCH] Add first run script --- Makefile | 3 ++- README.md | 2 +- bash_profile | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 bash_profile diff --git a/Makefile b/Makefile index b1770bd..a86583e 100644 --- a/Makefile +++ b/Makefile @@ -39,11 +39,12 @@ rootfs: base.tar mkdir rootfs sudo bsdtar -zxpf base.tar -C rootfs @echo "# This file was automatically generated by WSL. To stop automatic generation of this file, remove this line." | sudo tee rootfs/etc/resolv.conf > /dev/null + sudo cp bash_profile rootfs/root/.bash_profile sudo chmod +x rootfs base.tar: @echo -e '\e[1;31mExporting base.tar using docker...\e[m' - docker run --net=host --name mintwsl linuxmintd/mint20.3-amd64 /bin/bash -c "echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections; apt-get update; apt-get full-upgrade -y -q; apt-get install -y -q apt-transport-https apt-utils aria2 bash-completion build-essential ca-certificates curl dialog htop iputils-ping software-properties-common tree; touch /etc/wsl.conf; echo '[automount]' | tee -a /etc/wsl.conf > /dev/null; echo >> /etc/wsl.conf; echo '[network]' | tee -a /etc/wsl.conf > /dev/null; echo >> /etc/wsl.conf; echo '[interop]' | tee -a /etc/wsl.conf > /dev/null; echo >> /etc/wsl.conf; echo '[user]' | tee -a /etc/wsl.conf > /dev/null; echo >> /etc/wsl.conf; echo '#The Boot setting is only available on Windows 11' | tee -a /etc/wsl.conf > /dev/null; echo '[boot]' | tee -a /etc/wsl.conf > /dev/null; unminimize; apt-get autoremove -y; apt-get clean;" + docker run --net=host --name mintwsl linuxmintd/mint20.3-amd64 /bin/bash -c "echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections; apt-get update; apt-get full-upgrade -y -q; apt-get install -y -q apt-transport-https apt-utils aria2 bash-completion build-essential ca-certificates curl dialog figlet htop iputils-ping software-properties-common tree; unminimize; apt-get autoremove -y; apt-get clean;" docker export --output=base.tar mintwsl docker rm -f mintwsl diff --git a/README.md b/README.md index b7ea1d9..aa6576b 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,7 @@ Usage : ## How to setup -Open Mint.exe and run the following commands. +LinuxmintWSL will ask you to create a new user during its first run. If you chose to create a new user during initial setup, the steps below are not required unless you want to create additional users. ```dos passwd useradd -m -s /bin/bash diff --git a/bash_profile b/bash_profile new file mode 100644 index 0000000..afba07a --- /dev/null +++ b/bash_profile @@ -0,0 +1,46 @@ +# First run script for LinuxmintWSL + +ylw=$(tput setaf 3) +txtrst=$(tput sgr0) + +echo -e "\033[33;7mDo not interrupt or close the terminal window till script finishes execution!!!\033[0m" +figlet -t Welcome to LinuxmintWSL +echo -e "[automount]\n\n[network]\n\n[interop]\n\n[user]\n\n#The Boot setting is only available on Windows 11\n[boot]\n" >/etc/wsl.conf +echo " " +echo -e "\033[32mDo you want to create a new user?\033[m" +select yn in "Yup" "Nope"; do + case $yn in + Yup) + echo " " + while read -p "Please enter the username you wish to create : " username; do + if [ x$username = "x" ]; then + echo -e "\033[31m Blank username entered. Try again\033[m" + echo -en "\033[1A\033[1A\033[2K" + username="" + elif grep -q "$username" /etc/passwd; then + echo -e "\033[31mUsername already exists. Try again\033[m" + echo -en "\033[1A\033[1A\033[2K" + username="" + else + useradd -m -s /bin/bash "$username" + echo -en "\033[1B\033[1A\033[2K" + passwd $username + sed -i "/\[user\]/a default = $username" /etc/wsl.conf >/dev/null + echo " " + secs=5 + while [ $secs -gt 0 ]; do + printf ${ylw}"\r\033[KSystem needs to be restarted. Shutting down in %.d seconds."${txtrst} $((secs--)) + sleep 1 + done + rm ~/.bash_profile + cmd.exe /C wsl --shutdown + fi + done + ;; + Nope) + clear + rm ~/.bash_profile + break + ;; + esac +done