aboutsummaryrefslogtreecommitdiffhomepage
path: root/installer.sh
blob: fc544f6649b6464b110086d416aa9c11877865cf (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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash

################################################ SETUP ################################################
deps=(libasound2-dev libevdev-dev liblua5.3-dev libjack-jackd2-dev pkg-config libssl-dev gcc make wget git)
user=$(whoami)                  # for bypassing user check replace "$(whoami)" with "root".

script_path="`cd $0; pwd`"      # Script dir
tmp_path=$(mktemp -d)           # Repo download path

Iversion="TEST!"                 # (fallback version if )
makeargs=all                    # Build args

VAR_DESTDIR=""                  # Unused
VAR_PREFIX="/usr"
VAR_PLUGINS="$VAR_PREFIX/lib/midimonster"
VAR_DEFAULT_CFG="/etc/midimonster/midimonster.cfg"
VAR_EXAMPLE_CFGS="$VAR_PREFIX/share/midimonster"

################################################ SETUP ################################################

############################################## FUNCTIONS ##############################################

INSTALL-DEPS () {           ##Install deps from array "$deps"
for t in ${deps[@]}; do
    if [ $(dpkg-query -W -f='${Status}' $t 2>/dev/null | grep -c "ok installed") -eq 0 ];
    then
        echo "Installing "$t"";
        apt-get install $t;
        echo "Done.";
    else
        echo ""$t" already installed!"

    fi
done
echo ""
}

INSTALL-PREP () {
    echo "Starting Git!"
    git clone https://github.com/cbdevnet/midimonster.git "$tmp_path" # Gets Midimonster
    
(
    echo ""
    echo ""
    cd $tmp_path
    echo "IVer.: $Iversion"

    echo "Start GIT INIT"
    git init $tmp_path
    
    echo "IVer.: $Iversion VOR GIT DESCRIBE!"
    echo ""


    echo "Starting git describe.."
    Iversion=$(git describe --abbrev=0)                            # Get last tag(stable version)
    echo "IVer.: $Iversion NACH GIT DESCRIBE!"
    
    echo ""

    
    echo "Starting Git checkout to "$Iversion""
    git checkout $Iversion
 )   
    echo ""
    echo "Done. (Iver.: $Iversion)"
    
    
    
    echo ""

    read -e -i "$VAR_PREFIX" -p "PREFIX (Install root directory): " input # Reads VAR_PREFIX
    VAR_PREFIX="${input:-$VAR_PREFIX}"

    read -e -i "$VAR_PLUGINS" -p "PLUGINS (Plugin directory): " input # Reads VAR_PLUGINS
    VAR_PLUGINS="${input:-$VAR_PLUGINS}"

    read -e -i "$VAR_DEFAULT_CFG" -p "Default config path: " input # Reads VAR_DEFAULT_CFG
    VAR_DEFAULT_CFG="${input:-$VAR_DEFAULT_CFG}"

    read -e -i "$VAR_EXAMPLE_CFGS" -p "Example config directory: " input # Reads VAR_EXAMPLE_CFGS
    VAR_EXAMPLE_CFGS="${input:-$VAR_EXAMPLE_CFGS}"


    export PREFIX=$VAR_PREFIX
    export PLUGINS=$VAR_PLUGINS
    export DEFAULT_CFG=$VAR_DEFAULT_CFG
    export DESTDIR=$VAR_DESTDIR
    export EXAMPLES=$VAR_EXAMPLE_CFGS
}

INSTALL-RUN () {                                    # Build
    cd "$tmp_path"
    make clean
    make $makeargs
    make install
}

ERROR () {
    echo "Aborting..."
    CLEAN
    exit 1
}

DONE () {
    echo Done.
    CLEAN
    exit 0
}

CLEAN () {
    echo "Cleaning..."
    rm -rf $tmp_path
}

############################################## FUNCTIONS ##############################################


################################################ Main #################################################

trap ERROR SIGINT SIGTERM SIGKILL
clear

if [ $user != "root" ]; then echo "Installer must be run as root"; ERROR; fi    # Check if $user = root!

if [ $(wget -q --spider http://github.com) $? -eq 0 ]; then "INSTALL-DEPS"; else echo You need connection to the internet; ERROR ; fi

INSTALL-PREP
echo ""
INSTALL-RUN
DONE