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/install

154 lines
4.8 KiB
Text
Raw Normal View History

2021-03-01 14:53:57 +01:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
2021-03-01 19:00:42 +01:00
ynh_secure_remove --file="$go_tmp"
ynh_secure_remove --file="$lxd_tmp"
2021-03-01 14:53:57 +01:00
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
app=$YNH_APP_INSTANCE_NAME
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
2021-03-02 15:59:40 +01:00
ynh_script_progression --message="Storing installation settings..."
2021-03-01 14:53:57 +01:00
#=================================================
# STANDARD MODIFICATIONS
#=================================================
2021-03-01 19:00:42 +01:00
# OPEN A PORT
2021-03-01 14:53:57 +01:00
#=================================================
2021-03-02 15:59:40 +01:00
ynh_script_progression --message="Configuring firewall..."
2021-03-01 14:53:57 +01:00
2021-03-01 19:00:42 +01:00
ynh_exec_warn_less yunohost firewall allow --no-upnp Both 67
2021-03-01 14:53:57 +01:00
#=================================================
# INSTALL DEPENDENCIES
#=================================================
2021-03-02 15:59:40 +01:00
ynh_script_progression --message="Installing dependencies..." --weight=30
2021-03-01 14:53:57 +01:00
2021-03-02 15:44:34 +01:00
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
2021-03-01 14:53:57 +01:00
#=================================================
2021-03-01 19:00:42 +01:00
# DOWNLOAD, CHECK AND UNPACK SOURCE
2021-03-01 14:53:57 +01:00
#=================================================
2021-03-02 15:59:40 +01:00
ynh_script_progression --message="Setting up source files..." --weight=5
2021-03-01 19:00:42 +01:00
# 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
2021-03-01 14:53:57 +01:00
2021-03-01 19:00:42 +01:00
lxd_tmp=$(mktemp -d)
ynh_setup_source --dest_dir="$lxd_tmp" --source_id="lxd"
2021-03-01 14:53:57 +01:00
2021-03-01 19:00:42 +01:00
export GOPATH=${lxd_tmp}/_dist
2021-03-01 14:53:57 +01:00
#=================================================
2021-03-01 19:00:42 +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-01 19:00:42 +01:00
pushd ${lxd_tmp}
2021-03-01 14:53:57 +01:00
2021-03-02 15:44:34 +01:00
ynh_exec_warn_less make deps
2021-03-01 19:00:42 +01:00
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
2021-03-01 14:53:57 +01:00
2021-03-01 19:00:42 +01:00
# https://github.com/golang/go/issues/31997#issuecomment-782864390
go env -w GO111MODULE=auto
2021-03-02 15:44:34 +01:00
ynh_exec_warn_less make
2021-03-01 14:53:57 +01:00
2021-03-01 19:00:42 +01:00
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
popd
2021-03-01 14:53:57 +01:00
2021-03-01 19:00:42 +01:00
ynh_secure_remove --file="$go_tmp"
ynh_secure_remove --file="$lxd_tmp"
2021-03-01 14:53:57 +01:00
#=================================================
# CREATE DEDICATED USER
#=================================================
2021-03-02 15:59:40 +01:00
ynh_script_progression --message="Configuring system user..."
2021-03-01 14:53:57 +01:00
# Create a system user
ynh_system_user_create --username=$app
#=================================================
# SPECIFIC SETUP
#=================================================
# SETUP SYSTEMD
#=================================================
2021-03-02 15:59:40 +01:00
ynh_script_progression --message="Configuring a systemd service..."
2021-03-01 14:53:57 +01:00
# Create a dedicated systemd config
2021-03-01 19:00:42 +01:00
ynh_add_systemd_socket_config
2021-03-01 14:53:57 +01:00
ynh_add_systemd_config
#=================================================
# MODIFY A CONFIG FILE
#=================================================
2021-03-02 14:58:33 +01:00
echo "bind-interfaces
except-interface=lxdbr0" > /etc/dnsmasq.d/lxd
systemctl restart dnsmasq
ynh_store_file_checksum --file="/etc/dnsmasq.d/lxd"
2021-03-01 19:00:42 +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 19:00:42 +01:00
ldconfig
2021-03-01 14:53:57 +01:00
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
#=================================================
# GENERIC FINALIZATION
#=================================================
# 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-03-01 19:00:42 +01:00
yunohost service add $app --log="/var/log/$app/$app.log" --needs_exposed_ports=67
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
# Start a systemd service
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="Installation of $app completed" --last