forked from karmab/kcli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·97 lines (90 loc) · 4.58 KB
/
install.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/bash
# set some printing colors
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;36m'
NC='\033[0m'
shell=$(basename $SHELL)
packagefound=false
if [ "$(which dnf)" != "" ] ; then
packagefound=true
echo -e "${BLUE}Installing using copr package${NC}"
sudo dnf -y copr enable karmab/kcli
sudo dnf -y install kcli
if [ "$?" != "0" ] ; then
echo -e "${RED}Package installation didnt work${NC}"
exit 1
fi
elif [ "$(which apt-get)" != "" ] ; then
packagefound=true
echo -e "${BLUE}Installing using deb package${NC}"
grep -q Pop /etc/lsb-release && EXTRA="distro=ubuntu"
curl -1sLf https://dl.cloudsmith.io/public/karmab/kcli/cfg/setup/bash.deb.sh | sudo -E $EXTRA bash
sudo apt-get update
sudo apt-get -y install python3-kcli
if [ "$?" != "0" ] ; then
echo -e "${RED}Package installation didnt work${NC}"
exit 1
fi
fi
if [ "$packagefound" == "true" ] ; then
echo -e "${GREEN}kcli installed${NC}"
echo -e "${BLUE}Consider installing completion by following https://kcli.readthedocs.io/#auto-completion${NC}"
exit 0
fi
engine=""
which docker >/dev/null 2>&1 && engine="docker"
which podman >/dev/null 2>&1 && engine="podman"
if [ "$engine" == "" ] ; then
echo -e "${BLUE}No container engine found nor compatible package manager. Install podman or docker first${NC}"
exit 1
else
echo -e "${BLUE}Using engine $engine ${NC}"
fi
alias kcli >/dev/null 2>&1
ALIAS="$?"
if [ "$ALIAS" != "0" ]; then
echo -e "${BLUE}Installing container alias ${NC}"
$engine pull quay.io/karmab/kcli:latest
SSHVOLUME="-v $(realpath $HOME/.ssh):/root/.ssh"
if [ -d /var/lib/libvirt/images ] && [ -d /var/run/libvirt ]; then
VOLUMES="-v /var/lib/libvirt/images:/var/lib/libvirt/images -v /var/run/libvirt:/var/run/libvirt"
fi
[ -d $HOME/.kcli ] || mkdir -p $HOME/.kcli
[ -d $HOME/.ssh ] || ssh-keygen -t rsa -N '' -f $HOME/.ssh/id_rsa
echo -e '#/bin/bash\n'$engine run -p 9000:9000 --net host -it --rm --security-opt label=disable -v $HOME/.kcli:/root/.kcli $SSHVOLUME $VOLUMES '-v $PWD:/workdir --entrypoint=/usr/local/bin/klist.py quay.io/karmab/kcli' > $HOME/klist.py
case $shell in
bash|zsh)
shellfile="$HOME/.bashrc"
[ "$shell" == zsh ] && shellfile="$HOME/.zshrc"
grep -q kcli= $shellfile || echo alias kcli=\'$engine run --net host -it --rm --security-opt label=disable -v $HOME/.kcli:/root/.kcli $SSHVOLUME $VOLUMES '-v $PWD:/workdir quay.io/karmab/kcli'\' >> $shellfile
grep -q kclishell= $shellfile || echo alias kclishell=\'$engine run --net host -it --rm --security-opt label=disable -v $HOME/.kcli:/root/.kcli $SSHVOLUME $VOLUMES '-v $PWD:/workdir --entrypoint=/bin/sh quay.io/karmab/kcli'\' >> $shellfile
grep -q kcliweb= $shellfile || echo alias kweb=\'$engine run -p 9000:9000 --net host -it --rm --security-opt label=disable -v $HOME/.kcli:/root/.kcli $SSHVOLUME $VOLUMES '-v $PWD:/workdir --entrypoint=/usr/local/bin/kweb quay.io/karmab/kcli'\' >> $shellfile
alias kcli="$engine run --net host -it --rm --security-opt label=disable -v $HOME/.kcli:/root/.kcli $SSHVOLUME $VOLUMES -v $PWD:/workdir quay.io/karmab/kcli"
;;
fish)
shellfile="$HOME/.config/fish/config.fish"
[ ! -d ~/.config/fish ] && mkdir -p ~/.config/fish
grep -q 'kcli ' $shellfile || echo alias kcli $engine run --net host -it --rm --security-opt label=disable -v $HOME/.kcli:/root/.kcli $SSHVOLUME $VOLUMES '-v $PWD:/workdir quay.io/karmab/kcli' >> $shellfile
grep -q kclishell $shellfile || echo alias kclishell $engine run --net host -it --rm --security-opt label=disable -v $HOME/.kcli:/root/.kcli $SSHVOLUME $VOLUMES '-v $PWD:/workdir --entrypoint=/bin/sh quay.io/karmab/kcli' >> $shellfile
grep -q kcliweb $shellfile || echo alias kweb $engine run -p 9000:9000 --net host -it --rm --security-opt label=disable -v $HOME/.kcli:/root/.kcli $SSHVOLUME $VOLUMES '-v $PWD:/workdir --entrypoint=/usr/local/bin/kweb quay.io/karmab/kcli' >> $shellfile
alias kcli $engine run --net host -it --rm --security-opt label=disable -v $HOME/.kcli:/root/.kcli $SSHVOLUME $VOLUMES -v $PWD:/workdir quay.io/karmab/kcli
;;
*)
echo -e "${RED}Installing aliases for $shell is not supported ${NC}"
;;
esac
shopt -s expand_aliases
VERSION=$(kcli -v)
echo -e """${GREEN}Installed kcli $VERSION
Launch a new shell for aliases kcli, kclishell and kweb to work${NC}"""
else
echo -e "${BLUE}Skipping already installed kcli${NC}"
fi
if [ "$(id -u)" != "0" ] && [ -d /var/lib/libvirt/images ] && [ -d /var/run/libvirt ]; then
echo -e """${BLUE}Make sure you have libvirt access from your user by running:
sudo usermod -aG qemu,libvirt $(id -un)
newgrp qemu
newgrp libvirt
sudo setfacl -m u:$(id -un):rwx /var/lib/libvirt/images${NC}"""
fi