refactor argument parsing

This commit is contained in:
Frieder Schlesier 2018-06-02 17:17:16 +02:00
parent 34499ac38c
commit a038dc96be
1 changed files with 32 additions and 31 deletions

View File

@ -2,7 +2,7 @@
set -e
# install.sh
# This script installs my basic setup for a debian laptop
# This script installs my basic setup for a debian machine
USERNAME=fschl
@ -68,7 +68,6 @@ base_applications() {
}
install_server_base() {
echo "update and installing server base tools..."
DEBIAN_FRONTEND=noninteractive
@ -244,7 +243,6 @@ install_golang() {
go get golang.org/x/tools/cmd/goimports
go get golang.org/x/tools/cmd/gorename
go get github.com/FiloSottile/vendorcheck
go get github.com/nsf/gocode
#done
)
@ -310,36 +308,39 @@ main() {
local cmd=$1
if [[ -z "$cmd" ]]; then
echo "Usage: \n base | desktop | server | dotfiles | compose | go"
echo "Usage: \n base | desktop | server | dotfiles | update-docker | go"
fi
# TODO: refactor to case
if [[ $cmd == "compose" ]]; then
install_compose
elif [[ $cmd == "base" ]]; then
apt_sources
base_applications
install_docker
install_compose
elif [[ $cmd == "docker" ]]; then
install_docker
elif [[ $cmd == "dotfiles" ]]; then
get_dotfiles
elif [[ $cmd == "go" ]]; then
install_golang
elif [[ $cmd == "goprojects" ]]; then
get_public_go_projects
elif [[ $cmd == "server" ]]; then
install_server_base
elif [[ $cmd == "desktop" ]]; then
install_i3
if [ -f "./get_private_stuff.sh" ]; then
source get_private_stuff.sh
fi
fi
case "$cmd" in
base)
apt_sources
base_applications
install_docker
sudo groupadd docker
sudo adduser -aG docker "$USERNAME"
install_compose
;;
dotfiles)
get_dotfiles
;;
server)
install_server_base
;;
desktop)
install_i3
if [ -f "./get_private_stuff.sh" ]; then
source get_private_stuff.sh
fi
;;
update-docker)
# install_docker
install_compose
;;
go)
install_golang
get_public_go_projects
;;
esac
}
main "$@"