Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test DIY install.sh script #3015

Open
wants to merge 1 commit into
base: alpha
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/workflows/build-diy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# build diy image based on debian bullseye and bookworm
# test install.sh script as-it
name: Test DIY install.sh

# only trigger when last commit or PR modify install/**
on:
# only trigger CI when pull request on following branches and path
pull_request:
branches:
- 'alpha'
paths:
- install/**
# this is to manually trigger the worklow
workflow_dispatch:
inputs:
logLevel:
description: 'Reason'
default: 'Manual launch'

env:
GITHUB_REPOSITORY: jeedom/core

jobs:
InstallationDIY:
# This step build the same image on different runners / platforms
strategy:
# continue all jobs even if some fail
fail-fast: false
matrix:
debian: [bullseye, bookworm ]
targetRunner: [ ubuntu-latest] # [ ubuntu-latest, ARM, ARM64]
database: [ 1] # [1, 0]

runs-on: ${{ matrix.targetRunner }}
steps:

- name: Check Out Repo
# Check out the repo, using current branch
# https://github.com/marketplace/actions/checkout
uses: actions/checkout@v4

- name: install jeedom:${{ matrix.debian }}
# run current installation
run: |
echo "Running DIY install of ${GITHUB_REPOSITORY} / ${GITHUB_REF_NAME}" into ${{ matrix.debian }} >> ${GITHUB_STEP_SUMMARY}
docker build -t jeedom:${{ matrix.debian }} -f tests/Dockerfile \
--build-arg DEBIAN=${{ matrix.debian }} \
--build-arg DATABASE=${{ matrix.database }} \
--build-arg WEBSERVER_HOME=/var/www/html \
--build-arg MARIADB_NAME=jeedom .
docker run -p 80:80 -d --rm --name jeedom_${{ matrix.debian }} jeedom:${{ matrix.debian }}
sleep 10
docker exec jeedom_${{ matrix.debian }} php sick.php
133 changes: 69 additions & 64 deletions install/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,24 @@ if [ $(id -u) != 0 ] ; then
fi

apt_install() {
apt-get -o Dpkg::Options::="--force-confdef" -y install "$@"
# quiet install but confirm correct installation
apt-get --quiet --option Dpkg::Options::="--force-confdef" --yes install "$@" > /dev/null
if [ $? -ne 0 ]; then
echo "${RED}Cannot install $@ - Cancelling${NORMAL}"
exit 1
echo "${RED}Cannot install $@ - Continue anyway...${NORMAL}"
else
echo "${GREEN}$@ installed${NORMAL}"
fi
}

mariadb_sql() {
echo "$@" | mariadb -uroot
echo "$@" | mariadb -u root
if [ $? -ne 0 ]; then
echo "${RED}Cannot execute $@ in MySQL - Cancelling${NORMAL}"
exit 1
# try with sudo
echo "$@" | sudo mariadb
if [ $? -ne 0 ]; then
echo "${RED}Cannot execute $@ in MySQL - Cancelling${NORMAL}"
exit 1
fi
fi
}

Expand Down Expand Up @@ -52,42 +58,38 @@ step_1_upgrade() {
echo "---------------------------------------------------------------------"
echo "${YELLOW}Starting step 1 - install${NORMAL}"

apt-get update
apt-get -f install
apt-get -y dist-upgrade
apt-get --quiet update
apt-get --quiet -f install
apt-get --quiet -y dist-upgrade
echo "${GREEN} Step 1 - Install done ${NORMAL}"
}

step_2_mainpackage() {
echo "---------------------------------------------------------------------"
echo "${YELLOW}Starting step 2 - packages${NORMAL}"
apt-get -y install software-properties-common
apt-get update
apt_install software-properties-common
apt-get --quiet update
apt_install ntp ca-certificates unzip curl sudo cron
apt-get -o Dpkg::Options::="--force-confdef" -y install locate tar telnet wget logrotate dos2unix ntpdate htop iotop vim iftop smbclient
apt-get -y install usermod
apt-get -y install visudo
apt-get -y install git python python-pip
apt-get -y install python3 python3-pip
apt-get -y install libexpat1 ssl-cert
apt-get -y install apt-transport-https
apt-get -y install xvfb cutycapt xauth
apt-get -y install at
apt-get -y install mariadb-client
apt-get -y install libav-tools
apt-get -y install espeak
apt-get -y install mbrola
apt-get -y install net-tools
apt-get -y install nmap
apt-get -y install ffmpeg
apt-get -y install usbutils
apt-get -y install gettext
apt-get -y install libcurl3-gnutls
apt-get -y install chromium
apt-get -y install librsync-dev
apt-get -y install ssl-cert
apt-get -y remove brltty
apt-get -y iputils-ping
apt_install locate tar telnet wget logrotate dos2unix ntpdate htop iotop vim iftop smbclient
apt_install git python3 python3-pip
apt_install libexpat1 ssl-cert
apt_install apt-transport-https
apt_install xvfb cutycapt xauth
apt_install at
apt_install mariadb-client
apt_install espeak
# apt_install mbrola # included in espeak
apt_install net-tools
apt_install nmap
apt_install ffmpeg
apt_install usbutils
apt_install gettext
apt_install libcurl3-gnutls
apt_install chromium
apt_install librsync-dev
apt_install ssl-cert
apt-get -qq -y remove brltty
apt_install iputils-ping
echo "${GREEN}step 2 - packages done${NORMAL}"
}

Expand Down Expand Up @@ -124,28 +126,28 @@ step_5_php() {
echo "---------------------------------------------------------------------"
echo "${YELLOW}Starting step 5 - php${NORMAL}"
apt_install php libapache2-mod-php php-json php-mysql
apt install -y php-curl
apt install -y php-gd
apt install -y php-imap
apt install -y php-xml
apt install -y php-opcache
apt install -y php-soap
apt install -y php-xmlrpc
apt install -y php-common
apt install -y php-dev
apt install -y php-zip
apt install -y php-ssh2
apt install -y php-mbstring
apt install -y php-ldap
apt install -y php-yaml
apt install -y php-snmp
apt_install php-curl
apt_install php-gd
apt_install php-imap
apt_install php-xml
apt_install php-opcache
apt_install php-soap
apt_install php-xmlrpc
apt_install php-common
apt_install php-dev
apt_install php-zip
apt_install php-ssh2
apt_install php-mbstring
apt_install php-ldap
apt_install php-yaml
apt_install php-snmp
echo "${GREEN}Step 5 - php done${NORMAL}"
}

step_6_jeedom_download() {
echo "---------------------------------------------------------------------"
echo "${YELLOW}Starting step 6 - download Jeedom${NORMAL}"
wget https://codeload.github.com/jeedom/core/zip/refs/heads/${VERSION} -O /tmp/jeedom.zip
wget --no-verbose https://codeload.github.com/jeedom/core/zip/refs/heads/${VERSION} -O /tmp/jeedom.zip

if [ $? -ne 0 ]; then
echo "${YELLOW}Cannot download Jeedom from Github. Use deployment version if exist.${NORMAL}"
Expand All @@ -157,20 +159,19 @@ step_6_jeedom_download() {
echo "${RED}Cannot get jeedom.zip archive - Cancelling${NORMAL}"
exit 1
fi
mkdir -p ${WEBSERVER_HOME}
find ${WEBSERVER_HOME} ! -name 'index.html' -type f -exec rm -rf {} +
rm -rf /root/core-*
# unzip into /root/core-${VERSION}
unzip -q /tmp/jeedom.zip -d /root/
if [ $? -ne 0 ]; then
echo "${RED}Cannot unpack archive - Cancelling${NORMAL}"
exit 1
fi
cp -R /root/core-*/* ${WEBSERVER_HOME}
cp -R /root/core-*/.[^.]* ${WEBSERVER_HOME}
cp /root/core/.htaccess ${WEBSERVER_HOME}/.htaccess
rm -rf ${WEBSERVER_HOME} && mkdir -p ${WEBSERVER_HOME}
cd .
mv -v -T /root/core-${VERSION} ${WEBSERVER_HOME}
# force timestamp to now for all files:
find ${WEBSERVER_HOME}/ -exec touch {} +
rm -rf /root/core-* > /dev/null 2>&1
rm -rf ${WEBSERVER_HOME}/core-* > /dev/null 2>&1
rm /tmp/jeedom.zip
echo "${GREEN}Step 6 - download Jeedom done${NORMAL}"
}
Expand All @@ -184,7 +185,7 @@ step_7_jeedom_customization_mariadb() {
echo 'Restart=always' >> /lib/systemd/system/mariadb.service.d/override.conf
echo 'RestartSec=10' >> /lib/systemd/system/mariadb.service.d/override.conf

# do not start oany new service during docker build sequence
# do not start any new service during docker build sequence
if [ "${INSTALLATION_TYPE}" != "docker" ];then
systemctl daemon-reload

Expand Down Expand Up @@ -242,6 +243,7 @@ step_7_jeedom_customization_mariadb() {

step_8_jeedom_customization() {
echo "---------------------------------------------------------------------"
cd .
echo "${YELLOW}Starting step 8 - Jeedom customization${NORMAL}"
cp ${WEBSERVER_HOME}/install/apache_security /etc/apache2/conf-available/security.conf
sed -i -e "s%WEBSERVER_HOME%${WEBSERVER_HOME}%g" /etc/apache2/conf-available/security.conf
Expand All @@ -262,7 +264,7 @@ step_8_jeedom_customization() {

echo '' > /etc/apache2/mods-available/alias.conf

mkdir /etc/systemd/system/apache2.service.d
mkdir -p /etc/systemd/system/apache2.service.d
echo "[Service]" > /etc/systemd/system/apache2.service.d/override.conf
echo "PrivateTmp=no" >> /etc/systemd/system/apache2.service.d/override.conf
echo "Restart=always" >> /etc/systemd/system/apache2.service.d/override.conf
Expand Down Expand Up @@ -305,15 +307,15 @@ step_9_jeedom_configuration() {
echo "${YELLOW}Starting step 9 - Jeedom configuration${NORMAL}"

if [ "${INSTALLATION_TYPE}" != "docker" ];then
echo "DROP USER 'jeedom'@'localhost';" | mariadb -uroot > /dev/null 2>&1
mariadb_sql "DROP USER IF EXISTS 'jeedom'@'localhost';"
mariadb_sql "CREATE USER 'jeedom'@'localhost' IDENTIFIED BY '${MARIADB_JEEDOM_PASSWD}';"
mariadb_sql "DROP DATABASE IF EXISTS jeedom;"
mariadb_sql "CREATE DATABASE jeedom;"
mariadb_sql "DROP DATABASE IF EXISTS ${MARIADB_NAME};"
mariadb_sql "CREATE DATABASE ${MARIADB_NAME}"
mariadb_sql "GRANT ALL PRIVILEGES ON jeedom.* TO 'jeedom'@'localhost';"

cp ${WEBSERVER_HOME}/core/config/common.config.sample.php ${WEBSERVER_HOME}/core/config/common.config.php
sed -i "s/#PASSWORD#/${MARIADB_JEEDOM_PASSWD}/g" ${WEBSERVER_HOME}/core/config/common.config.php
sed -i "s/#DBNAME#/jeedom/g" ${WEBSERVER_HOME}/core/config/common.config.php
sed -i "s/#DBNAME#/${MARIADB_NAME}/g" ${WEBSERVER_HOME}/core/config/common.config.php
sed -i "s/#USERNAME#/jeedom/g" ${WEBSERVER_HOME}/core/config/common.config.php
sed -i "s/#PORT#/3306/g" ${WEBSERVER_HOME}/core/config/common.config.php
sed -i "s/#HOST#/localhost/g" ${WEBSERVER_HOME}/core/config/common.config.php
Expand All @@ -325,12 +327,14 @@ step_9_jeedom_configuration() {

step_10_jeedom_installation() {
echo "---------------------------------------------------------------------"
cd .
echo "${YELLOW}Starting step 10 - Jeedom install${NORMAL}"
chmod +x ${WEBSERVER_HOME}/resources/install_composer.sh
${WEBSERVER_HOME}/resources/install_composer.sh
export COMPOSER_ALLOW_SUPERUSER=1
cd ${WEBSERVER_HOME}
composer install --no-ansi --no-dev --no-interaction --no-plugins --no-progress --no-scripts --optimize-autoloader

mkdir -p /tmp/jeedom
chmod 777 -R /tmp/jeedom
chown www-data:www-data -R /tmp/jeedom
Expand Down Expand Up @@ -414,11 +418,12 @@ distrib_1_spe(){
STEP=0
VERSION=master
WEBSERVER_HOME=/var/www/html
MARIADB_NAME=${MARIADB_NAME:-jeedom}
MARIADB_JEEDOM_PASSWD=${MARIADB_JEEDOM_PASSWD:-$(openssl rand -base64 32 | tr -d /=+ | cut -c -15)}
INSTALLATION_TYPE='standard'
DATABASE=1

while getopts ":s:v:w:m:i:d:" opt; do
while getopts ":s:v:w:i:d:" opt; do
case $opt in
s) STEP="$OPTARG"
;;
Expand Down
2 changes: 1 addition & 1 deletion resources/install_composer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
echo "Begin installation of composer"
wget https://getcomposer.org/installer -O composer-setup.php
php composer-setup.php
php -r "unlink('composer-setup.php');"
rm composer-setup.php
[[ -f /usr/local/bin/composer ]] && sudo rm /usr/local/bin/composer || true
sudo mv composer.phar /usr/local/bin/composer
echo "End installation of composer"
32 changes: 32 additions & 0 deletions tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
ARG DEBIAN=bookworm-slim

FROM debian:${DEBIAN}

ARG WEBSERVER_HOME=/var/www/html
ENV WEBSERVER_HOME=${WEBSERVER_HOME}
ARG VERSION=alpha
ARG DATABASE=1
ARG MARIADB_NAME=jeedom
ENV MARIADB_NAME=${MARIADB_NAME}
WORKDIR ${WEBSERVER_HOME}

COPY --chown=root:root --chmod=550 install/install.sh /install.sh
RUN /install.sh -v ${VERSION} -w ${WEBSERVER_HOME} -d ${DATABASE}

# créer le script d'init
COPY --chown=root:root --chmod=550 <<EOF /root/init.sh
#!/bin/bash
# démarrer mariadb
service mariadb start
# démarrer atd
service atd start
# démarrer apache2
service apache2 start
# démarrer cron
service cron start
# attendre à l'infini
while :; do echo "$((COUNT++)) DAYS"; sleep 86400; done
EOF

# définir le script d'init comme commande par défaut
CMD ["/root/init.sh"]