This repository has been archived by the owner on Nov 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
bash_profile
176 lines (165 loc) · 8.92 KB
/
bash_profile
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# First run script for SlackwareWSL
blu=$(tput setaf 4)
cyn=$(tput setaf 6)
grn=$(tput setaf 2)
mgn=$(tput setaf 5)
red=$(tput setaf 1)
ylw=$(tput setaf 3)
txtrst=$(tput sgr0)
diskvol=$(mount | grep -m1 ext4 | cut -f 1 -d " ")
sudo resize2fs $diskvol >/dev/null 2>&1
disksize=$(sudo blockdev --getsize64 $diskvol)
osname=$(/mnt/c/Windows/System32/wbem/wmic.exe os get Caption | sed -n 2p)
width=$(echo $COLUMNS)
if [ "$width" -gt 120 ]; then
width=120
fi
test -e /mnt/c/Users/Public/vhdresize.txt && rm /mnt/c/Users/Public/vhdresize.txt
test -e /mnt/c/Users/Public/shutdown.cmd && rm /mnt/c/Users/Public/shutdown.cmd
test -e ~/vhdresize.txt && rm ~/vhdresize.txt
test -e ~/shutdown.cmd && rm ~/shutdown.cmd
figlet -t -k -f /usr/share/figlet/mini.flf "Welcome to SlackwareWSL" | lolcat
echo -e "\033[33;7mDo not interrupt or close the terminal window till script finishes execution!!!\n\033[0m"
setcap cap_net_raw+ep /bin/ping
chmod +x /usr/local/bin/slack_mirrortest
echo -e ${grn}"Updating CA certificates..."${txtrst}
/usr/sbin/update-ca-certificates --fresh >/dev/null
cp -f /etc/skel/.bashrc ~/.bashrc
echo "PS1='\[\033[01;31m\][\u@\h\[\033[01;36m\] \W\[\033[01;31m\]]\$\[\033[00m\] '" | tee -a ~/.bashrc >/dev/null 2>&1
if [ "$disksize" -le 274877906944 ]; then
echo -e ${grn}"SlackwareWSL's VHD has a default maximum size of 256GB. Disk space errors which occur if size exceeds 256GB can be fixed by expanding the VHD. Would you like to resize your VHD? More information on this process is available at \033[36mhttps://docs.microsoft.com/en-us/windows/wsl/vhd-size\033[32m."${txtrst} | fold -sw $width
select yn in "Yes" "No"; do
case $yn in
Yes)
echo " "
while read -p ${mgn}"Path to virtual disk (e.g. C:\Users\silesh\wsl\ext4.vhdx) : "${txtrst} -r vhdpath; do
if [ "x$vhdpath" = "x" ]; then
echo -e ${red}"Path cannot be blank."${txtrst}
echo -en "\033[1A\033[1A\033[2K"
vhdpath=""
else
wsl_path=$(wslpath -a $vhdpath)
if [ ! -f $wsl_path ]; then
echo -e ${red}"Disk does not exist. "${txtrst}
echo -en "\033[1A\033[1A\033[2K"
vhdpath=""
else
echo "select vdisk file=\"$vhdpath\"" | sudo tee -a ~/vhdresize.txt >/dev/null 2>&1
break
fi
fi
done
while read -p ${mgn}"Size of virtual disk in MegaBytes(e.g. 512000 for 512GB) : "${txtrst} vhdsize; do
if [[ $vhdsize =~ ^-?[0-9]+$ ]]; then
if [ "$vhdsize" -le 256000 ]; then
echo -e ${red}"Disk size should be greater than 256000 MegaBytes."${txtrst}
echo -en "\033[1A\033[1A\033[2K"
vhdsize=0
else
echo -en "\033[1B\033[1A\033[2K"
echo "expand vdisk maximum=$vhdsize" | sudo tee -a ~/vhdresize.txt >/dev/null 2>&1
echo " "
printf "%s" "$(<~/vhdresize.txt)"
echo " "
echo -e ${grn}"\nReview the information displayed above and confirm to proceed."${txtrst}
echo -e ${red}"Edit only your input if you want to make changes!!!"${txtrst}
select yn in "Proceed" "Edit"; do
case $yn in
Proceed)
break
;;
Edit)
"${EDITOR:-nano}" ~/vhdresize.txt
break
;;
esac
done
echo "@echo off" | sudo tee -a ~/shutdown.cmd >/dev/null 2>&1
echo "wsl --shutdown" | sudo tee -a ~/shutdown.cmd >/dev/null 2>&1
echo "diskpart /s C:\Users\Public\vhdresize.txt" | sudo tee -a ~/shutdown.cmd >/dev/null 2>&1
if env | grep "WT_SESSION" >/dev/null 2>&1; then
echo "wt.exe -w 0 nt wsl.exe -d $WSL_DISTRO_NAME" | sudo tee -a ~/shutdown.cmd >/dev/null 2>&1
else
echo "cmd /c start \"$WSL_DISTRO_NAME\" wsl.exe --cd ~ -d $WSL_DISTRO_NAME" | sudo tee -a ~/shutdown.cmd >/dev/null 2>&1
fi
cp ~/vhdresize.txt /mnt/c/Users/Public
cp ~/shutdown.cmd /mnt/c/Users/Public && rm ~/shutdown.cmd
break
fi
else
echo -e ${red}"Disk size cannot be blank and has to be numeric. "${txtrst}
echo -en "\033[1A\033[1A\033[2K"
fi
done
secs=3
printf ${ylw}"\nPlease grant diskpart elevated permissions when requested. SlackwareWSL will restart after disk resize.\n"${txtrst}
printf ${red}"Warning!!! Any open wsl distros will be shutdown.\n\n"${txtrst}
while [ $secs -gt 0 ]; do
printf "\r\033[KShutting down in %.d seconds. " $((secs--))
sleep 1
done
/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -command "Start-Process -Verb Open -FilePath 'shutdown.cmd' -WorkingDirectory 'C:\Users\Public' -WindowStyle Hidden"
exec sleep 0
;;
No)
break
;;
esac
done
fi
echo -e ${grn}"Create root password"${txtrst}
passwd
echo " "
echo -e ${grn}"Do you want to create a new user?"${txtrst}
select yn in "Yes" "No"; do
case $yn in
Yes)
echo " "
while read -p "Please enter the username you wish to create : " username; do
if [ "x$username" = "x" ]; then
echo -e ${red}" Blank username entered. Try again!!!"${txtrst}
echo -en "\033[1A\033[1A\033[2K"
username=""
elif grep -q "^$username" /etc/passwd; then
echo -e ${red}"Username already exists. Try again!!!"${txtrst}
echo -en "\033[1A\033[1A\033[2K"
username=""
else
groupadd sudo
useradd -m -g users -G sudo,wheel,floppy,audio,video,cdrom,plugdev,power,netdev,lp,scanner -s /bin/bash "$username"
echo "%wheel ALL=(ALL) ALL" >/etc/sudoers.d/wheel
echo "%sudo ALL=(ALL) ALL" >/etc/sudoers.d/sudo
cp -f /etc/skel/.bash_profile /home/"$username"/.bash_profile
cp -f /etc/skel/.bashrc /home/"$username"/.bashrc
echo "PS1='\[\033[01;32m\][\u@\h\[\033[01;37m\] \W\[\033[01;32m\]]\$\[\033[00m\] '" | tee -a /home/"$username"/.bashrc >/dev/null 2>&1
echo -en "\033[1B\033[1A\033[2K"
passwd $username
sed -i "/\[user\]/a default = $username" /etc/wsl.conf >/dev/null
echo "@echo off" | sudo tee -a ~/shutdown.cmd >/dev/null 2>&1
echo "wsl.exe --terminate $WSL_DISTRO_NAME" | sudo tee -a ~/shutdown.cmd >/dev/null 2>&1
if env | grep "WT_SESSION" >/dev/null 2>&1; then
echo "wt.exe -w 0 nt wsl.exe -d $WSL_DISTRO_NAME" | sudo tee -a ~/shutdown.cmd >/dev/null 2>&1
else
echo "cmd /c start \"$WSL_DISTRO_NAME\" wsl.exe --cd ~ -d $WSL_DISTRO_NAME" | sudo tee -a ~/shutdown.cmd >/dev/null 2>&1
fi
echo "del C:\Users\Public\shutdown.cmd" | sudo tee -a ~/shutdown.cmd >/dev/null 2>&1
cp ~/shutdown.cmd /mnt/c/Users/Public && rm ~/shutdown.cmd
secs=3
printf ${ylw}"\nTo set the new user as the default user, SlackwareWSL will shutdown and restart!!!\n\n"${txtrst}
while [ $secs -gt 0 ]; do
printf "\r\033[KShutting down in %.d seconds. " $((secs--))
sleep 1
done
rm ~/.bash_profile
/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -command "Start-Process -Verb Open -FilePath 'shutdown.cmd' -WorkingDirectory 'C:\Users\Public' -WindowStyle Hidden"
exec sleep 0
fi
done
;;
No)
clear
rm ~/.bash_profile
break
;;
esac
done