~aleteoryx/muditaos

ref: sign_test muditaos/config/bootstrap.sh -rwxr-xr-x 5.8 KiB
a217eeb3 — Dawid Wojtas [BH-2024] Fix lack of alarm directory after updating software 1 year, 5 months ago
                                                                                
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/bin/bash -e
# Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
# For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#####################################################################
#
#                   !!! WARNING !!!
#
# this script was written for `raw` ubuntu 18.10 64b
# optionally consider installing ccache:
#     `sudo apt install ccache`
# it's support is added to default ccache

# packages settings
SCRIPT=$(readlink -f $0)
SCRIPT_DIR="$(dirname ${SCRIPT})"

. ${SCRIPT_DIR}/bootstrap_config
. ${SCRIPT_DIR}/common_scripts_lib

function test_if_run_as_root() {
    echo -e "\e[32m${FUNCNAME[0]}\e[0m"
    MY_NAME=$(whoami)
    if [[ "${MY_NAME}" == "root" ]]; then
        cat <<-MSGEND
			Please do not run this script as a root.
			Script will ask for your password for tasks it needs
			to run as a root (sudo ...)
			MSGEND
        exit 1
    fi
}
function add_to_path() {
    echo -e "\e[32m${FUNCNAME[0]} $1 $2\e[0m"
    TOOL_NAME=$1
    TOOL_DIR=$2
    BASH_RC="${HOME}/.bashrc"
    TOOL_PATH_VAR="${TOOL_NAME}_PATH"
    set +e
    check_if_exists="`cat ${BASH_RC} | grep \"${TOOL_PATH_VAR}\"`"
    set -e

    if [[ -n ${check_if_exists} ]]; then
        SED_SCRIPT="s%${TOOL_PATH_VAR}=\".*\"%${TOOL_PATH_VAR}=\"${TOOL_DIR}\"%"
        sed -e "$SED_SCRIPT" -i ${BASH_RC}
    else
        echo "export ${TOOL_PATH_VAR}=\"${TOOL_DIR}\"" >> ${BASH_RC}
        echo "PATH=\"\${${TOOL_PATH_VAR}:+\${${TOOL_PATH_VAR}}:}\${PATH}\"" >> ${BASH_RC}
    fi
}
function install_hooks(){
    echo -e "\e[32m${FUNCNAME[0]}\e[0m"
    cat <<-MSGEND
		Install style checking hooks
		by default hook is reporting error only
		if you would like to make it automatically fix style errors add config "user.fixinstage" to your git configuration:
		    git config user.fixinstage true
		MSGEND
    HOOK="pre-commit.hook"

    L_GIT_DIR=$(git rev-parse --show-toplevel)
    ln -sf ${L_GIT_DIR}/config/${HOOK} ${L_GIT_DIR}/.git/hooks/pre-commit
}

function add_ignore_revs_for_blame() {
    echo -e "\e[32m${FUNCNAME[0]}\e[0m"
    git config blame.ignoreRevsFile .gitblameignorerevs
}

function setup_gcc_alternatives() {
    echo -e "\e[32m${FUNCNAME[0]}\e[0m"
    cat <<-MSGEND
		# set gcc-10 as default alternative (instead of default current in ubuntu)
		sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 1000 --slave /usr/bin/g++ g++ /usr/bin/g++-10
		MSGEND
    sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 1000 --slave /usr/bin/g++ g++ /usr/bin/g++-10
}

function install_pip_packages() {
    echo -e "\e[32m${FUNCNAME[0]}\e[0m"
    pip3 install -r ${SCRIPT_DIR}/requirements.txt
    pip3 install -r ${SCRIPT_DIR}/../test/requirements.txt
}

function install_ubuntu_packages() {
    echo -e "\e[32m${FUNCNAME[0]}\e[0m"
    cat <<-MSGEND
		# Install necessary packages
		MSGEND
    echo "This will change your system, press CTRL+C if you do not want to install required packages, or press enter to continue..."
    read asdfasraewrawesjr
    INSTALL_PACKAGES=$( echo "${INSTALL_PACKAGES}" | tr "\n" " "|tr -s " ")
    sudo apt-get update
    sudo apt-get install ${INSTALL_PACKAGES}
    setup_gcc_alternatives
    install_pip_packages
}

