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

[autopatch] Automatic patch attempt for helpers 2.1 #181

Open
wants to merge 4 commits into
base: testing
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*~
*.sw[op]
.DS_Store
7 changes: 4 additions & 3 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ packaging_format = 2

id = "lxd"
name = "LXD"
description.en = "Offers a user experience similar to virtual machines but using Linux containers instead."
description.fr = "Offre une expérience utilisateur similaire aux machines virtuelles mais en utilisant des conteneurs Linux à la place."
description.en = "Manage virtual machines and system containers"
description.fr = "Gérer les machines virtuelles et les conteneurs système"

version = "6.1~ynh1"

Expand All @@ -20,7 +20,8 @@ code = "https://github.com/canonical/lxd"
cpe = "cpe:2.3:a:canonical:lxd"

[integration]
yunohost = ">= 11.2"
yunohost = ">= 11.2.30"
helpers_version = "2.1"
architectures = "all"
multi_instance = false
ldap = "not_relevant"
Expand Down
50 changes: 19 additions & 31 deletions scripts/_common.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
#!/bin/bash

#=================================================
# COMMON VARIABLES
#=================================================

#=================================================
# PERSONAL HELPERS
# COMMON VARIABLES AND CUSTOM HELPERS
#=================================================

# Create a dedicated systemd socket config
#
# usage: ynh_add_systemd_config [--socket=socket] [--template=template]
# usage: ynh_add_systemd_config [--socket=socket] [--template=template] [--others_var="list of others variables to replace"]
# usage: ynh_config_add_systemd [--socket=socket] [--template=template]
# usage: ynh_config_add_systemd [--socket=socket] [--template=template] [--others_var="list of others variables to replace"]
# | arg: -s, --socket= - socket name (optionnal, $app by default)
# | arg: -t, --template= - Name of template file (optionnal, this is 'systemd' by default, meaning ./conf/systemd.socket will be used as template)
# | arg: -v, --others_var= - List of others variables to replace separated by a space. For example: 'var_1 var_2 ...'
Expand All @@ -30,7 +26,7 @@
#
ynh_add_systemd_socket_config () {
# Declare an array to define the options of this helper.
local legacy_args=stv
#REMOVEME? local legacy_args=stv
local -A args_array=( [s]=socket= [t]=template= [v]=others_var= )
local socket
local template
Expand All @@ -42,27 +38,27 @@ ynh_add_systemd_socket_config () {
others_var="${others_var:-}"

finalsystemdconf="/etc/systemd/system/$socket.socket"
ynh_backup_if_checksum_is_different --file="$finalsystemdconf"
ynh_backup_if_checksum_is_different "$finalsystemdconf"
cp ../conf/$template "$finalsystemdconf"

# To avoid a break by set -u, use a void substitution ${var:-}. If the variable is not set, it's simply set with an empty variable.
# Substitute in a nginx config file only if the variable is not empty
if [ -n "${final_path:-}" ]; then
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$finalsystemdconf"
ynh_replace --match="__FINALPATH__" --replace="$final_path" --file="$finalsystemdconf"
fi
if [ -n "${app:-}" ]; then
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$finalsystemdconf"
ynh_replace --match="__APP__" --replace="$app" --file="$finalsystemdconf"
fi

# Replace all other variables given as arguments
for var_to_replace in $others_var
do
# ${var_to_replace^^} make the content of the variable on upper-cases
# ${!var_to_replace} get the content of the variable named $var_to_replace
ynh_replace_string --match_string="__${var_to_replace^^}__" --replace_string="${!var_to_replace}" --target_file="$finalsystemdconf"
ynh_replace --match="__${var_to_replace^^}__" --replace="${!var_to_replace}" --file="$finalsystemdconf"
done

ynh_store_file_checksum --file="$finalsystemdconf"
ynh_store_file_checksum "$finalsystemdconf"

chown root: "$finalsystemdconf"
systemctl enable "$socket.socket" --quiet
Expand All @@ -71,12 +67,12 @@ ynh_add_systemd_socket_config () {

# Remove the dedicated systemd socket config
#
# usage: ynh_remove_systemd_config [--socket=socket]
# usage: ynh_config_remove_systemd [--socket=socket]
# | arg: -s, --socket= - socket name (optionnal, $app by default)
#
ynh_remove_systemd_socket_config () {
# Declare an array to define the options of this helper.
local legacy_args=s
#REMOVEME? local legacy_args=s
local -A args_array=( [s]=socket= )
local socket
# Manage arguments with getopts
Expand All @@ -86,33 +82,33 @@ ynh_remove_systemd_socket_config () {
local finalsystemdconf="/etc/systemd/system/$socket.socket"
if [ -e "$finalsystemdconf" ]
then
ynh_systemd_action --service_name="$socket.socket" --action=stop
ynh_systemctl --service="$socket.socket" --action=stop
systemctl disable $socket.socket --quiet
ynh_secure_remove --file="$finalsystemdconf"
ynh_safe_rm "$finalsystemdconf"
systemctl daemon-reload
fi
}

_ynh_add_dnsmasq() {
ynh_add_config --template="dnsmasq.conf" --destination="/etc/dnsmasq.d/$app"
ynh_config_add --template="dnsmasq.conf" --destination="/etc/dnsmasq.d/$app"

ynh_systemd_action --service_name=dnsmasq --action=restart
ynh_systemctl --service=dnsmasq --action=restart
}

_ynh_remove_dnsmasq() {
ynh_secure_remove --file="/etc/dnsmasq.d/$app"
ynh_safe_rm "/etc/dnsmasq.d/$app"

ynh_systemd_action --service_name=dnsmasq --action=restart
ynh_systemctl --service=dnsmasq --action=restart
}

_ynh_add_ld_so() {
ynh_add_config --template="ld.so.conf" --destination="/etc/ld.so.conf.d/$app.conf"
ynh_config_add --template="ld.so.conf" --destination="/etc/ld.so.conf.d/$app.conf"

ldconfig
}

_ynh_remove_ld_so() {
ynh_secure_remove --file="/etc/ld.so.conf.d/$app.conf"
ynh_safe_rm "/etc/ld.so.conf.d/$app.conf"

ldconfig
}
Expand All @@ -124,11 +120,3 @@ _ynh_set_subuid_subgid() {
_ynh_unset_subuid_subgid() {
sed -i "/# Added by lxd$/{N;/root:100000:65536/d}" /etc/sub{u,g}id
}

#=================================================
# EXPERIMENTAL HELPERS
#=================================================

#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================
45 changes: 17 additions & 28 deletions scripts/backup
Original file line number Diff line number Diff line change
@@ -1,53 +1,42 @@
#!/bin/bash

#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================

# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers

#=================================================
# DECLARE DATA AND CONF FILES TO BACKUP
#=================================================
ynh_print_info --message="Declaring files to be backed up..."
ynh_print_info "Declaring files to be backed up..."

#=================================================
# SPECIFIC BACKUP
#=================================================
# BACKUP SYSTEMD
#=================================================

ynh_backup --src_path="/etc/systemd/system/$app.service"
ynh_backup --src_path="/etc/systemd/system/$app.socket"
ynh_backup "/etc/systemd/system/$app.service"
ynh_backup "/etc/systemd/system/$app.socket"

#=================================================
# BACKUP VARIOUS FILES
#=================================================

ynh_backup --src_path="/var/log/$app/"
ynh_backup "/var/log/$app/"

ynh_backup --src_path="/usr/local/lib/$app/"
ynh_backup "/usr/local/lib/$app/"

ynh_backup --src_path="/usr/local/bin/fuidshift"
ynh_backup --src_path="/usr/local/bin/lxc"
ynh_backup --src_path="/usr/local/bin/lxc-to-lxd"
ynh_backup --src_path="/usr/local/bin/lxd"
ynh_backup --src_path="/usr/local/bin/lxd-agent"
ynh_backup --src_path="/usr/local/bin/lxd-benchmark"
ynh_backup --src_path="/usr/local/bin/lxd-migrate"
ynh_backup --src_path="/usr/local/bin/lxd-user"
ynh_backup --src_path="/etc/bash_completion.d/lxd-client"
ynh_backup "/usr/local/bin/fuidshift"
ynh_backup "/usr/local/bin/lxc"
ynh_backup "/usr/local/bin/lxc-to-lxd"
ynh_backup "/usr/local/bin/lxd"
ynh_backup "/usr/local/bin/lxd-agent"
ynh_backup "/usr/local/bin/lxd-benchmark"
ynh_backup "/usr/local/bin/lxd-migrate"
ynh_backup "/usr/local/bin/lxd-user"
ynh_backup "/etc/bash_completion.d/lxd-client"

ynh_backup --src_path="/etc/dnsmasq.d/lxd"
ynh_backup "/etc/dnsmasq.d/lxd"

ynh_backup --src_path="/etc/ld.so.conf.d/$app.conf"
ynh_backup "/etc/ld.so.conf.d/$app.conf"

#=================================================
# END OF SCRIPT
#=================================================

ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."
ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)."
31 changes: 11 additions & 20 deletions scripts/install
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
#!/bin/bash

#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================

source _common.sh
source /usr/share/yunohost/helpers

#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=5
ynh_script_progression "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"
ynh_setup_source --source_id="main" --dest_dir="$install_dir/lxd"

Expand All @@ -23,21 +16,21 @@ ynh_setup_source --source_id="main" --dest_dir="$install_dir/lxd"
#=================================================
# BUILD FROM SOURCES
#=================================================
ynh_script_progression --message="Building lxd from sources..." --weight=60
ynh_script_progression "Building lxd from sources..."

pushd "$install_dir/lxd"
(
export PATH="$install_dir/go/bin:$PATH"
export GOPATH="$install_dir/lxd/vendor/"
export HOME=${HOME:-"/root/"}

ynh_exec_warn_less make deps
ynh_hide_warnings make deps
export CGO_CFLAGS="-I${GOPATH}dqlite/include/"
export CGO_LDFLAGS="-L${GOPATH}dqlite/.libs/"
export LD_LIBRARY_PATH="${GOPATH}dqlite/.libs/"
export CGO_LDFLAGS_ALLOW="(-Wl,-wrap,pthread_create)|(-Wl,-z,now)"

ynh_exec_warn_less make
ynh_hide_warnings make

mkdir -p /usr/local/lib/$app
mkdir -p /var/log/$app
Expand All @@ -47,18 +40,17 @@ pushd "$install_dir/lxd"
)
popd

ynh_secure_remove --file="$install_dir/go"
ynh_secure_remove --file="$install_dir/lxd"
ynh_safe_rm "$install_dir/go"
ynh_safe_rm "$install_dir/lxd"

#=================================================
# SYSTEM CONFIGURATION
#=================================================
ynh_script_progression --message="Adding system configurations related to $app..." --weight=1
ynh_script_progression "Adding system configurations related to $app..."

# Create a dedicated systemd config
ynh_add_systemd_socket_config

ynh_add_systemd_config
ynh_config_add_systemd
yunohost service add "$app" --log="/var/log/$app/$app.log"

_ynh_add_dnsmasq
Expand All @@ -70,13 +62,12 @@ _ynh_set_subuid_subgid
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..."
ynh_script_progression "Starting $app's systemd service..."

# Start a systemd service
ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log"
ynh_systemctl --service="$app" --action="start"

#=================================================
# END OF SCRIPT
#=================================================

ynh_script_progression --message="Installation of $app completed" --last
ynh_script_progression "Installation of $app completed"
Loading