irongit

feat: install test can choose root or test user

huncholanehuncholaneauthored
parent 00c4763commit 8df39e99456489378e919e2df4289031f29a407dBrowse files

1 file changed, +45 -9

+45-9install_test.sh
@@ -1,12 +1,48 @@
11 #!/bin/bash
22
3-case "$1" in
4-"ubuntu") docker run --rm -v "$(pwd):/installer" -w /installer -it ubuntu bash -c "
5- apt update -y && apt install sudo -y && useradd test -m && echo test:test | chpasswd && usermod -aG sudo test &&
6- ln -s /installer/install.sh /bin/doit && su - test" ;;
7-"arch") docker run --rm -v "$(pwd):/installer" -w /installer -it archlinux bash -c "
8- pacman --noconfirm -Syu && pacman -S sudo --noconfirm && useradd test -m && usermod -aG wheel test &&
9- echo test:test | chpasswd && sed -i 's/# %wheel ALL=(ALL:ALL) ALL/%wheel ALL=(ALL:ALL) ALL/' /etc/sudoers &&
10- ln -s /installer/install.sh /bin/doit && su - test" ;;
11-*) echo "usage: install_test.sh [ubuntu|arch]"
3+# Usage statement
4+usage="\e[37musage: install_test.sh [arch|ubuntu]
5+
6+Spins up a docker image for arch or ubuntu with the current directory as a volume in '/installer'.
7+It 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+
10+Options:
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
16+for 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
25+done
26+
27+# Create command pieces
28+case "$os" in
29+ubuntu)
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+ ;;
34+arch)
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 ;;
1240 esac
41+ln_cmd="ln -s /installer/install.sh /usr/bin/doit"
42+
43+# Start the docker image
44+if [[ -n "$root" ]]; then # Create symlink and start bash
45+ eval "$docker_cmd -c \"$ln_cmd && bash\""
46+else # Create sudo user test:test and su - test
47+ eval "$docker_cmd -c \"$update_cmd && $user_cmd && $ln_cmd && su - test\""
48+fi