forked from mikkeloscar/arch-travis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.sh
executable file
·110 lines (94 loc) · 2.57 KB
/
init.sh
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
#!/bin/bash
# Copyright (C) 2018 Mikkel Oscar Lyderik Larsen
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
cd /build
if [ -n "$CC" ]; then
# store travis CC
TRAVIS_CC=$CC
# reset to gcc for building arch packages
CC=gcc
fi
# /etc/pacman.conf repository line
repo_line=70
# read arch-travis config from env
read_config() {
local old_ifs=$IFS
local sep='::::'
CONFIG_BUILD_SCRIPTS=${CONFIG_BUILD_SCRIPTS//$sep/$'\n'}
CONFIG_PACKAGES=${CONFIG_PACKAGES//$sep/$'\n'}
CONFIG_REPOS=${CONFIG_REPOS//$sep/$'\n'}
IFS=$'\n'
CONFIG_BUILD_SCRIPTS=(${CONFIG_BUILD_SCRIPTS[@]})
CONFIG_PACKAGES=(${CONFIG_PACKAGES[@]})
CONFIG_REPOS=(${CONFIG_REPOS[@]})
IFS=$old_ifs
}
# add custom repositories to pacman.conf
add_repositories() {
if [ ${#CONFIG_REPOS[@]} -gt 0 ]; then
for r in "${CONFIG_REPOS[@]}"; do
local splitarr=(${r//=/ })
((repo_line+=1))
sudo sed -i "${repo_line}i[${splitarr[0]}]" /etc/pacman.conf
((repo_line+=1))
sudo sed -i "${repo_line}iServer = ${splitarr[1]}\n" /etc/pacman.conf
((repo_line+=1))
done
# update repos
sudo pacman -Syy
fi
}
# install packages defined in .travis.yml
install_packages() {
for package in "${CONFIG_PACKAGES[@]}"; do
yay -S $package --noconfirm
done
}
# run build scripts defined in .travis.yml
build_scripts() {
if [ ${#CONFIG_BUILD_SCRIPTS[@]} -gt 0 ]; then
for script in "${CONFIG_BUILD_SCRIPTS[@]}"; do
echo "\$ $script"
eval $script
done
else
echo "No build scripts defined"
exit 1
fi
}
install_c_compiler() {
if [ "$TRAVIS_CC" != "gcc" ]; then
yay -S "$TRAVIS_CC" --noconfirm
fi
}
arch_msg() {
lightblue='\033[1;34m'
reset='\e[0m'
echo -e "${lightblue}$@${reset}"
}
read_config
echo "travis_fold:start:arch_travis"
arch_msg "Setting up Arch environment"
add_repositories
install_packages
if [ -n "$CC" ]; then
install_c_compiler
# restore CC
CC=$TRAVIS_CC
fi
echo "travis_fold:end:arch_travis"
echo ""
arch_msg "Running travis build"
build_scripts