function setup_arm_toolchain() {
    echo -e "\e[32m${FUNCNAME[0]}\e[0m"
    pushd /tmp
    echo "Download armgcc"
    [[ ! -f $ARM_GCC ]] &&
        getArmCC
    # untar to HOME
    if [[ ! -d ${HOME}/${ARM_GCC} ]]; then
        echo "extracting: ${ARM_GCC_PKG} to ${HOME}"
        tar -xjf ${ARM_GCC_PKG} -C ${HOME}/
    fi
    echo "ARM GCC installed to ${HOME}/${ARM_GCC}"
    popd 
}

function setup_cmake() {
    echo -e "\e[32m${FUNCNAME[0]}\e[0m"
    pushd /tmp
    [[ ! -f ${CMAKE_NAME}.tgz ]] &&
        getCMake
    [[ ! -d ${HOME}/${CMAKE_NAME} ]] &&
        tar -xf ${CMAKE_PKG} -C ${HOME}/
    popd
    echo "CMAKEV installed to ${HOME}/${CMAKE_NAME} and set in PATH"
}

function install_docker() {
    if [[ -n $(command -v docker) ]]; then
        TESTED_VERSION="19.03.8"
        DOCKER_VERSION=$(docker version -f '{{.Server.Version}}')
        if [[ ${TESTED_VERSION} != ${DOCKER_VERSION} ]]; then
            echo -e "Tested with docker ${DOCKER_VERSION} your is ${DOCKER_VERSION} consider updating"
        else
            echo "Docker already installed"
        fi

    else
        curl -fsSL https://get.docker.com -o /tmp/get-docker.sh
        sudo sh /tmp/get-docker.sh
    fi
}

function add_to_docker_group() {
    DOCKER_GRP="docker"
    if grep -q $DOCKER_GRP /etc/group
    then
        NAME=$(whoami)
        sudo usermod -aG ${DOCKER_GRP} ${NAME}
        cat <<-MSGEND
		Group is updated, please logout and login back so
		the change has come into effect
		MSGEND
    fi
}


BUILD_STEPS=(
        install_hooks
        add_ignore_revs_for_blame
        install_ubuntu_packages
        setup_arm_toolchain
        setup_cmake
        setup_gcc_alternatives
        "add_to_path ARM_GCC ${HOME}/${ARM_GCC}/bin"
        "add_to_path CMAKE ${HOME}/${CMAKE_NAME}/bin"
        install_docker
        add_to_docker_group
        )

test_if_run_as_root

if [ $# -eq 1 ]; then 
    PARAM=$1
    if [ "${PARAM:$(( ${#PARAM} - 1 )):1}" == "-" ]; then
        START=${PARAM%*-}
        END=${#BUILD_STEPS[@]}
    else
        START=${PARAM}
        END=$(( ${PARAM} + 1 ))
    fi
else
    echo "Available build steps:"
    I=0
    while [ $I -lt ${#BUILD_STEPS[@]} ]
    do
        echo -e "\t$I ${BUILD_STEPS[${I}]}"
        I=$(( $I + 1 ))
    done
    cat <<- MSGEND
		call:
			${0} <build step no>[-]
		ex.:
			${0} 1       - build step 1 (${BUILD_STEPS[1]})
			${0} 3       - build step 3 (${BUILD_STEPS[3]})
			${0} 3-      - build from step 3 to the end
			${0} 0-      - build everything
		MSGEND
    exit 0
fi
echo "START:${BUILD_STEPS[$START]}(${START})"
echo "END:${BUILD_STEPS[$END]}(${END})"

I=${START}
while [ ${I} -lt ${END} ]
do
    eval ${BUILD_STEPS[${I}]}
    echo "${I}" > LAST_STEP
    I=$(( ${I} + 1 ))
done