-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswitch-os.sh
executable file
·80 lines (65 loc) · 2.14 KB
/
switch-os.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env bash
# OS Switcher
# Run Docker based OS on Host OS
# Inspired by: https://github.com/wurmlab/oswitch
VERSION="17.07.v0.1" ## YY.MM.VV
AUTHOR="Stephen Newhouse <stephen.j.newhouse@gmail.com>"
# select Docker OS
if [[ $# -eq 0 ]]; then
echo -e "
------------------------------------------------------------
[switch-os ]: Seamlessly switch between Os's using Docker
[Version ]: ${VERSION}
------------------------------------------------------------
Available OS's:
- ubuntu:16.04 [ubuntu]
- yeban/biolinux:8 [biolinux]
To use any other image on your machine, just provide <REPOSITORY:TAG>
If image is not already on your system, Docker will pull it from
Docker Hub, if its available.
See Usage below.
Usage:
switch-os.sh <REPOSITORY:TAG> <true|false>
<true|false>: The second flag sets the option to remove the
container on exit.
Set this to false if you make changes to the running image
and wish to commit the changes for future use.
List Images:
switch-os.sh list
eg:
switch-os.sh ubuntu true \n
switch-os.sh ubuntu:16.04-v0.0.1 false\n
------------------------------------------------------------"
exit 1
elif [[ "${1}" == "list" ]]; then
docker images
exit 1
elif [[ $# -gt 1 ]]; then
DOCKER_OS="${1}"
elif [[ "${1}" == "ubuntu" ]]; then
DOCKER_OS="ubuntu:16.04"
elif [[ "${1}" == "biolinux" ]]; then
DOCKER_OS="yeban/biolinux:8"
fi
# set container base name to rep_tag
NAME=$(echo ${1} | sed s/:/_/g )
# run selected Docker OS
CMD="docker run --rm=${2} \
--name ${NAME}_$(date +%y%m%d%M) \
-v ${HOME}:/home/${USER} \
-e USER=${USER} \
-e USERID=${UID} \
-w=/home/${USER} \
-i -t ${DOCKER_OS} /bin/bash"
# print to screen
echo -e "switch-os:${VERSION}
------------------------
Running:${DOCKER_OS}
Setting Container UID: ${UID}
Setting Container USER: ${USER}
Mounting HOST Volume ${HOME} to Container Volume: /home/${USER}
Setting Container WORKDIR: /home/${USER}
Remove Container on Exit (--rm=true|false): ${2}
${CMD}"
# run it
${CMD}