#!/bin/bash
pkg_path=http://aos-np-prod-1:aos-np-prod-1@git.eshift.org/AoS_Digital_Health_Platform/aos-homer-ke-prod.git

## Update Alpine to latest things and make good to work with docker.
apk update;apk upgrade --update-cache --available
apk add --no-cache bash

## Core AoS things we want on this kind of lxc
apk add sed attr dialog bash bash-completion grep
apk add util-linux binutils findutils readline
apk add lsof less nano curl glances
apk add openssh
apk add procps

rc-update add sshd
rc-service sshd start
rc-service sshd status

apk add nodejs npm
apk add xsel
apk add yarn
apk add git
yarn global add serve


adduser -D -g 'AoS Dashboard' --shell /bin/ash homer
su -c "cd /home/homer; git clone $pkg_path /home/homer/aos-dashboard" -s /bin/sh homer


cat > /etc/crontabs/root << 'EOF'
# do daily/weekly/monthly maintenance
# min   hour    day     month   weekday command
*/15    *       *       *       *       run-parts /etc/periodic/15min
0       *       *       *       *       run-parts /etc/periodic/hourly
0       2       *       *       *       run-parts /etc/periodic/daily
0       3       *       *       6       run-parts /etc/periodic/weekly
0       5       1       *       *       run-parts /etc/periodic/monthly
@reboot su -c "cd /home/homer/aos-dashboard/homer && /usr/bin/npx serve --no-clipboard 2>&1 > /dev/null &" -s /bin/sh homer
0 0 * 0 0 su -c "cd /home/homer/aos-dashboard/homer && git pull 2>&1 > /dev/null &" -s /bin/sh homer 
EOF
chmod 600 /etc/crontabs/root