2021-03-01 14:53:57 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2021-03-02 15:59:40 +01:00
|
|
|
ynh_script_progression --message="Loading installation settings..."
|
2021-03-01 14:53:57 +01:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
2021-03-02 15:59:40 +01:00
|
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
|
2021-03-01 14:53:57 +01:00
|
|
|
|
|
|
|
# Backup the current version of the app
|
|
|
|
ynh_backup_before_upgrade
|
|
|
|
ynh_clean_setup () {
|
2021-05-25 14:44:10 +02:00
|
|
|
ynh_exec_warn_less popd
|
|
|
|
|
2021-03-02 14:58:33 +01:00
|
|
|
ynh_secure_remove --file="$go_tmp"
|
|
|
|
ynh_secure_remove --file="$lxd_tmp"
|
2021-03-01 14:53:57 +01:00
|
|
|
# Restore it if the upgrade fails
|
|
|
|
ynh_restore_upgradebackup
|
|
|
|
}
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
2022-02-23 14:59:25 +01:00
|
|
|
# Remove old file
|
|
|
|
if [ -f "/usr/local/bin/lxd-p2c" ]; then
|
|
|
|
ynh_secure_remove --file="/usr/local/bin/lxd-p2c"
|
|
|
|
fi
|
|
|
|
|
2021-03-01 14:53:57 +01:00
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
# STOP SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2021-03-02 15:59:40 +01:00
|
|
|
ynh_script_progression --message="Stopping a systemd service..."
|
2021-03-01 14:53:57 +01:00
|
|
|
|
2021-10-12 13:32:48 +02:00
|
|
|
ynh_systemd_action --service_name="$app.socket" --action="stop"
|
2021-03-01 14:53:57 +01:00
|
|
|
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
|
|
|
|
|
|
|
|
#=================================================
|
2022-07-27 20:53:30 +02:00
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
2021-03-01 14:53:57 +01:00
|
|
|
#=================================================
|
2022-07-27 20:53:30 +02:00
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..."
|
2021-03-01 14:53:57 +01:00
|
|
|
|
2022-07-27 20:53:30 +02:00
|
|
|
sed -i "/root:1000000:65536 # Added by lxd#/d" /etc/sub{u,g}id
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# 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
|
2021-03-01 14:53:57 +01:00
|
|
|
|
2021-03-02 15:44:34 +01:00
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
2021-03-02 15:59:40 +01:00
|
|
|
ynh_script_progression --message="Setting up source files..."
|
2021-03-01 14:53:57 +01:00
|
|
|
|
2021-03-02 14:58:33 +01:00
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
|
|
go_tmp=$(mktemp -d)
|
2022-07-27 20:53:30 +02:00
|
|
|
ynh_setup_source --dest_dir="$go_tmp" --source_id="go.$YNH_ARCH"
|
2021-03-02 14:58:33 +01:00
|
|
|
|
|
|
|
export PATH=$go_tmp/bin:$PATH
|
|
|
|
|
|
|
|
lxd_tmp=$(mktemp -d)
|
|
|
|
ynh_setup_source --dest_dir="$lxd_tmp" --source_id="lxd"
|
2021-03-01 14:53:57 +01:00
|
|
|
|
2021-09-06 15:17:18 +02:00
|
|
|
export GOPATH=${lxd_tmp}/vendor/
|
2021-03-01 14:53:57 +01:00
|
|
|
|
2022-07-27 20:53:30 +02:00
|
|
|
#=================================================
|
|
|
|
# UPGRADE DEPENDENCIES
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrading dependencies..."
|
|
|
|
|
|
|
|
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
2021-03-01 14:53:57 +01:00
|
|
|
#=================================================
|
2021-03-02 14:58:33 +01:00
|
|
|
# BUILD FROM SOURCES
|
2021-03-01 14:53:57 +01:00
|
|
|
#=================================================
|
2021-03-02 15:59:40 +01:00
|
|
|
ynh_script_progression --message="Building lxd from sources..." --weight=60
|
2021-03-01 14:53:57 +01:00
|
|
|
|
2021-03-02 14:58:33 +01:00
|
|
|
pushd ${lxd_tmp}
|
2022-07-27 20:53:30 +02:00
|
|
|
export HOME=${HOME:-"/root/"}
|
2021-03-02 14:58:33 +01:00
|
|
|
|
2022-07-27 20:53:30 +02:00
|
|
|
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)"
|
2021-03-02 14:58:33 +01:00
|
|
|
|
2022-07-27 20:53:30 +02:00
|
|
|
export GOCACHE=$go_tmp
|
2021-05-25 16:32:15 +02:00
|
|
|
|
2022-07-27 20:53:30 +02:00
|
|
|
ynh_exec_warn_less make
|
2021-03-02 14:58:33 +01:00
|
|
|
|
2022-07-27 20:53:30 +02:00
|
|
|
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 ${lxd_tmp}/scripts/bash/lxd-client /etc/bash_completion.d/
|
2021-03-02 14:58:33 +01:00
|
|
|
popd
|
|
|
|
|
|
|
|
ynh_secure_remove --file="$go_tmp"
|
|
|
|
ynh_secure_remove --file="$lxd_tmp"
|
2021-03-01 14:53:57 +01:00
|
|
|
|
|
|
|
#=================================================
|
2022-07-27 20:53:30 +02:00
|
|
|
# UPDATE A CONFIG FILE
|
2021-03-01 14:53:57 +01:00
|
|
|
#=================================================
|
2022-07-27 20:53:30 +02:00
|
|
|
ynh_script_progression --message="Updating a configuration file..."
|
2021-03-01 14:53:57 +01:00
|
|
|
|
2021-03-02 14:58:33 +01:00
|
|
|
ynh_backup_if_checksum_is_different --file="/etc/dnsmasq.d/lxd"
|
2021-03-01 14:53:57 +01:00
|
|
|
|
2021-03-02 14:58:33 +01:00
|
|
|
echo "bind-interfaces
|
|
|
|
except-interface=lxdbr0" > /etc/dnsmasq.d/lxd
|
|
|
|
systemctl restart dnsmasq
|
2021-03-01 14:53:57 +01:00
|
|
|
|
2021-03-02 14:58:33 +01:00
|
|
|
ynh_store_file_checksum --file="/etc/dnsmasq.d/lxd"
|
2021-03-01 14:53:57 +01:00
|
|
|
|
2021-03-02 14:58:33 +01:00
|
|
|
ynh_backup_if_checksum_is_different --file="/etc/ld.so.conf.d/$app.conf"
|
2021-03-01 14:53:57 +01:00
|
|
|
|
2021-03-02 14:58:33 +01:00
|
|
|
echo "/usr/local/lib/$app/" > /etc/ld.so.conf.d/$app.conf
|
2021-03-01 14:53:57 +01:00
|
|
|
|
2021-03-02 14:58:33 +01:00
|
|
|
ynh_store_file_checksum --file="/etc/ld.so.conf.d/$app.conf"
|
2021-03-01 14:53:57 +01:00
|
|
|
|
2021-03-02 14:58:33 +01:00
|
|
|
ldconfig
|
|
|
|
|
2021-03-16 13:43:01 +01:00
|
|
|
echo "# Added by lxd
|
|
|
|
root:100000:65536" | tee -a /etc/subuid /etc/subgid
|
2021-03-01 14:53:57 +01:00
|
|
|
|
2022-07-27 20:53:30 +02:00
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrading systemd configuration..."
|
|
|
|
|
|
|
|
# Create a dedicated systemd config
|
|
|
|
ynh_add_systemd_socket_config
|
|
|
|
ynh_add_systemd_config
|
|
|
|
|
2021-03-02 14:58:33 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
2021-03-01 14:53:57 +01:00
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
2021-03-02 15:59:40 +01:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
2021-03-01 14:53:57 +01:00
|
|
|
|
2021-04-12 12:26:14 +02:00
|
|
|
yunohost service add $app --log="/var/log/$app/$app.log"
|
2021-03-01 14:53:57 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2021-03-02 15:59:40 +01:00
|
|
|
ynh_script_progression --message="Starting a systemd service..."
|
2021-03-01 14:53:57 +01:00
|
|
|
|
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2021-03-02 15:59:40 +01:00
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|