-
Notifications
You must be signed in to change notification settings - Fork 1
/
wallet.sh
96 lines (82 loc) · 2.43 KB
/
wallet.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
#!/bin/sh
set -e
install_docker() {
curl -fsSL https://get.docker.com -o /tmp/get-docker.sh
sh /tmp/get-docker.sh
sudo usermod -aG docker $USER
echo "... Log out and log back so that your group membership is re-evaluated!"
}
install_dependencies() {
echo "Installing dependencies (jq and curl) ..."
sudo apt-get update
sudo apt-get install -y jq curl
}
install_coin() {
echo "\nSetting up coin wallet ..."
sudo curl -fsSL -o /usr/local/bin/${COIN} \
https://raw.githubusercontent.com/fentas/crypto/master/${COIN}/wallet/bin/${COIN}
sudo chmod +x /usr/local/bin/${COIN}
echo "✔ ${COIN} executable"
# Install desktop shortcut
if [ -d /usr/share/applications ]; then
sudo curl -fsSL -o /usr/share/applications/${COIN}.desktop \
https://raw.githubusercontent.com/fentas/crypto/master/${COIN}/wallet/${COIN}.desktop
sudo chmod +x /usr/share/applications/${COIN}.desktop
echo "✔ Desktop shortcut (1/2)"
sudo mkdir -p /usr/share/icons/hicolor/256x256/crypto/
sudo curl -fsSL -o /usr/share/icons/hicolor/256x256/crypto/${COIN}.png \
https://raw.githubusercontent.com/fentas/crypto/master/${COIN}/${COIN}.png
echo "✔ Desktop shortcut (2/2)"
fi
}
list_coins() {
curl -s https://api.github.com/repos/fentas/crypto/contents/ \
| jq -rc '. | map(select(.type == "dir")) | .[].name' \
| grep -v '^_'
}
contains () {
local e match="$1"
shift
for e; do [ "$e" = "$match" ] && return 0; done
return 1
}
choose_coin() {
local coins
coins="$(list_coins)"
until contains "${COIN}" ${coins}; do
echo "You need to choose a coin from the list"
printf '$ %s\n' ${coins}
echo -n "Select coin: "
IFS= read -r COIN
done
}
pull_docker_image() {
local image
image="$(cat /usr/local/bin/${COIN} | grep 'fentas/crypto:' | tr -d ' ')"
docker pull "${image}"
}
# Check if jq exists
if ! ( [ -x "$(command -v jq)" ] && [ -x "$(command -v curl)" ] ); then
install_dependencies
fi
# Check if docker exists
if ! [ -x "$(command -v docker)" ]; then
install_docker
fi
# Choose coin
export COIN
if [ -z "${COIN}" ]; then
choose_coin
fi
# Everything is set to install coin wallet
install_coin
# Give docker the rights to access the X-Server
if [ -x "$(command -v xhost)" ]; then
xhost +local:docker
fi
# Pull docker image directly for transparancy
pull_docker_image
echo "✔ All done"
echo
echo "# Add the following either to your ~/.profile or ~/.bashrc"
echo "xhost +local:docker"