move tasks from WSL setup to config.sh and tidy
This commit is contained in:
parent
4a1d65aa1f
commit
2d8c7e6837
166
config.sh
166
config.sh
|
@ -1,67 +1,119 @@
|
|||
#!/bin/bash
|
||||
ROOT="$(dirname "$(readlink -e "$0")")"
|
||||
while :; do
|
||||
SELECTION="$(whiptail --menu '' 13 50 7 \
|
||||
autocomplete 'Setup .bash_completion.d' \
|
||||
nodejs 'Install Node.js' \
|
||||
docker 'Setup Docker WSL/Windows relay' \
|
||||
git 'Create .gitconfig/.git-credentials symlinks' \
|
||||
ssh 'Create .ssh symlink' \
|
||||
tmux 'Create .tmux.conf symlink' \
|
||||
win 'Create Windows symlinks' \
|
||||
--title 'Select action' --notags --default-item "$SELECTION" 3>&2 2>&1 1>&3-)"
|
||||
case "$SELECTION" in
|
||||
autocomplete)
|
||||
cd && \
|
||||
mkdir -p .bash_completion.d && \
|
||||
([ -f .bash_completion ] && grep -Fq .bash_completion.d .bash_completion || echo $'for i in ~/.bash_completion.d/*; do\n\t[ -f "$i" ] && . "$i"\ndone' >> .bash_completion) && \
|
||||
whiptail --msgbox Done 7 10
|
||||
ACTION_1="$(whiptail --menu '' 10 50 3 \
|
||||
linux 'General Linux actions...' \
|
||||
symlinks 'Create symlinks to config files...' \
|
||||
wsl 'WSL-specific actions...' \
|
||||
--title 'Select action' --notags --default-item "$ACTION_1" 3>&2 2>&1 1>&3-)"
|
||||
case "$ACTION_1" in
|
||||
linux)
|
||||
while :; do
|
||||
ACTION_2="$(whiptail --menu '' 10 50 3 \
|
||||
2path 'Set up 2path.sh script' \
|
||||
completion 'Set up user-specific ~/.bash_completion.d/' \
|
||||
nodejs 'Install Node.js' \
|
||||
--title 'Select Linux action' --notags --default-item "$ACTION_2" 3>&2 2>&1 1>&3-)"
|
||||
case "$ACTION_2" in
|
||||
2path)
|
||||
"$ROOT"/2path.sh "$ROOT"/2path.sh && \
|
||||
whiptail --msgbox Done 7 10
|
||||
;;
|
||||
completion)
|
||||
cd && \
|
||||
mkdir -p .bash_completion.d && \
|
||||
([ -f .bash_completion ] && grep -Fq .bash_completion.d .bash_completion || echo $'for i in ~/.bash_completion.d/*; do\n\t[ -f "$i" ] && . "$i"\ndone' >> .bash_completion) && \
|
||||
whiptail --msgbox Done 7 10
|
||||
;;
|
||||
nodejs)
|
||||
NODE_VERSION="$(whiptail --inputbox 'Version?' 10 20 3>&2 2>&1 1>&3-)" && \
|
||||
[ "$NODE_VERSION" ] && \
|
||||
cd && \
|
||||
rm -rf nodejs && \
|
||||
mkdir nodejs && \
|
||||
cd nodejs && \
|
||||
wget https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz -O- | tar xJ --strip-components=1 && \
|
||||
(which node || echo 'PATH="$HOME/nodejs/bin:$PATH"' >> ~/.profile) && \
|
||||
whiptail --msgbox Done 7 10
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
;;
|
||||
nodejs)
|
||||
NODE_VERSION="$(whiptail --inputbox 'Version?' 10 20 3>&2 2>&1 1>&3-)" && \
|
||||
[ "$NODE_VERSION" ] && \
|
||||
cd && \
|
||||
rm -rf nodejs && \
|
||||
mkdir nodejs && \
|
||||
cd nodejs && \
|
||||
wget https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz -O- | tar xJ --strip-components=1 && \
|
||||
(which node || echo 'PATH="$HOME/nodejs/bin:$PATH"' >> ~/.profile) && \
|
||||
whiptail --msgbox Done 7 10
|
||||
symlinks)
|
||||
while :; do
|
||||
ACTION_2="$(whiptail --menu '' 10 50 3 \
|
||||
git '.gitconfig and .git-credentials' \
|
||||
ssh '.ssh' \
|
||||
tmux '.tmux.conf' \
|
||||
--title 'Select config symlinks to create' --notags --default-item "$ACTION_2" 3>&2 2>&1 1>&3-)"
|
||||
case "$ACTION_2" in
|
||||
git)
|
||||
cd && \
|
||||
ln -fs "$ROOT"/.gitconfig && \
|
||||
ln -fs "$ROOT"/.git-credentials && \
|
||||
whiptail --msgbox Done 7 10
|
||||
;;
|
||||
ssh)
|
||||
cd && \
|
||||
ln -fs "$ROOT"/.ssh/ && \
|
||||
chmod 600 .ssh/* && \
|
||||
whiptail --msgbox Done 7 10
|
||||
;;
|
||||
tmux)
|
||||
cd && \
|
||||
ln -fs "$ROOT"/.tmux.conf && \
|
||||
whiptail --msgbox Done 7 10
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
;;
|
||||
docker)
|
||||
sudo apt-get install socat && \
|
||||
cd /usr/local/bin && \
|
||||
sudo ln -fs "$ROOT"/npiperelay.exe && \
|
||||
sudo ln -fs "$ROOT"/docker-relay && \
|
||||
sudo adduser $USER docker && \
|
||||
whiptail --msgbox Done 7 10
|
||||
;;
|
||||
git)
|
||||
cd && \
|
||||
ln -fs "$ROOT"/.gitconfig && \
|
||||
ln -fs "$ROOT"/.git-credentials && \
|
||||
whiptail --msgbox Done 7 10
|
||||
;;
|
||||
ssh)
|
||||
cd && \
|
||||
ln -fs "$ROOT"/.ssh && \
|
||||
chmod 600 .ssh/* && \
|
||||
whiptail --msgbox Done 7 10
|
||||
;;
|
||||
tmux)
|
||||
cd && \
|
||||
ln -fs "$ROOT"/.tmux.conf && \
|
||||
whiptail --msgbox Done 7 10
|
||||
;;
|
||||
win)
|
||||
ROOTWIN="$(wslpath -w "$ROOT")" && \
|
||||
(cmd.exe /c del "%USERPROFILE%\.gitconfig" 2> nul; cmd.exe /c mklink "%USERPROFILE%\.gitconfig" "$ROOTWIN\.gitconfig") && \
|
||||
(cmd.exe /c del "%USERPROFILE%\.git-credentials" 2> nul; cmd.exe /c mklink "%USERPROFILE%\.git-credentials" "$ROOTWIN\.git-credentials") && \
|
||||
(cmd.exe /c rmdir "%USERPROFILE%\.ssh" 2> nul; cmd.exe /c mklink /d "%USERPROFILE%\.ssh" "$ROOTWIN\.ssh") && \
|
||||
whiptail --msgbox Done 7 10
|
||||
wsl)
|
||||
while :; do
|
||||
ACTION_2="$(whiptail --menu '' 11 50 4 \
|
||||
win 'Create ~/win symlink to %USERPROFILE%' \
|
||||
hosts 'Create /etc/hosts symlink to system' \
|
||||
docker 'Set up Docker WSL/Windows relay' \
|
||||
windows 'Create Windows symlinks' \
|
||||
--title 'Select WSL action' --notags --default-item "$ACTION_2" 3>&2 2>& 1>&3-)"
|
||||
case "$ACTION_2" in
|
||||
win)
|
||||
cd && \
|
||||
ln -fs "$(wslpath "$(cmd.exe /c echo %USERPROFILE% | tr -d '\r')")"/ win && \
|
||||
whiptail --msgbox Done 7 10
|
||||
;;
|
||||
hosts)
|
||||
sudo ln -fs /c/Windows/System32/drivers/etc/hosts /etc/hosts && \
|
||||
whiptail --msgbox Done 7 10
|
||||
;;
|
||||
docker)
|
||||
sudo apt-get install socat && \
|
||||
cd /usr/local/bin && \
|
||||
sudo ln -fs "$ROOT"/npiperelay.exe && \
|
||||
sudo ln -fs "$ROOT"/docker-relay && \
|
||||
sudo adduser $USER docker && \
|
||||
whiptail --msgbox Done 7 10
|
||||
;;
|
||||
windows)
|
||||
ROOTWIN="$(wslpath -w "$ROOT")" && \
|
||||
(cmd.exe /c del "%USERPROFILE%\.gitconfig" 2\> nul; cmd.exe /c mklink "%USERPROFILE%\.gitconfig" "$ROOTWIN\.gitconfig") && \
|
||||
(cmd.exe /c del "%USERPROFILE%\.git-credentials" 2\> nul; cmd.exe /c mklink "%USERPROFILE%\.git-credentials" "$ROOTWIN\.git-credentials") && \
|
||||
(cmd.exe /c rmdir "%USERPROFILE%\.ssh" 2\> nul; cmd.exe /c mklink /d "%USERPROFILE%\.ssh" "$ROOTWIN\.ssh") && \
|
||||
whiptail --msgbox Done 7 10
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
;;
|
||||
*)
|
||||
exit
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
|
|
@ -6,10 +6,9 @@ if [%~3]==[] goto :missing
|
|||
if [%~4]==[] goto :missing
|
||||
|
||||
LxRunOffline.exe install -n %~3 -d %~2 -f %~1
|
||||
LxRunOffline.exe run -n %~3 -c "/bin/bash -c \"echo $'[automount]\n\troot = /\n\toptions = metadata\n[network]\n\tgenerateHosts = false' ^> /etc/wsl.conf\""
|
||||
LxRunOffline.exe run -n %~3 -c "/bin/bash -c \"rm -r /mnt; ln -fs /c/Windows/System32/drivers/etc/hosts /etc/hosts; adduser %~4; adduser %~4 sudo\""
|
||||
LxRunOffline.exe set-uid -n %~3 -v 1000
|
||||
LxRunOffline.exe run -n %~3 -c "/bin/bash -c \"cd; ln -s $(wslpath $(cmd.exe /c echo %%USERPROFILE%% ^| tr -d '\r')) win\""
|
||||
LxRunOffline.exe run -n %~3 -c "/bin/bash -c \"echo $'[automount]\n\troot = /\n\toptions = metadata\n[network]\n\tgenerateHosts = false' ^> /etc/wsl.conf; chmod 644 /etc/wsl.conf\""
|
||||
LxRunOffline.exe run -n %~3 -c "/bin/bash -c \"rm -r /mnt; adduser %~4; adduser %~4 sudo\""
|
||||
for /f "tokens=*" %%f in ('LxRunOffline.exe run -n %~3 -c "id -u %~4"') do (LxRunOffline.exe set-uid -n %~3 -v %%f)
|
||||
|
||||
goto :end
|
||||
|
||||
|
|
Loading…
Reference in New Issue