diff --git a/.github/workflows/updater.sh b/.github/workflows/updater.sh index 5cae7a4..6583088 100644 --- a/.github/workflows/updater.sh +++ b/.github/workflows/updater.sh @@ -9,98 +9,32 @@ # Since each app is different, maintainers can adapt its contents so as to perform # automatic actions when a new upstream release is detected. -#================================================= -# FETCHING LATEST RELEASE AND ITS ASSETS -#================================================= - -# Fetching information -current_version=$(cat manifest.json | jq -j '.version|split("~")[0]') -repo=$(cat manifest.json | jq -j '.upstream.code|split("https://github.com/")[1]') -# Some jq magic is needed, because the latest upstream release is not always the latest version (e.g. security patches for older versions) -version=$(curl --silent "https://api.github.com/repos/$repo/releases" | jq -r '.[] | select( .prerelease != true ) | .tag_name' | sort -V | tail -1) -assets=($(curl --silent "https://api.github.com/repos/$repo/releases" | jq -r '[ .[] | select(.tag_name=="'$version'").assets[].browser_download_url ] | join(" ") | @sh' | tr -d "'")) - -# Later down the script, we assume the version has only digits and dots -# Sometimes the release name starts with a "v", so let's filter it out. -# You may need more tweaks here if the upstream repository has different naming conventions. -if [[ ${version:0:3} == "lxd" ]]; then - version=${version:4} -fi - -# Setting up the environment variables -echo "Current version: $current_version" -echo "Latest release from upstream: $version" -echo "VERSION=$version" >> $GITHUB_ENV -# For the time being, let's assume the script will fail -echo "PROCEED=false" >> $GITHUB_ENV - -# Proceed only if the retrieved version is greater than the current one -if ! dpkg --compare-versions "$current_version" "lt" "$version" ; then - echo "::warning ::No new version available" - exit 0 -# Proceed only if a PR for this new version does not already exist -elif git ls-remote -q --exit-code --heads https://github.com/$GITHUB_REPOSITORY.git ci-auto-update-v$version ; then - echo "::warning ::A branch already exists for this update" - exit 0 -fi - -# Each release can hold multiple assets (e.g. binaries for different architectures, source code, etc.) -echo "${#assets[@]} available asset(s)" - -#================================================= -# UPDATE SOURCE FILES -#================================================= - -# Here we use the $assets variable to get the resources published in the upstream release. -# Here is an example for Grav, it has to be adapted in accordance with how the upstream releases look like. - -# Let's loop over the array of assets URLs -for asset_url in "${assets[@]}"; do - -echo "Handling asset at $asset_url" - -src="lxd" - -# Create the temporary directory -tempdir="$(mktemp -d)" - -# Download sources and calculate checksum -filename=${asset_url##*/} -curl --silent -4 -L $asset_url -o "$tempdir/$filename" -checksum=$(sha256sum "$tempdir/$filename" | head -c 64) - -# Delete temporary directory -rm -rf $tempdir - -# Get extension -if [[ $filename == *.tar.gz ]]; then - extension=tar.gz -else - echo "... asset ignored" - continue -fi - -# Rewrite source file -cat < conf/$src.src -SOURCE_URL=$asset_url -SOURCE_SUM=$checksum -SOURCE_SUM_PRG=sha256sum -SOURCE_FORMAT=$extension -SOURCE_IN_SUBDIR=true -SOURCE_FILENAME= -SOURCE_EXTRACT=true -EOT -echo "... conf/$src.src updated" - -done - #================================================= # Update Go #================================================= go_url="https://go.dev/dl/?mode=json" +current_version=$(cat manifest.toml | sed -n "s/\"https:\/\/go.dev\/dl\/go\(.*\).linux-amd64.tar.gz\"/\1/p" | cut -d'=' -f2) go_version=$(curl --silent "$go_url" | jq -r '.[] | .version' | sort -V | tail -1) go_arch=($(curl --silent "$go_url" | jq -r '.[] | select(.version=="'$go_version'") | .files[] | select(.os == "linux") | .arch')) + +# Setting up the environment variables +echo "Current version: $current_version" +echo "Latest release from upstream: ${go_version#go}" +echo "VERSION=${go_version#go}" >> $GITHUB_ENV +# For the time being, let's assume the script will fail +echo "PROCEED=false" >> $GITHUB_ENV + +# Proceed only if the retrieved version is greater than the current one +if ! dpkg --compare-versions "$current_version" "lt" "${go_version#go}" ; then + echo "::warning ::No new version available" + exit 0 +# Proceed only if a PR for this new version does not already exist +elif git ls-remote -q --exit-code --heads https://github.com/$GITHUB_REPOSITORY.git ci-auto-update-go-v$version ; then + echo "::warning ::A branch already exists for this update" + exit 0 +fi + for arch in "${go_arch[@]}" do filename=$(curl --silent "$go_url" | jq -r '.[] | select(.version=="'$go_version'") | .files[] | select(.os == "linux") | select(.arch == "'$arch'") | .filename') @@ -127,17 +61,11 @@ do continue fi - # Rewrite source file - cat < conf/go.$src.src -SOURCE_URL=https://go.dev/dl/$filename -SOURCE_SUM=$checksum -SOURCE_SUM_PRG=sha256sum -SOURCE_FORMAT=tar.gz -SOURCE_IN_SUBDIR=true -SOURCE_FILENAME= -SOURCE_EXTRACT=true -EOT - echo "... conf/go.$src.src updated" + # Rewrite manifest.toml file + sed -i "s/$src.url = \"https:\/\/go.dev.*/$src.url = \"https:\/\/go.dev\/dl\/$filename\"/g" manifest.toml + sed -i "s/$src.sha256 = \".*/$src.sha256 = \"$checksum\"/g" manifest.toml + + echo "... resource go.$src updated" done @@ -152,11 +80,8 @@ done # GENERIC FINALIZATION #================================================= -# Replace new version in manifest -echo "$(jq -s --indent 4 ".[] | .version = \"$version~ynh1\"" manifest.json)" > manifest.json - # No need to update the README, yunohost-bot takes care of it # The Action will proceed only if the PROCEED environment variable is set to true echo "PROCEED=true" >> $GITHUB_ENV -exit 0 +exit 0 \ No newline at end of file diff --git a/.github/workflows/updater.yml b/.github/workflows/updater.yml index a56d7cb..cdc9a4a 100644 --- a/.github/workflows/updater.yml +++ b/.github/workflows/updater.yml @@ -29,21 +29,21 @@ jobs: id: commit if: ${{ env.PROCEED == 'true' }} run: | - git commit -am "Upgrade to v$VERSION" + git commit -am "Upgrade go to v$VERSION" - name: Create Pull Request id: cpr if: ${{ env.PROCEED == 'true' }} uses: peter-evans/create-pull-request@v4 with: token: ${{ secrets.GITHUB_TOKEN }} - commit-message: Update to version ${{ env.VERSION }} + commit-message: Update go to version ${{ env.VERSION }} committer: 'yunohost-bot ' author: 'yunohost-bot ' signoff: false base: testing - branch: ci-auto-update-v${{ env.VERSION }} + branch: ci-auto-update-go-v${{ env.VERSION }} delete-branch: true - title: 'Upgrade to version ${{ env.VERSION }}' + title: 'Upgrade go to version ${{ env.VERSION }}' body: | - Upgrade to v${{ env.VERSION }} - draft: false + Upgrade go to v${{ env.VERSION }} + draft: false \ No newline at end of file diff --git a/README.md b/README.md index 3f430f5..0dde584 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ @@ -26,12 +26,6 @@ LXD is a next generation system container and virtual machine manager. It offers ![Screenshot of LXD](./doc/screenshots/LXD-logo.png) -## Disclaimers / important information - -## Configuration - -How to configure this app: In cli - ## Documentation and resources * Official app website: @@ -52,4 +46,4 @@ or sudo yunohost app upgrade lxd -u https://github.com/YunoHost-Apps/lxd_ynh/tree/testing --debug ``` -**More info regarding app packaging:** +**More info regarding app packaging:** \ No newline at end of file diff --git a/README_fr.md b/README_fr.md index 6acf499..c9cf7de 100644 --- a/README_fr.md +++ b/README_fr.md @@ -1,5 +1,5 @@ @@ -27,12 +27,6 @@ LXD est un gestionnaire de conteneurs système et de machines virtuelles de nouv ![Capture d’écran de LXD](./doc/screenshots/LXD-logo.png) -## Avertissements / informations importantes - -## Configuration - -Comment configurer cette application : en cli - ## Documentations et ressources * Site officiel de l’app : diff --git a/check_process b/check_process deleted file mode 100644 index 7affb53..0000000 --- a/check_process +++ /dev/null @@ -1,12 +0,0 @@ -;; Test complet - ; Manifest - ; Checks - pkg_linter=1 - setup_nourl=1 - upgrade=1 - upgrade=1 from_commit=b66ae64c2dae8595c817f058c4e45cd7cc40ac64 - backup_restore=1 -;;; Options -Email= -Notification=none - diff --git a/conf/dnsmasq.conf b/conf/dnsmasq.conf new file mode 100644 index 0000000..1377981 --- /dev/null +++ b/conf/dnsmasq.conf @@ -0,0 +1,2 @@ +bind-interfaces +except-interface=lxdbr0 diff --git a/conf/go.amd64.src b/conf/go.amd64.src deleted file mode 100644 index 4c0a560..0000000 --- a/conf/go.amd64.src +++ /dev/null @@ -1,7 +0,0 @@ -SOURCE_URL=https://go.dev/dl/go1.21.5.linux-amd64.tar.gz -SOURCE_SUM=e2bc0b3e4b64111ec117295c088bde5f00eeed1567999ff77bc859d7df70078e -SOURCE_SUM_PRG=sha256sum -SOURCE_FORMAT=tar.gz -SOURCE_IN_SUBDIR=true -SOURCE_FILENAME= -SOURCE_EXTRACT=true diff --git a/conf/go.arm.src b/conf/go.arm.src deleted file mode 100644 index 06a18bc..0000000 --- a/conf/go.arm.src +++ /dev/null @@ -1,7 +0,0 @@ -SOURCE_URL=https://go.dev/dl/go1.21.5.linux-armv6l.tar.gz -SOURCE_SUM=837f4bf4e22fcdf920ffeaa4abf3d02d1314e03725431065f4d44c46a01b42fe -SOURCE_SUM_PRG=sha256sum -SOURCE_FORMAT=tar.gz -SOURCE_IN_SUBDIR=true -SOURCE_FILENAME= -SOURCE_EXTRACT=true diff --git a/conf/go.arm64.src b/conf/go.arm64.src deleted file mode 100644 index 5eec401..0000000 --- a/conf/go.arm64.src +++ /dev/null @@ -1,7 +0,0 @@ -SOURCE_URL=https://go.dev/dl/go1.21.5.linux-arm64.tar.gz -SOURCE_SUM=841cced7ecda9b2014f139f5bab5ae31785f35399f236b8b3e75dff2a2978d96 -SOURCE_SUM_PRG=sha256sum -SOURCE_FORMAT=tar.gz -SOURCE_IN_SUBDIR=true -SOURCE_FILENAME= -SOURCE_EXTRACT=true diff --git a/conf/go.i386.src b/conf/go.i386.src deleted file mode 100644 index 0d6add7..0000000 --- a/conf/go.i386.src +++ /dev/null @@ -1,7 +0,0 @@ -SOURCE_URL=https://go.dev/dl/go1.21.5.linux-386.tar.gz -SOURCE_SUM=8f4dba9cf5c61757bbd7e9ebdb93b6a30a1b03f4a636a1ba0cc2f27b907ab8e1 -SOURCE_SUM_PRG=sha256sum -SOURCE_FORMAT=tar.gz -SOURCE_IN_SUBDIR=true -SOURCE_FILENAME= -SOURCE_EXTRACT=true diff --git a/conf/ld.so.conf b/conf/ld.so.conf new file mode 100644 index 0000000..2eabc70 --- /dev/null +++ b/conf/ld.so.conf @@ -0,0 +1 @@ +/usr/local/lib/__APP__/ diff --git a/conf/lxd.src b/conf/lxd.src deleted file mode 100644 index 473da13..0000000 --- a/conf/lxd.src +++ /dev/null @@ -1,7 +0,0 @@ -SOURCE_URL=https://github.com/canonical/lxd/releases/download/lxd-5.20/lxd-5.20.tar.gz -SOURCE_SUM=2f958b757f4cde64d0f3578da0bda9ee5965a3a70ec0956eddf8287d1290167f -SOURCE_SUM_PRG=sha256sum -SOURCE_FORMAT=tar.gz -SOURCE_IN_SUBDIR=true -SOURCE_FILENAME= -SOURCE_EXTRACT=true diff --git a/doc/DISCLAIMER.md b/doc/ADMIN.md similarity index 100% rename from doc/DISCLAIMER.md rename to doc/ADMIN.md diff --git a/doc/DISCLAIMER_fr.md b/doc/ADMIN_fr.md similarity index 100% rename from doc/DISCLAIMER_fr.md rename to doc/ADMIN_fr.md diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 92f3592..0000000 --- a/manifest.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "name": "LXD", - "id": "lxd", - "packaging_format": 1, - "description": { - "en": "Offers a user experience similar to virtual machines but using Linux containers instead.", - "fr": "Offre une expérience utilisateur similaire aux machines virtuelles mais en utilisant des conteneurs Linux à la place." - }, - "version": "5.20~ynh1", - "url": "https://example.com", - "upstream": { - "license": "Apache-2.0", - "website": "https://linuxcontainers.org/lxd/", - "demo": "https://linuxcontainers.org/lxd/try-it/", - "admindoc": "https://linuxcontainers.org/lxd/docs/master/index.html", - "code": "https://github.com/canonical/lxd" - }, - "license": "Apache-2.0", - "maintainer": { - "name": "kay0u", - "email": "pierre@kayou.io" - }, - "requirements": { - "yunohost": ">= 4.3.0" - }, - "multi_instance": false, - "services": [], - "arguments": { - "install": [] - } -} diff --git a/manifest.toml b/manifest.toml new file mode 100644 index 0000000..5fc7c8d --- /dev/null +++ b/manifest.toml @@ -0,0 +1,90 @@ +#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/manifest.v2.schema.json + +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." + +version = "5.20~ynh1" + +maintainers = ["kay0u"] + +[upstream] +license = "Apache-2.0" +website = "https://linuxcontainers.org/lxd/" +demo = "https://linuxcontainers.org/lxd/try-it/" +admindoc = "https://linuxcontainers.org/lxd/docs/master/index.html" +code = "https://github.com/canonical/lxd" +cpe = "cpe:2.3:a:canonical:lxd" + +[integration] +yunohost = ">= 4.3.0" +architectures = "all" +multi_instance = false +ldap = "not_relevant" +sso = "not_relevant" +disk = "500M" +ram.build = "600M" +ram.runtime = "500M" + +[install] + +[resources] + [resources.sources] + [resources.sources.go] + amd64.url = "https://go.dev/dl/go1.22.0.linux-amd64.tar.gz" + amd64.sha256 = "f6c8a87aa03b92c4b0bf3d558e28ea03006eb29db78917daec5cfb6ec1046265" + i386.url = "https://go.dev/dl/go1.22.0.linux-386.tar.gz" + i386.sha256 = "1e209c4abde069067ac9afb341c8003db6a210f8173c77777f02d3a524313da3" + arm64.url = "https://go.dev/dl/go1.22.0.linux-arm64.tar.gz" + arm64.sha256 = "6a63fef0e050146f275bf02a0896badfe77c11b6f05499bb647e7bd613a45a10" + armhf.url = "https://go.dev/dl/go1.21.5.linux-armv6l.tar.gz" + armhf.sha256 = "837f4bf4e22fcdf920ffeaa4abf3d02d1314e03725431065f4d44c46a01b42fe" + + [resources.sources.lxd] + url = "https://github.com/canonical/lxd/releases/download/lxd-5.20/lxd-5.20.tar.gz" + sha256 = "2f958b757f4cde64d0f3578da0bda9ee5965a3a70ec0956eddf8287d1290167f" + autoupdate.strategy = "latest_github_release" + + [resources.system_user] + + [resources.install_dir] + + [resources.permissions] + + [resources.apt] + packages = [ + # According to https://documentation.ubuntu.com/lxd/en/latest/installing/#install-lxd-from-source + "acl", + "attr", + "autoconf", + "automake", + "dnsmasq-base", + "git", + "libacl1-dev", + "libcap-dev", + "liblxc1", + "lxc-dev", + "libsqlite3-dev", + "libtool", + "libudev-dev", + "liblz4-dev", + "libuv1-dev", + "make", + "pkg-config", + "rsync", + "squashfs-tools", + "tar", + "tcl", + "xz-utils", + "ebtables", + + # For lvm2 + "lvm2", + "thin-provisioning-tools", + + # For btrfs + "btrfs-progs" + ] diff --git a/scripts/_common.sh b/scripts/_common.sh index 37c653b..7cee4c8 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -4,9 +4,6 @@ # COMMON VARIABLES #================================================= -# dependencies used by the app -pkg_dependencies="acl attr autoconf dnsmasq-base git libacl1-dev libcap-dev liblxc1 lxc-dev libsqlite3-dev libtool libudev-dev liblz4-dev libuv1-dev make pkg-config rsync squashfs-tools tar tcl xz-utils ebtables libapparmor-dev libseccomp-dev libcap-dev lvm2 thin-provisioning-tools btrfs-progs busybox|busybox-static libattr1-dev libuv1 libdevmapper-event1.02.1 dmeventd lxc tcl8.6" - #================================================= # PERSONAL HELPERS #================================================= @@ -61,7 +58,7 @@ ynh_add_systemd_socket_config () { 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 + # ${!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" done @@ -96,6 +93,38 @@ ynh_remove_systemd_socket_config () { fi } +_ynh_add_dnsmasq() { + ynh_add_config --template="dnsmasq.conf" --destination="/etc/dnsmasq.d/$app" + + ynh_systemd_action --service_name=dnsmasq --action=restart +} + +_ynh_remove_dnsmasq() { + ynh_secure_remove --file="/etc/dnsmasq.d/$app" + + ynh_systemd_action --service_name=dnsmasq --action=restart +} + +_ynh_add_ld_so() { + ynh_add_config --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" + + ldconfig +} + +_ynh_set_subuid_subgid() { + echo -e "# Added by lxd\nroot:100000:65536" | tee -a /etc/subuid /etc/subgid +} + +_ynh_unset_subuid_subgid() { + sed -i "/# Added by lxd$/{N;/root:100000:65536/d}" /etc/sub{u,g}id +} + #================================================= # EXPERIMENTAL HELPERS #================================================= diff --git a/scripts/backup b/scripts/backup index 402b1e8..70cf656 100755 --- a/scripts/backup +++ b/scripts/backup @@ -10,23 +10,6 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -ynh_clean_setup () { - true -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# LOAD SETTINGS -#================================================= -ynh_print_info --message="Loading installation settings..." - -app=$YNH_APP_INSTANCE_NAME - #================================================= # DECLARE DATA AND CONF FILES TO BACKUP #================================================= diff --git a/scripts/install b/scripts/install index 0a5e584..3bf9c53 100755 --- a/scripts/install +++ b/scripts/install @@ -9,62 +9,14 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -ynh_clean_setup () { - ynh_exec_warn_less popd - - ynh_secure_remove --file="$go_tmp" - ynh_secure_remove --file="$lxd_tmp" -} -# 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 -#================================================= -ynh_script_progression --message="Storing installation settings..." - -#================================================= -# STANDARD MODIFICATIONS -#================================================= -# INSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Installing dependencies..." --weight=30 - -ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies - -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Configuring system user..." - -# Create a system user -ynh_system_user_create --username=$app - #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." --weight=5 # 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_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}/vendor/ +ynh_setup_source --source_id="go" --dest_dir="$install_dir/go" +ynh_setup_source --source_id="lxd" --dest_dir="$install_dir/lxd" #================================================= # SPECIFIC SETUP @@ -73,64 +25,47 @@ export GOPATH=${lxd_tmp}/vendor/ #================================================= ynh_script_progression --message="Building lxd from sources..." --weight=60 -pushd ${lxd_tmp} - export HOME=${HOME:-"/root/"} +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 - 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 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 + 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 ${lxd_tmp}/scripts/bash/lxd-client /etc/bash_completion.d/ + 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="$go_tmp" -ynh_secure_remove --file="$lxd_tmp" +ynh_secure_remove --file="$install_dir/go" +ynh_secure_remove --file="$install_dir/lxd" #================================================= -# ADD A CONFIGURATION +# SYSTEM CONFIGURATION #================================================= -ynh_script_progression --message="Adding a configuration file..." - -echo "bind-interfaces -except-interface=lxdbr0" > /etc/dnsmasq.d/lxd -systemctl restart dnsmasq - -ynh_store_file_checksum --file="/etc/dnsmasq.d/lxd" - -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 - -#================================================= -# SETUP SYSTEMD -#================================================= -ynh_script_progression --message="Configuring a systemd service..." +ynh_script_progression --message="Adding 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" -#================================================= -# GENERIC FINALIZATION -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." +_ynh_add_dnsmasq -yunohost service add $app --log="/var/log/$app/$app.log" +_ynh_add_ld_so + +_ynh_set_subuid_subgid #================================================= # START SYSTEMD SERVICE @@ -138,7 +73,7 @@ yunohost service add $app --log="/var/log/$app/$app.log" 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" +ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" #================================================= # END OF SCRIPT diff --git a/scripts/remove b/scripts/remove index 95203ad..b8398ce 100755 --- a/scripts/remove +++ b/scripts/remove @@ -10,59 +10,42 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." - -app=$YNH_APP_INSTANCE_NAME - -#================================================= -# STANDARD REMOVE -#================================================= -# REMOVE SERVICE INTEGRATION IN YUNOHOST +# REMOVE SYSTEM CONFIGURATIONS #================================================= +ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 # Remove the service from the list of services known by YunoHost (added from `yunohost service add`) -if ynh_exec_warn_less yunohost service status $app >/dev/null -then - ynh_script_progression --message="Removing $app service integration..." - yunohost service remove $app +if ynh_exec_warn_less yunohost service status "$app" >/dev/null; then + yunohost service remove "$app" fi -#================================================= -# STOP AND REMOVE SERVICE -#================================================= -ynh_script_progression --message="Stopping and removing the systemd service..." - # Remove the dedicated systemd config ynh_exec_warn_less ynh_remove_systemd_socket_config ynh_exec_warn_less ynh_remove_systemd_config +# Stop LXC systemd services for dnsmasq. +ynh_systemd_action --service_name="lxc-net" --action="stop" +ynh_systemd_action --service_name="lxc" --action="stop" + +_ynh_remove_ld_so + +_ynh_unset_subuid_subgid + +_ynh_remove_dnsmasq + #================================================= # REMOVE CONTAINERS #================================================= - # Remove the data directory if --purge option is used -if [ "${YNH_APP_PURGE:-0}" -eq 1 ] -then +if [ "${YNH_APP_PURGE:-0}" -eq 1 ]; then ynh_script_progression --message="Removing containers..." ynh_secure_remove --file="/var/lib/lxd" fi -#================================================= -# REMOVE DEPENDENCIES -#================================================= -ynh_script_progression --message="Removing dependencies..." --weight=20 - -# Remove metapackage and its dependencies -ynh_exec_warn_less ynh_remove_app_dependencies - #================================================= # CLOSE A PORT #================================================= - -if yunohost firewall list | grep -q "\- 67$" -then +if yunohost firewall list | grep -q "\- 67$"; then ynh_script_progression --message="Closing port 67..." ynh_exec_warn_less yunohost firewall disallow Both 67 fi @@ -74,11 +57,6 @@ fi #================================================= ynh_script_progression --message="Removing various files..." -# Remove a directory securely -ynh_secure_remove --file="/etc/ld.so.conf.d/$app.conf" - -ldconfig - ynh_secure_remove --file="/usr/local/lib/$app" # Remove the log files @@ -94,22 +72,6 @@ ynh_secure_remove --file="/usr/local/bin/lxd-migrate" ynh_secure_remove --file="/usr/local/bin/lxd-user" ynh_secure_remove --file="/etc/bash_completion.d/lxd-client" -sed -i "/# Added by lxd$/{N;/root:100000:65536/d}" /etc/sub{u,g}id - -ynh_secure_remove --file="/etc/dnsmasq.d/lxd" - -systemctl restart dnsmasq - -#================================================= -# GENERIC FINALIZATION -#================================================= -# REMOVE DEDICATED USER -#================================================= -ynh_script_progression --message="Removing the dedicated system user..." - -# Delete a system user -ynh_system_user_delete --username=$app - #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/restore b/scripts/restore index 635c162..cb917d4 100755 --- a/scripts/restore +++ b/scripts/restore @@ -10,43 +10,6 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -ynh_clean_setup () { - ynh_clean_check_starting -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." - -app=$YNH_APP_INSTANCE_NAME - -#================================================= -# STANDARD RESTORATION STEPS -#================================================= -# RECREATE THE DEDICATED USER -#================================================= -ynh_script_progression --message="Recreating the dedicated system user..." - -# Create the dedicated user (if not existing) -ynh_system_user_create --username=$app - -#================================================= -# SPECIFIC RESTORATION -#================================================= -# REINSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Reinstalling dependencies..." --weight=30 - -# Define and install dependencies -ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies - #================================================= # RESTORE VARIOUS FILES #================================================= @@ -66,39 +29,31 @@ ynh_restore_file --origin_path="/usr/local/bin/lxd-migrate" ynh_restore_file --origin_path="/usr/local/bin/lxd-user" ynh_restore_file --origin_path="/etc/bash_completion.d/lxd-client" -ynh_restore_file --origin_path="/etc/dnsmasq.d/lxd" - -systemctl restart dnsmasq - -ynh_restore_file --origin_path="/etc/ld.so.conf.d/$app.conf" - -ldconfig - -echo "# Added by lxd -root:100000:65536" | tee -a /etc/subuid /etc/subgid - #================================================= -# RESTORE SYSTEMD +# RESTORE SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Restoring the systemd configuration..." +ynh_script_progression --message="Restoring system configurations related to $app..." ynh_restore_file --origin_path="/etc/systemd/system/$app.service" ynh_restore_file --origin_path="/etc/systemd/system/$app.socket" -systemctl enable $app.service --quiet +systemctl enable "$app.service" --quiet -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." +yunohost service add "$app" --log="/var/log/$app/$app.log" -yunohost service add $app --log="/var/log/$app/$app.log" +ynh_restore_file --origin_path="/etc/dnsmasq.d/lxd" +systemctl restart dnsmasq + +ynh_restore_file --origin_path="/etc/ld.so.conf.d/$app.conf" +ldconfig + +_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" +ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" #================================================= # END OF SCRIPT diff --git a/scripts/upgrade b/scripts/upgrade index 0048c21..86ae56c 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -9,36 +9,6 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." - -app=$YNH_APP_INSTANCE_NAME - -#================================================= -# 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 - -# Remove old file -if [ -f "/usr/local/bin/lxd-p2c" ]; then - ynh_secure_remove --file="/usr/local/bin/lxd-p2c" -fi - #================================================= # STANDARD UPGRADE STEPS #================================================= @@ -47,45 +17,33 @@ fi 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" +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 -#================================================= -# 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 - #================================================= # 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_ARCH" +ynh_setup_source --source_id="go" --dest_dir="$install_dir/go" --full_replace=1 -export PATH=$go_tmp/bin:$PATH +export PATH="$install_dir/go/bin:$PATH" -lxd_tmp=$(mktemp -d) -ynh_setup_source --dest_dir="$lxd_tmp" --source_id="lxd" +ynh_setup_source --source_id="lxd" --dest_dir="$install_dir/lxd" --full_replace=1 -export GOPATH=${lxd_tmp}/vendor/ - -#================================================= -# UPGRADE DEPENDENCIES -#================================================= -ynh_script_progression --message="Upgrading dependencies..." - -ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies +export GOPATH="$install_dir/lxd/vendor/" #================================================= # SPECIFIC UPGRADE @@ -94,7 +52,7 @@ ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies #================================================= ynh_script_progression --message="Building lxd from sources..." --weight=60 -pushd ${lxd_tmp} +pushd "$install_dir/lxd" export HOME=${HOME:-"/root/"} ynh_exec_warn_less make deps @@ -103,68 +61,41 @@ pushd ${lxd_tmp} export LD_LIBRARY_PATH="${GOPATH}/raft/.libs/:${GOPATH}/dqlite/.libs/" export CGO_LDFLAGS_ALLOW="(-Wl,-wrap,pthread_create)|(-Wl,-z,now)" - export GOCACHE=$go_tmp - 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 ${lxd_tmp}/scripts/bash/lxd-client /etc/bash_completion.d/ + cp $install_dir/lxd/scripts/bash/lxd-client /etc/bash_completion.d/ popd -ynh_secure_remove --file="$go_tmp" -ynh_secure_remove --file="$lxd_tmp" +ynh_secure_remove --file="$install_dir/go" +ynh_secure_remove --file="$install_dir/lxd" #================================================= -# UPDATE A CONFIG FILE +# REAPPLY SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Updating a configuration 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 - -#================================================= -# SETUP SYSTEMD -#================================================= -ynh_script_progression --message="Upgrading systemd configuration..." +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" -#================================================= -# GENERIC FINALIZATION -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." +_ynh_add_dnsmasq -yunohost service add $app --log="/var/log/$app/$app.log" +_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" +ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" #================================================= # END OF SCRIPT diff --git a/tests.toml b/tests.toml new file mode 100644 index 0000000..ce11d20 --- /dev/null +++ b/tests.toml @@ -0,0 +1,7 @@ +#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/tests.v1.schema.json + +test_format = 1.0 + +[default] + + test_upgrade_from.b66ae64c2dae8595c817f058c4e45cd7cc40ac64.name = "5.16~ynh1"