aboutsummaryrefslogtreecommitdiff
path: root/bin/luxcena-neo-cli.sh
blob: 034d713ed7e66e317403abc5545980a12053a0b7 (plain) (blame)
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
#!/bin/bash

usage() {
    printf "Usage: $0 update/uninstall/start/stop\n" 1>&2
    exit 1
}

while getopts ":a:" o; do
    case "${o}" in
        a )
            p=${OPTARG}
            ;;
        *)
            usage
            ;;
    esac
done
shift $((OPTIND-1))

action=$1
if [ "$action" == "update" ]; then

  tput rev
  printf '%s\n' "Luxcena-neo Updater"
  tput sgr0
  printf '\e[93m%s\e[0m\n\n' "-------------------"

  sudo systemctl stop lxucena-neo
  oldDir=$PWD
  cd ~/luxcena-neo-install
  git pull
  export NODE_ENV=production
  npm i --only=production
  cd $oldDir
  sudo systemctl start luxcena-neo

elif [ "$action" == "uninstall" ]; then
    tput setab 1
    printf '%s\n' "Luxcena Neo Uninstaller..."
    tput sgr0
    printf '\e[93m%s\e[0m\n' "--------------------------"
    tput setaf 8
    printf "By uninstalling Luxcena-Neo you will loose all you data, including your scripts.\n\n"

    tput sc
    tput setaf 4
    printf ". Are you sure you want to uninstall (y/n)? "
    while :
    do
        read -n 1 -p "" YNQuestionAnswer
        if [[ $YNQuestionAnswer == "y" ]]; then
            tput rc; tput el
            printf ". Are you sure you want to uninstall? \e[0;32mYes\e[0m\n"
            tput sc
            sudo systemctl stop luxcena-neo || { printf "\n\nUninstall failed.\n"; exit 1; }
            rm -rf ~/luxcena-neo-install || { printf "\n\nUninstall failed.\n"; exit 1; }
            sudo rm /etc/systemd/system/luxcena-neo.service || { printf "\n\nUninstall failed.\n"; exit 1; }
            tput rc; tput ed

            tput setaf 2
            printf "\nEverything should now be gone. To remove the last piece, enter this command:\n"
            tput sgr0
            tput smso
            printf "sudo rm /bin/luxcena-neo\n\n"
            tput sgr0
            tput setaf 8
            printf "Well, some dependencies still exists. Those are:\n"
            printf " - rpi_ws281x-library\n"
            printf " - packages (nodejs scons python-dev swig)\n"
            break
        elif [[ $YNQuestionAnswer == "n" ]]; then
            tput rc; tput el
            printf ". Are you sure you want to uninstall? \e[0;31mNo\e[0m\n"
            break
        fi
    done

elif [ "$action" == "start" ]; then
    sudo systemctl start luxcena-neo
elif [ "$action" == "stop" ]; then
    sudo systemctl stop luxcena-neo
else
    usage
fi