mirror of
https://github.com/YunoHost-Apps/lxd_ynh.git
synced 2024-09-03 19:45:53 +02:00
165 lines
5.3 KiB
Bash
165 lines
5.3 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# LOAD SETTINGS
|
|
#=================================================
|
|
ynh_script_progression --message="Loading installation settings..."
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
#=================================================
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
#=================================================
|
|
ynh_script_progression --message="Ensuring downward compatibility..."
|
|
|
|
sed -i "/root:1000000:65536 # Added by lxd#/d" /etc/sub{u,g}id
|
|
|
|
#=================================================
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
#=================================================
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
|
|
|
|
# Backup the current version of the app
|
|
ynh_backup_before_upgrade
|
|
ynh_clean_setup () {
|
|
ynh_exec_warn_less popd
|
|
|
|
ynh_secure_remove --file="$go_tmp"
|
|
ynh_secure_remove --file="$lxd_tmp"
|
|
# Restore it if the upgrade fails
|
|
ynh_restore_upgradebackup
|
|
}
|
|
# Exit if an error occurs during the execution of the script
|
|
ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# STANDARD UPGRADE STEPS
|
|
#=================================================
|
|
# STOP SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Stopping a systemd service..."
|
|
|
|
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
|
|
|
|
#=================================================
|
|
# UPGRADE DEPENDENCIES
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading dependencies..."
|
|
|
|
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
ynh_script_progression --message="Setting up source files..."
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
go_tmp=$(mktemp -d)
|
|
ynh_setup_source --dest_dir="$go_tmp" --source_id="go.$(ynh_detect_arch)"
|
|
|
|
export PATH=$go_tmp/bin:$PATH
|
|
|
|
lxd_tmp=$(mktemp -d)
|
|
ynh_setup_source --dest_dir="$lxd_tmp" --source_id="lxd"
|
|
|
|
export GOPATH=${lxd_tmp}/_dist
|
|
|
|
#=================================================
|
|
# BUILD FROM SOURCES
|
|
#=================================================
|
|
ynh_script_progression --message="Building lxd from sources..." --weight=60
|
|
|
|
pushd ${lxd_tmp}
|
|
|
|
ynh_exec_warn_less make deps
|
|
export CGO_CFLAGS="-I${GOPATH}/deps/raft/include/ -I${GOPATH}/deps/dqlite/include/"
|
|
export CGO_LDFLAGS="-L${GOPATH}/deps/raft/.libs -L${GOPATH}/deps/dqlite/.libs/"
|
|
export LD_LIBRARY_PATH="${GOPATH}/deps/raft/.libs/:${GOPATH}/deps/dqlite/.libs/"
|
|
export CGO_LDFLAGS_ALLOW="-Wl,-wrap,pthread_create"
|
|
cd $GOPATH/src/github.com/lxc/lxd
|
|
|
|
ynh_exec_warn_less make
|
|
|
|
mkdir -p /usr/local/lib/$app
|
|
mkdir -p /var/log/$app
|
|
cp -a ${GOPATH}/deps/{raft,dqlite}/.libs/lib*.so* /usr/local/lib/$app/
|
|
cp ${GOPATH}/bin/{lxc,lxd,lxc-to-lxd,lxd-p2c} /usr/local/bin
|
|
cp ${lxd_tmp}/scripts/bash/lxd-client /etc/bash_completion.d/
|
|
popd
|
|
|
|
ynh_secure_remove --file="$go_tmp"
|
|
ynh_secure_remove --file="$lxd_tmp"
|
|
|
|
#=================================================
|
|
# CREATE DEDICATED USER
|
|
#=================================================
|
|
ynh_script_progression --message="Making sure dedicated system user exists..."
|
|
|
|
# Create a dedicated user (if not existing)
|
|
ynh_system_user_create --username=$app
|
|
|
|
#=================================================
|
|
# SPECIFIC UPGRADE
|
|
#=================================================
|
|
# SETUP SYSTEMD
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring a systemd service..."
|
|
|
|
# Create a dedicated systemd config
|
|
ynh_add_systemd_socket_config
|
|
ynh_add_systemd_config
|
|
|
|
#=================================================
|
|
# MODIFY A CONFIG FILE
|
|
#=================================================
|
|
|
|
ynh_backup_if_checksum_is_different --file="/etc/dnsmasq.d/lxd"
|
|
|
|
echo "bind-interfaces
|
|
except-interface=lxdbr0" > /etc/dnsmasq.d/lxd
|
|
systemctl restart dnsmasq
|
|
|
|
ynh_store_file_checksum --file="/etc/dnsmasq.d/lxd"
|
|
|
|
ynh_backup_if_checksum_is_different --file="/etc/ld.so.conf.d/$app.conf"
|
|
|
|
echo "/usr/local/lib/$app/" > /etc/ld.so.conf.d/$app.conf
|
|
|
|
ynh_store_file_checksum --file="/etc/ld.so.conf.d/$app.conf"
|
|
|
|
ldconfig
|
|
|
|
echo "# Added by lxd
|
|
root:100000:65536" | tee -a /etc/subuid /etc/subgid
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
#=================================================
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
|
|
|
yunohost service add $app --log="/var/log/$app/$app.log"
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Starting a systemd service..."
|
|
|
|
# Start a systemd service
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|