irongit
dotzsh/install_test.sh
48 lines1.7 KBBourne Again Shell (bash)
1#!/bin/bash
2
3# Usage statement
4usage="\e[37musage: install_test.sh [arch|ubuntu]
5
6Spins up a docker image for arch or ubuntu with the current directory as a volume in '/installer'.
7It links the install script at '/installer/install.sh' to '/usr/bin/doit' for convience. Just run
8'doit' within the image to run the installer.
9
10Options:
11 --root,-r Should the image be ran in root. If not set, a test user with the password
12 test is set as current shell.
13\e[0m"
14
15# Gather arguments
16for var in "$@"; do
17 case "$var" in
18 --root) root=1 ;;
19 -r) root=1 ;;
20 ubuntu) os="ubuntu" ;;
21 arch) os="arch" ;;
22 -h) printf "$usage" && exit 1 ;;
23 --help) printf "$usage" && exit 1 ;;
24 esac
25done
26
27# Create command pieces
28case "$os" in
29ubuntu)
30 docker_cmd="docker run --rm -v $(pwd):/installer -w /installer -it ubuntu bash"
31 update_cmd="apt update -y && apt install sudo -y"
32 user_cmd="useradd test -m && echo test:test | chpasswd && usermod -aG sudo test && ln -s /installer/install.sh /bin/doit && su - test"
33 ;;
34arch)
35 docker_cmd="docker run --rm -v $(pwd):/installer -w /installer -it archlinux bash "
36 update_cmd="pacman --noconfirm -Syu && pacman -S sudo --noconfirm"
37 user_cmd="useradd test -m && usermod -aG wheel test && echo test:test | chpasswd && sed -i 's/# %wheel ALL=(ALL:ALL) ALL/%wheel ALL=(ALL:ALL) ALL/' /etc/sudoers"
38 ;;
39*) printf "$usage" && exit 1 ;;
40esac
41ln_cmd="ln -s /installer/install.sh /usr/bin/doit"
42
43# Start the docker image
44if [[ -n "$root" ]]; then # Create symlink and start bash
45 eval "$docker_cmd -c \"$ln_cmd && bash\""
46else # Create sudo user test:test and su - test
47 eval "$docker_cmd -c \"$update_cmd && $user_cmd && $ln_cmd && su - test\""
48fi