summarylogtreecommitdiffstats
path: root/skywire.install
blob: 690baa2b7298d6b04d40497e11e2b7ef63a2ba19 (plain)
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
post_install() {
  systemctl disable --now skywire-hypervisor.service
  systemctl disable --now skywire-visor.service
  skywire-halt

  skywire-cli visor gen-config -ro /etc/skywire-visor.json
  if pacman -Qi hypervisorconfig > /dev/null ; then
    local hvisorkey=$(cat /usr/lib/skycoin/skywire/hypervisor.txt)
    echo "Setting hypervisor key to $hvisorkey"
  else
    skywire-hypervisor gen-config -ro /etc/skywire-hypervisor.json
    local hvisorkey=$(cat /etc/skywire-hypervisor.json | grep "public_key" | awk '{print substr($2,2,66)}')
    echo "Setting hypervisor key to $hvisorkey"
    #setting key and cert in hypervisor config file
    sed -i 's+"enable_tls": false,+"enable_tls": true,+g' /etc/skywire-hypervisor.json
    sed -i 's+"tls_cert_file": "",+"tls_cert_file": "/etc/skywire-hypervisor/cert.pem",+g' /etc/skywire-hypervisor.json
    sed -i 's+"tls_key_file": ""+"tls_key_file": "/etc/skywire-hypervisor/key.pem"+g' /etc/skywire-hypervisor.json
    echo "Starting hypervisor on 127.0.0.1:8000"
    systemctl enable --now skywire-hypervisor.service
  fi
  sed -i 's/"hypervisors".*/"hypervisors": [{"public_key": "'"${hvisorkey}"'"}],/' /etc/skywire-visor.json
  ISO_USER="$(cat /etc/passwd | grep "/home" |cut -d: -f1 |head -1)"
  su -c "rm -rf ~/.cache/yay/hypervisorconfig/" $ISO_USER
  su -c "mkdir -p ~/.cache/yay/hypervisorconfig" $ISO_USER
  su -c "cp -b /usr/lib/skycoin/skywire/hypervisorconfig/PKGBUILD ~/.cache/yay/hypervisorconfig/PKGBUILD" $ISO_USER
  su -c "echo $hvisorkey > ~/.cache/yay/hypervisorconfig/hypervisor.txt" $ISO_USER
  su -c "cd ~/.cache/yay/hypervisorconfig/ && makepkg -f" $ISO_USER
  cp -b /home/$ISO_USER/.cache/yay/hypervisorconfig/*.pkg.tar.* /usr/lib/skycoin/skywire/
  echo "Starting visor"
  systemctl enable --now skywire-visor.service

  #if pacman -Qi readonly-cache > /dev/null ; then
  #  systemctl enable --now readonly-cache.service
  #fi
}

pre-upgrade() {
systemctl disable --now skywire-hypervisor.service
systemctl disable --now skywire-visor.service
skywire-halt
}

post_upgrade() {
post_install
}

pre-remove() {
  systemctl disable --now skywire-hypervisor.service
  systemctl disable --now skywire-visor.service
  skywire-halt
}

post_remove() {
rm -rf /etc/skywire-hypervisor.json /etc/skywire-visor.json /usr/lib/skycoin/skywire
}