| 1 | |
| 2 | |
| 3 | |
| 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 | |
| 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 | |
| 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 ;; |
| 40 | esac |
| 41 | ln_cmd="ln -s /installer/install.sh /usr/bin/doit" |
| 42 | |
| 43 | |
| 44 | if [[ -n "$root" ]]; then |
| 45 | eval "$docker_cmd -c \"$ln_cmd && bash\"" |
| 46 | else |
| 47 | eval "$docker_cmd -c \"$update_cmd && $user_cmd && $ln_cmd && su - test\"" |
| 48 | fi |