1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/lxd_ynh.git synced 2024-09-03 19:45:53 +02:00
lxd_ynh/scripts/upgrade

104 lines
3.5 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..."
ynh_systemd_action --service_name="$app.socket" --action="stop"
ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log"
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
ynh_script_progression --message="Ensuring downward compatibility..."
# Remove old file
if [ -f "/usr/local/bin/lxd-p2c" ]; then
ynh_secure_remove --file="/usr/local/bin/lxd-p2c"
fi
sed -i "/root:1000000:65536 # Added by lxd#/d" /etc/sub{u,g}id
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..."
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --source_id="go" --dest_dir="$install_dir/go" --full_replace=1
export PATH="$install_dir/go/bin:$PATH"
ynh_setup_source --source_id="main" --dest_dir="$install_dir/lxd" --full_replace=1
export GOPATH="$install_dir/lxd/vendor/"
#=================================================
# SPECIFIC UPGRADE
#=================================================
# BUILD FROM SOURCES
#=================================================
ynh_script_progression --message="Building lxd from sources..." --weight=60
pushd "$install_dir/lxd"
export HOME=${HOME:-"/root/"}
ynh_exec_warn_less make deps
export CGO_CFLAGS="-I${GOPATH}/raft/include/ -I${GOPATH}/dqlite/include/"
export CGO_LDFLAGS="-L${GOPATH}/raft/.libs -L${GOPATH}/dqlite/.libs/"
export LD_LIBRARY_PATH="${GOPATH}/raft/.libs/:${GOPATH}/dqlite/.libs/"
export CGO_LDFLAGS_ALLOW="(-Wl,-wrap,pthread_create)|(-Wl,-z,now)"
ynh_exec_warn_less make
mkdir -p /usr/local/lib/$app
mkdir -p /var/log/$app
cp -a ${GOPATH}/{raft,dqlite}/.libs/lib*.so* /usr/local/lib/$app/
cp ${GOPATH}/bin/{fuidshift,lxc,lxc-to-lxd,lxd,lxd-agent,lxd-benchmark,lxd-migrate,lxd-user} /usr/local/bin
cp $install_dir/lxd/scripts/bash/lxd-client /etc/bash_completion.d/
popd
ynh_secure_remove --file="$install_dir/go"
ynh_secure_remove --file="$install_dir/lxd"
#=================================================
# REAPPLY SYSTEM CONFIGURATIONS
#=================================================
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
# Create a dedicated systemd config
ynh_add_systemd_socket_config
ynh_add_systemd_config
yunohost service add "$app" --log="/var/log/$app/$app.log"
_ynh_add_dnsmasq
_ynh_add_ld_so
_ynh_set_subuid_subgid
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting 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