#!/bin/bash
# SPDX-License-Identifier: MulanPSL-2.0+
# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved.
# frozen_string_literal: true

# disable swap
swapoff -a
sed -i '/swap/d' /etc/fstab

id -u lkp || useradd -u 1090 lkp

sh ../sparrow/1-storage/tiny

# install stable version ruby
yum -y update
yum -y install gcc make tar gzip openssl-devel gcc-c++ zlib iproute wget docker git
wget https://ftp.ruby-lang.org/pub/ruby/2.7/ruby-2.7.6.tar.gz
tar xzvf ruby-2.7.6.tar.gz && cd ruby-2.7.6 && ./configure && make && make install

# clean ruby srv files
rm -f ruby-2.7.6.tar.gz
rm -rf ruby-2.7.6

# use internal sources addr instead of the default
gem sources -r https://rubygems.org/
gem sources -a  https://gems.ruby-china.com/
gem sources -u

# install required ruby gem packages
gem install --no-user-install git activesupport rest-client cucumber json faye-websocket elasticsearch bunny nokogiri
yum  -y remove gcc make gcc-c++

# download cbs
mkdir -p /c
git clone https://gitee.com/openeuler-customization/cbs.git /c/cbs
git clone https://gitee.com/openeuler-customization/lkp-tests.git /c/lkp-tests

# add env for CCI_SRC
os_shell=$(basename $SHELL)
echo export CCI_SRC=/c/cbs >> $HOME/.${os_shell}rc
echo export LKP_SRC=/c/lkp-tests >> $HOME/.${os_shell}rc
