refactor(script/bootstrap): Allow pre-bootstrap
to be ran
automatically by `bootstrap` This will simplify the process of installing the dotfiles while still giving users control
This commit is contained in:
parent
c212f09fe3
commit
a843e5236a
3 changed files with 55 additions and 21 deletions
26
bootstrap
26
bootstrap
|
@ -1,6 +1,23 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
[ $ZI_DOTFILES ] || { >&2 echo "Please run pre-bootstrap first!"; exit 1; }
|
[ $ZI_DOTFILES ] && {
|
||||||
|
. $ZI_DOTFILES/common
|
||||||
|
} || {
|
||||||
|
[ -f ./common ] || { >&2 echo "Bootstrap should be ran directly from dotfiles directory ('./bootstrap'), or run './pre-bootstrap' before running bootstrap!"; exit 1; }
|
||||||
|
. ./common
|
||||||
|
}
|
||||||
|
|
||||||
|
[ $ZI_DOTFILES ] || {
|
||||||
|
ZI_DOTFILES=$PWD
|
||||||
|
echo "'./pre-bootstrap' was never ran before. This script will store '$PWD' in \$ZI_DOTFILES as helper variable for automation scripts."
|
||||||
|
prompt "Run it now? [y/N] " || { >&2 echo "You need to run './pre-bootstrap' before running bootstrap!"; exit 1; }
|
||||||
|
echo "======include/dotfiles======"
|
||||||
|
./pre-bootstrap -
|
||||||
|
echo "============================"
|
||||||
|
prompt "Set '$PWD' as dotfiles directory? [y/N] " || exit 1
|
||||||
|
./pre-bootstrap - > $ZI_DOTFILES/.config/zsh/include/dotfiles
|
||||||
|
}
|
||||||
|
|
||||||
[ -d $ZI_DOTFILES ] || { >&2 echo "Invalid dotfiles path, please re-run pre-bootstrap!"; exit 1; }
|
[ -d $ZI_DOTFILES ] || { >&2 echo "Invalid dotfiles path, please re-run pre-bootstrap!"; exit 1; }
|
||||||
|
|
||||||
. $ZI_DOTFILES/bootstrap-pkgs
|
. $ZI_DOTFILES/bootstrap-pkgs
|
||||||
|
@ -91,7 +108,10 @@ ln -si $ZI_DOTFILES/.config/zsh $HOME/.config/zsh
|
||||||
echo "Configuring doas..."
|
echo "Configuring doas..."
|
||||||
echo """permit persist :wheel
|
echo """permit persist :wheel
|
||||||
permit nopass root as root""" > /tmp/doas.conf.tmp
|
permit nopass root as root""" > /tmp/doas.conf.tmp
|
||||||
echo "======doas.conf======"
|
echo "=======/etc/doas.conf======="
|
||||||
cat /tmp/doas.conf.tmp
|
cat /tmp/doas.conf.tmp
|
||||||
echo "====================="
|
echo "============================"
|
||||||
$SUDO cp -i /tmp/doas.conf.tmp /etc/doas.conf
|
$SUDO cp -i /tmp/doas.conf.tmp /etc/doas.conf
|
||||||
|
|
||||||
|
echo "============================"
|
||||||
|
echo "Bootstrap completed, please restart your shell!"
|
||||||
|
|
10
common
Normal file
10
common
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
prompt() {
|
||||||
|
printf "$1"
|
||||||
|
read INPUT
|
||||||
|
case $INPUT in
|
||||||
|
[yY] ) return 0 ;;
|
||||||
|
* ) return 1 ;;
|
||||||
|
esac;
|
||||||
|
}
|
|
@ -1,29 +1,33 @@
|
||||||
#!/bin/zsh
|
#!/bin/sh
|
||||||
|
|
||||||
|
. ./common
|
||||||
|
|
||||||
[ "$1" = "-" ] || {
|
[ "$1" = "-" ] || {
|
||||||
printf "Experimental script! Run it anyway? (y/N) ";
|
prompt 'Experimental script! Run it anyway? [y/N] ' || exit 1
|
||||||
read choice;
|
|
||||||
[ "$choice" = "y" ] || exit 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "$(cat README.md | head -n 1)" = "<!-- ZI-DOTFILES -->" ] || {
|
[ "$(cat README.md | head -n 1)" = "<!-- ZI-DOTFILES -->" ] || {
|
||||||
>&2 echo "Current working directory is not the dotfiles is located!";
|
>&2 echo "Current working directory is not the dotfiles is located!"
|
||||||
>&2 echo "Please 'cd' to the dotfiles directory before running the script.";
|
>&2 echo "Please 'cd' to the dotfiles directory before running the script."
|
||||||
exit 1;
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
info="""
|
echo_info() {
|
||||||
########################################################################
|
echo "########################################################################"
|
||||||
# Please replace '~/.config/zsh/include/dotfiles' with the code above. #
|
echo "# Please replace '~/.config/zsh/include/dotfiles' with the code above. #"
|
||||||
# TIPS: Run './pre-bootstrap - > ~/.config/zsh/include/dotfiles' #
|
echo "# TIPS: Run './pre-bootstrap - > ~/.config/zsh/include/dotfiles' #"
|
||||||
########################################################################
|
echo "########################################################################"
|
||||||
"""
|
}
|
||||||
|
|
||||||
|
echo_config() {
|
||||||
echo "#!/bin/zsh"
|
echo "#!/bin/zsh"
|
||||||
echo $info
|
[ "$1" = "-" ] || echo_info
|
||||||
|
|
||||||
echo """export ZI_DOTFILES="${PWD}"
|
echo "export ZI_DOTFILES=\"${PWD}\""
|
||||||
|
echo ""
|
||||||
|
echo "[ ! \$ZI_DOTFILES ] && unset ZI_DOTFILES"
|
||||||
|
|
||||||
[ ! \$ZI_DOTFILES ] && unset ZI_DOTFILES"""
|
[ "$1" = "-" ] || echo_info
|
||||||
|
}
|
||||||
|
|
||||||
echo $info
|
echo_config $1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue