yunohost_demo/demo_lxc_build.sh

182 lines
12 KiB
Bash
Raw Normal View History

2016-08-12 01:38:13 +02:00
#!/bin/bash
2016-08-13 01:08:44 +02:00
# Créer les conteneurs Yunohost et les configure
2016-08-12 01:38:13 +02:00
# Récupère le dossier du script
2016-09-18 19:23:54 +02:00
if [ "${0:0:1}" == "/" ]; then script_dir="$(dirname "$0")"; else script_dir="$(echo $PWD/$(dirname "$0" | cut -d '.' -f2) | sed 's@/$@@')"; fi
2016-08-12 01:38:13 +02:00
2022-10-13 05:46:46 +02:00
source $script_dir/ynh_lxd
source /usr/share/yunohost/helpers
app=${__APP__:-yunohost_demo}
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
lxdbr_demo_name=$(ynh_app_setting_get --app=$app --key=lxdbr_demo_name)
lxdbr_demo_network=$(ynh_app_setting_get --app=$app --key=lxdbr_demo_network)
lxc_ip1=$(ynh_app_setting_get --app=$app --key=lxc_ip1)
lxc_ip2=$(ynh_app_setting_get --app=$app --key=lxc_ip2)
demo_user=$(ynh_app_setting_get --app=$app --key=demo_user)
demo_password=$(ynh_app_setting_get --app=$app --key=demo_password)
demo_package=$(ynh_app_setting_get --app=$app --key=demo_package)
yunohost_password="$demo_password"
lxc_name1=$(ynh_app_setting_get --app=$app --key=lxc_name1)
lxc_name2=$(ynh_app_setting_get --app=$app --key=lxc_name2)
time_to_switch=$(ynh_app_setting_get --app=$app --key=time_to_switch)
DIST=$(ynh_app_setting_get --app=$app --key=DIST)
ARCH=$(ynh_app_setting_get --app=$app --key=ARCH)
YNH_BRANCH=$(ynh_app_setting_get --app=$app --key=YNH_BRANCH)
lxc_base="ynh-dev-$DIST-$ARCH-$YNH_BRANCH-base"
2016-08-16 15:36:12 +02:00
2022-10-13 05:46:46 +02:00
LOG=Build_lxc.log
LOG_BUILD_LXC="$final_path/$LOG"
2018-08-26 13:40:41 +02:00
2022-10-15 22:25:49 +02:00
date | tee -a "$LOG_BUILD_LXC" 2>&1
ynh_print_info --message=">> Starting demo build." | tee -a "$LOG_BUILD_LXC" 2>&1
if ynh_lxc_exists --name="$name"
then
ynh_print_info --message="> Deleting existing LXC containers." | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-15 20:19:52 +02:00
/bin/bash "$final_path/demo_lxc_destroy.sh" quiet | tee -a "$LOG_BUILD_LXC" 2>&1
2018-08-26 13:40:41 +02:00
fi
2022-10-15 22:25:49 +02:00
ynh_print_info --message="> Creating a YunoHost $DIST $ARCH $YNH_BRANCH" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-13 05:46:46 +02:00
ynh_lxc_create --image="$lxc_base" --name="$lxc_name1" | tee -a "$LOG_BUILD_LXC" 2>&1
2018-08-26 13:40:41 +02:00
2022-10-15 22:25:49 +02:00
ynh_print_info --message= "> Creating the $lxdbr_demo_name bridge" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-13 05:46:46 +02:00
lxc network attach $lxdbr_demo_name $lxc_name1 eth1 eth1 | tee -a "$LOG_BUILD_LXC" 2>&1
2016-08-12 01:38:13 +02:00
2022-10-15 22:25:49 +02:00
ynh_print_info --message="> Configuring network of the LXC container" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-13 05:46:46 +02:00
ynh_lxc_run_inside --name="$lxc_name1" --command="cp /etc/systemd/network/eth0.network /etc/systemd/network/eth1.network"
ynh_lxc_run_inside --name="$lxc_name1" --command="sed -i s/eth0/eth1/g /etc/systemd/network/eth1.network"
2016-08-12 01:38:13 +02:00
2022-10-15 22:25:49 +02:00
ynh_print_info --message="> Update of the LXC container" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-13 05:46:46 +02:00
ynh_lxc_run_inside --name="$lxc_name1" --command="apt-get -y update"
ynh_lxc_run_inside --name="$lxc_name1" --command="apt-get -y full-upgrade"
ynh_lxc_run_inside --name="$lxc_name1" --command="apt-get -y autoremove"
ynh_lxc_run_inside --name="$lxc_name1" --command="apt-get -y clean"
2016-08-12 01:38:13 +02:00
2022-10-15 20:19:52 +02:00
ynh_print_info --message="> Post install Yunohost" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-13 05:46:46 +02:00
ynh_lxc_run_inside --name="$lxc_name1" --command="yunohost tools postinstall --domain $domain --password $yunohost_password --force-password" | tee -a "$LOG_BUILD_LXC" 2>&1
2018-08-26 13:40:41 +02:00
2022-10-15 20:19:52 +02:00
ynh_print_info --message="> Disable password strength" | tee -a "$LOG_BUILD_LXC" 2>&1
ynh_lxc_run_inside --name="$lxc_name1" --command="yunohost settings set security.password.user.strength -v -1" | tee -a "$LOG_BUILD_LXC" 2>&1
2018-08-26 13:40:41 +02:00
2022-10-15 22:25:49 +02:00
ynh_print_info --message="> Add demo user" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-15 20:19:52 +02:00
ynh_lxc_run_inside --name="$lxc_name1" --command="yunohost user create $demo_user --firstname $demo_user --lastname $demo_user --domain $domain --password $demo_password" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-15 22:25:49 +02:00
ynh_print_info --message="> Check YunoHost state" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-13 05:46:46 +02:00
ynh_lxc_run_inside --name="$lxc_name1" --command="yunohost -v" | tee -a "$LOG_BUILD_LXC" 2>&1
2016-08-12 01:38:13 +02:00
2016-09-18 19:23:54 +02:00
# ********
2022-10-15 22:25:49 +02:00
ynh_print_info --message="> Installing demo apps" | tee -a "$LOG_BUILD_LXC" 2>&1
2016-09-18 19:23:54 +02:00
2022-10-15 21:13:40 +02:00
if [ ${DONT_INSTALL_FOR_NOW:-0} -eq 1 ]; then
2018-08-26 13:40:41 +02:00
# Ampache
2022-10-15 22:25:49 +02:00
ynh_print_info --message="installing Ampache" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-15 20:19:52 +02:00
ynh_lxc_run_inside --name="$lxc_name1" --command="yunohost app install ampache --force --args \"domain=$domain&path=/ampache&admin=$demo_user&is_public=1&\"" | tee -a "$LOG_BUILD_LXC" 2>&1
2018-08-26 13:40:41 +02:00
# Baikal
2022-10-15 22:25:49 +02:00
ynh_print_info --message="installing baikal" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-15 20:19:52 +02:00
ynh_lxc_run_inside --name="$lxc_name1" --command="yunohost app install baikal --force --args \"domain=$domain&path=/baikal&password=$demo_password&\"" | tee -a "$LOG_BUILD_LXC" 2>&1
2018-08-26 13:40:41 +02:00
# Agendav
2022-10-15 20:19:52 +02:00
ynh_print_info --message="Installation d'agendav" | tee -a "$LOG_BUILD_LXC" 2>&1
ynh_lxc_run_inside --name="$lxc_name1" --command="yunohost app install agendav --force --args \"domain=$domain&path=/agendav&language=en&\"" | tee -a "$LOG_BUILD_LXC" 2>&1
2018-08-26 13:40:41 +02:00
# Dokuwiki
2022-10-15 22:25:49 +02:00
ynh_print_info --message="installing dokuwiki" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-15 20:19:52 +02:00
ynh_lxc_run_inside --name="$lxc_name1" --command="yunohost app install dokuwiki --force --args \"domain=$domain&path=/dokuwiki&admin=$demo_user&is_public=1&language=en&\"" | tee -a "$LOG_BUILD_LXC" 2>&1
2018-08-26 13:40:41 +02:00
# Etherpad
2022-10-15 22:25:49 +02:00
ynh_print_info --message="installing etherpad" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-15 20:19:52 +02:00
ynh_lxc_run_inside --name="$lxc_name1" --command="yunohost app install etherpad_mypads --force --args \"domain=$domain&path=/etherpad&admin=$demo_user&password=administration&language=en&is_public=1&export=none&mypads=1&useldap=0&\"" | tee -a "$LOG_BUILD_LXC" 2>&1
2018-08-26 13:40:41 +02:00
# Hextris
2022-10-15 22:25:49 +02:00
ynh_print_info --message="installing hextris" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-15 20:19:52 +02:00
ynh_lxc_run_inside --name="$lxc_name1" --command="yunohost app install hextris --force --args \"domain=$domain&path=/hextris&is_public=1&\"" | tee -a "$LOG_BUILD_LXC" 2>&1
2018-08-26 13:40:41 +02:00
# Jirafeau
2022-10-15 22:25:49 +02:00
ynh_print_info --message="installing jirafeau" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-15 20:19:52 +02:00
ynh_lxc_run_inside --name="$lxc_name1" --command="yunohost app install jirafeau --force --args \"domain=$domain&path=/jirafeau&admin_user=$demo_user&upload_password=$demo_password&is_public=1&\"" | tee -a "$LOG_BUILD_LXC" 2>&1
2018-08-26 13:40:41 +02:00
# Kanboard
2022-10-15 22:25:49 +02:00
ynh_print_info --message="installing kanboard" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-15 20:19:52 +02:00
ynh_lxc_run_inside --name="$lxc_name1" --command="yunohost app install kanboard --force --args \"domain=$domain&path=/kanboard&admin=$demo_user&is_public=1&\"" | tee -a "$LOG_BUILD_LXC" 2>&1
2018-08-26 13:40:41 +02:00
# Nextcloud
2022-10-15 22:25:49 +02:00
ynh_print_info --message="installing nextcloud" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-15 20:19:52 +02:00
ynh_lxc_run_inside --name="$lxc_name1" --command="yunohost app install nextcloud --force --args \"domain=$domain&path=/nextcloud&admin=$demo_user&user_home=0&is_public=1&\"" | tee -a "$LOG_BUILD_LXC" 2>&1
2018-08-26 13:40:41 +02:00
# Opensondage
2022-10-15 22:25:49 +02:00
ynh_print_info --message="installing opensondage" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-15 20:19:52 +02:00
ynh_lxc_run_inside --name="$lxc_name1" --command="yunohost app install opensondage --force --args \"domain=$domain&path=/date&admin=$demo_user&language=en&is_public=1&\"" | tee -a "$LOG_BUILD_LXC" 2>&1
2018-08-26 13:40:41 +02:00
# Phpmyadmin
2022-10-15 22:25:49 +02:00
ynh_print_info --message="installing phpmyadmin" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-15 20:19:52 +02:00
ynh_lxc_run_inside --name="$lxc_name1" --command="yunohost app install phpmyadmin --force --args \"domain=$domain&path=/phpmyadmin&admin=$demo_user&\"" | tee -a "$LOG_BUILD_LXC" 2>&1
2018-08-26 13:40:41 +02:00
# Piwigo
2022-10-15 22:25:49 +02:00
ynh_print_info --message="installing piwigo" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-15 20:19:52 +02:00
ynh_lxc_run_inside --name="$lxc_name1" --command="yunohost app install piwigo --force --args \"domain=$domain&path=/piwigo&admin=$demo_user&is_public=1&language=en&\"" | tee -a "$LOG_BUILD_LXC" 2>&1
2018-08-26 13:40:41 +02:00
# Rainloop
2022-10-15 22:25:49 +02:00
ynh_print_info --message="installing rainloop" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-15 20:19:52 +02:00
ynh_lxc_run_inside --name="$lxc_name1" --command="yunohost app install rainloop --force --args \"domain=$domain&path=/rainloop&is_public=No&password=$demo_password&ldap=Yes&language=en&\"" | tee -a "$LOG_BUILD_LXC" 2>&1
2018-08-26 13:40:41 +02:00
# Roundcube
2022-10-15 22:25:49 +02:00
ynh_print_info --message="installing roundcube" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-15 20:19:52 +02:00
ynh_lxc_run_inside --name="$lxc_name1" --command="yunohost app install roundcube --force --args \"domain=$domain&path=/webmail&with_carddav=0&with_enigma=0&language=en_GB&\"" | tee -a "$LOG_BUILD_LXC" 2>&1
2018-08-26 13:40:41 +02:00
# Searx
2022-10-15 22:25:49 +02:00
ynh_print_info --message="installing searx" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-15 20:19:52 +02:00
ynh_lxc_run_inside --name="$lxc_name1" --command="yunohost app install searx --force --args \"domain=$domain&path=/searx&is_public=1&\"" | tee -a "$LOG_BUILD_LXC" 2>&1
2018-08-26 13:40:41 +02:00
# Shellinabox
2022-10-15 22:25:49 +02:00
ynh_print_info --message="installing shellinabox" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-15 20:19:52 +02:00
ynh_lxc_run_inside --name="$lxc_name1" --command="yunohost app install shellinabox --force --args \"domain=$domain&path=/ssh&\"" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-13 05:46:46 +02:00
# Désactive l'accès à shellinabox
ynh_lxc_run_inside --name="$lxc_name1" --command="rm /etc/nginx/conf.d/$domain.d/shellinabox.conf"
ynh_lxc_run_inside --name="$lxc_name1" --command="yunohost app setting shellinabox path -d"
ynh_lxc_run_inside --name="$lxc_name1" --command="yunohost app setting shellinabox domain -d"
ynh_lxc_run_inside --name="$lxc_name1" --command="yunohost app ssowatconf"
2018-08-26 13:40:41 +02:00
# Strut
2022-10-15 22:25:49 +02:00
ynh_print_info --message="installing strut" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-15 20:19:52 +02:00
ynh_lxc_run_inside --name="$lxc_name1" --command="yunohost app install strut --force --args \"domain=$domain&path=/strut&is_public=1&\"" | tee -a "$LOG_BUILD_LXC" 2>&1
2018-08-26 13:40:41 +02:00
# Transmission
2022-10-15 22:25:49 +02:00
ynh_print_info --message="installing transmission" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-15 20:19:52 +02:00
ynh_lxc_run_inside --name="$lxc_name1" --command="yunohost app install transmission --force --args \"domain=$domain&path=/torrent&\"" | tee -a "$LOG_BUILD_LXC" 2>&1
2018-08-26 13:40:41 +02:00
# Ttrss
2022-10-15 22:25:49 +02:00
ynh_print_info --message="installing ttrss" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-15 20:19:52 +02:00
ynh_lxc_run_inside --name="$lxc_name1" --command="yunohost app install ttrss --force --args \"domain=$domain&path=/ttrss&is_public=1&\"" | tee -a "$LOG_BUILD_LXC" 2>&1
2018-08-26 13:40:41 +02:00
# Wallabag
2022-10-15 22:25:49 +02:00
ynh_print_info --message="installing wallabag" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-15 20:19:52 +02:00
ynh_lxc_run_inside --name="$lxc_name1" --command="yunohost app install wallabag2 --force --args \"domain=$domain&path=/wallabag&admin=$demo_user&\"" | tee -a "$LOG_BUILD_LXC" 2>&1
2018-08-26 13:40:41 +02:00
# Wordpress
2022-10-15 22:25:49 +02:00
ynh_print_info --message="installing wordpress" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-15 20:19:52 +02:00
ynh_lxc_run_inside --name="$lxc_name1" --command="yunohost app install wordpress --force --args \"domain=$domain&path=/blog&admin=$demo_user&language=en_US&multisite=0&is_public=1&\"" | tee -a "$LOG_BUILD_LXC" 2>&1
2018-08-26 13:40:41 +02:00
# Zerobin
2022-10-15 22:25:49 +02:00
ynh_print_info --message="installing zerobin" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-15 20:19:52 +02:00
ynh_lxc_run_inside --name="$lxc_name1" --command="yunohost app install zerobin --force --args \"domain=$domain&path=/zerobin&is_public=1&\"" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-15 01:41:22 +02:00
fi
2022-10-15 22:25:49 +02:00
2016-09-18 19:23:54 +02:00
# ********
2016-08-12 01:38:13 +02:00
2022-10-15 22:25:49 +02:00
ynh_print_info --message="> Creating a snapshot for $lxc_name1" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-13 05:46:46 +02:00
ynh_lxc_create_snapshot --name="$lxc_name1" --snapname="snap0"
2016-08-12 01:38:13 +02:00
2022-10-15 23:36:15 +02:00
ynh_print_info --message="> Upgrading the $lxc_name1 LXC container" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-13 05:46:46 +02:00
ynh_lxc_stop --name="$lxc_name1" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-15 23:36:15 +02:00
ynh_lxc_upgrade_demo --name=$lxc_name1 --time_to_switch=$time_to_switch | tee -a "$LOG_BUILD_LXC" 2>&1
2016-08-13 19:31:36 +02:00
2022-10-15 22:25:49 +02:00
ynh_print_info --message="> Cloning $lxc_name1 to $lxc_name2" | tee -a "$LOG_BUILD_LXC" 2>&1
ynh_lxc_clone --source="$lxc_name1" --destination="$lxc_name2" | tee -a "$LOG_BUILD_LXC" 2>&1
2016-08-12 18:07:01 +02:00
2022-10-15 22:25:49 +02:00
ynh_print_info --message="> Creating a snapshot for $lxc_name2" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-15 23:36:15 +02:00
ynh_lxc_create_snapshot --name="$lxc_name2" --snapname="snap0" | tee -a "$LOG_BUILD_LXC" 2>&1
2016-08-13 19:31:36 +02:00
2022-10-15 22:25:49 +02:00
ynh_print_info --message="> Setuping the switch cron" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-15 23:36:15 +02:00
ynh_add_config --template="$final_path/conf/cron_demo_switch" --destination="/etc/cron.d/demo_switch" | tee -a "$LOG_BUILD_LXC" 2>&1
2016-09-18 19:23:54 +02:00
2022-10-15 22:25:49 +02:00
ynh_print_info --message="> and the upgrade cron" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-15 23:36:15 +02:00
ynh_add_config --template="$final_path/conf/cron_demo_upgrade" --destination="/etc/cron.d/demo_upgrade" | tee -a "$LOG_BUILD_LXC" 2>&1
2016-09-18 19:23:54 +02:00
2022-10-15 22:25:49 +02:00
ynh_print_info --message="> Setuping the service" | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-13 05:46:46 +02:00
#ynh_add_systemd_config --template="$final_path/conf/systemd.service"
ynh_add_systemd_config
2016-09-18 19:23:54 +02:00
2022-10-15 20:19:52 +02:00
ynh_print_info --message="> Integrating service in YunoHost..." | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-13 05:46:46 +02:00
yunohost service add $app --log="/var/log/$app/$app.log"
2016-09-18 19:23:54 +02:00
2022-10-15 20:19:52 +02:00
ynh_print_info --message="> Starting a systemd service..." | tee -a "$LOG_BUILD_LXC" 2>&1
2022-10-13 05:46:46 +02:00
ynh_systemd_action --service_name=$app --action="start" --log_path="systemd"
2022-10-15 22:25:49 +02:00
date | tee -a "$LOG_BUILD_LXC" 2>&1
ynh_print_info --message=">> Demo build finished." | tee -a "$LOG_BUILD_LXC" 2>&1