diff --git a/merge/README.txt b/merge/README.txt
index 7051f62..288098b 100644
--- a/merge/README.txt
+++ b/merge/README.txt
@@ -39,3 +39,8 @@ desktop файл содержит то же самое значение
Из шаблонов samba убран параметр protected (unbound), необходимо проверить новый механизм изменённых пользователем параметров
+merge/sys-apps/portage/syncmodule/calculate содержит код, который ссылается на cl-core
+
+Изучить условие subgid sys-apps/shadow (они одинаковые для subuid и subgid)
+
+Из sys-apps/calculate-utils удалены все шаблоны исправляющие код утилит 3.X
diff --git a/merge/sys-apps/.calculate_directory b/merge/sys-apps/.calculate_directory
new file mode 100644
index 0000000..8e3df7f
--- /dev/null
+++ b/merge/sys-apps/.calculate_directory
@@ -0,0 +1 @@
+{% calculate append = 'skip' %}
diff --git a/merge/sys-apps/baselayout/.calculate_directory b/merge/sys-apps/baselayout/.calculate_directory
new file mode 100644
index 0000000..b755664
--- /dev/null
+++ b/merge/sys-apps/baselayout/.calculate_directory
@@ -0,0 +1 @@
+{% calculate name='etc', package='sys-apps/baselayout' %}
diff --git a/merge/sys-apps/baselayout/filesystems b/merge/sys-apps/baselayout/filesystems
new file mode 100644
index 0000000..db0c6f5
--- /dev/null
+++ b/merge/sys-apps/baselayout/filesystems
@@ -0,0 +1,8 @@
+{% calculate format='regex' %}
+(# 'mount -t auto' command.
+#
+)
+
+\1ntfs-3g
+
+
diff --git a/merge/sys-apps/baselayout/gentoo-release b/merge/sys-apps/baselayout/gentoo-release
new file mode 100644
index 0000000..0689c4b
--- /dev/null
+++ b/merge/sys-apps/baselayout/gentoo-release
@@ -0,0 +1,5 @@
+{% if install.os.linux.subname %}
+{{ install.os.linux.name }} {{ install.os.linux.ver }} {{ install.os.linux.subname }}
+{% else %}
+{{ install.os.linux.name }} {{ install.os.linux.ver }}
+{% endif %}
diff --git a/merge/sys-apps/baselayout/issue b/merge/sys-apps/baselayout/issue
new file mode 100644
index 0000000..27785d0
--- /dev/null
+++ b/merge/sys-apps/baselayout/issue
@@ -0,0 +1,6 @@
+
+{% if install.os.linux.subname %}
+Welcome to \n.\O ({{ install.os.linux.name }} {{ install.os.linux.ver }} {{ install.os.linux.subname }})
+{% else %}
+Welcome to \n.\O ({{ install.os.linux.name }} {{ install.os.linux.ver }})
+{% endif %}
diff --git a/merge/sys-apps/baselayout/os-release b/merge/sys-apps/baselayout/os-release
new file mode 100644
index 0000000..1965387
--- /dev/null
+++ b/merge/sys-apps/baselayout/os-release
@@ -0,0 +1,8 @@
+{% calculate format='openrc' %}
+NAME=Calculate
+ID=calculate
+PRETTY_NAME="Calculate/Linux"
+ANSI_COLOR="1;32"
+HOME_URL="http://www.calculate-linux.org"
+SUPPORT_URL="http://www.calculate-linux.org/main/en/community"
+BUG_REPORT_URL="http://www.calculate-linux.org/projects/calculatelinux/issues"
diff --git a/merge/sys-apps/baselayout/sysctl.conf b/merge/sys-apps/baselayout/sysctl.conf
new file mode 100644
index 0000000..7279c24
--- /dev/null
+++ b/merge/sys-apps/baselayout/sysctl.conf
@@ -0,0 +1,6 @@
+{% calculte format='procmail' %}
+# IssueID 848
+{% if not os.subsystem }}
+vm.dirty_background_ratio = 1
+vm.dirty_ratio = 3
+{% endif %}
diff --git a/merge/sys-apps/calculate-utils/.calculate_directory b/merge/sys-apps/calculate-utils/.calculate_directory
new file mode 100644
index 0000000..d1a96c5
--- /dev/null
+++ b/merge/sys-apps/calculate-utils/.calculate_directory
@@ -0,0 +1 @@
+{% calculate append='skip', package='sys-apps/calculate-utils' %}
diff --git a/merge/sys-apps/calculate-utils/boot/.calculate_directory b/merge/sys-apps/calculate-utils/boot/.calculate_directory
new file mode 100644
index 0000000..3e91c01
--- /dev/null
+++ b/merge/sys-apps/calculate-utils/boot/.calculate_directory
@@ -0,0 +1 @@
+{% calculate path='/etc/runlevels' %}
diff --git a/merge/sys-apps/calculate-utils/boot/zram b/merge/sys-apps/calculate-utils/boot/zram
new file mode 100644
index 0000000..3a0a4b2
--- /dev/null
+++ b/merge/sys-apps/calculate-utils/boot/zram
@@ -0,0 +1,2 @@
+{% calculate append="link", source="/etc/init.d/zram", custom.runlevels.zram != 'on' or grep('var/lib/calculate/-runlevels-calculate-utils','/zram') %}
+{% save.system custom.runlevels.zram = "on" %}
diff --git a/merge/sys-apps/calculate-utils/calculate-desktop/.calculate_directory b/merge/sys-apps/calculate-utils/calculate-desktop/.calculate_directory
new file mode 100644
index 0000000..a689a2e
--- /dev/null
+++ b/merge/sys-apps/calculate-utils/calculate-desktop/.calculate_directory
@@ -0,0 +1 @@
+{% calculate path='/usr/share/calculate', name='xdm', pkg('sys-apps/calculate-utils[desktop]') %}
diff --git a/merge/sys-apps/calculate-utils/calculate-desktop/login.d/00init b/merge/sys-apps/calculate-utils/calculate-desktop/login.d/00init
new file mode 100644
index 0000000..00fc536
--- /dev/null
+++ b/merge/sys-apps/calculate-utils/calculate-desktop/login.d/00init
@@ -0,0 +1,3 @@
+{% calculate format='regex', multiline %}
+local bg_color=.*$
+local bg_color="{{ custom.theme.dm.splash.color }}"
diff --git a/merge/sys-apps/calculate-utils/calculate-desktop/logout.d/00init b/merge/sys-apps/calculate-utils/calculate-desktop/logout.d/00init
new file mode 100644
index 0000000..00fc536
--- /dev/null
+++ b/merge/sys-apps/calculate-utils/calculate-desktop/logout.d/00init
@@ -0,0 +1,3 @@
+{% calculate format='regex', multiline %}
+local bg_color=.*$
+local bg_color="{{ custom.theme.dm.splash.color }}"
diff --git a/merge/sys-apps/calculate-utils/calculate-update/.calculate_directory b/merge/sys-apps/calculate-utils/calculate-update/.calculate_directory
new file mode 100644
index 0000000..b8dc96a
--- /dev/null
+++ b/merge/sys-apps/calculate-utils/calculate-update/.calculate_directory
@@ -0,0 +1 @@
+{% calculate path='/var/lib/calculate' %}
diff --git a/merge/sys-apps/calculate-utils/calculate.conf b/merge/sys-apps/calculate-utils/calculate.conf
new file mode 100644
index 0000000..abe7223
--- /dev/null
+++ b/merge/sys-apps/calculate-utils/calculate.conf
@@ -0,0 +1,5 @@
+{% calculate comment='#', path='/usr/share/portage/config/sets' %}
+
+[autodeps]
+class = portage.sets.shell.CommandOutputSet
+command = cat /var/db/pkg/*/*/autodeps 2>/dev/null | sort | uniq
diff --git a/merge/sys-apps/calculate-utils/conf.d.lxc/.calculate_directory b/merge/sys-apps/calculate-utils/conf.d.lxc/.calculate_directory
new file mode 100644
index 0000000..bf4fa4e
--- /dev/null
+++ b/merge/sys-apps/calculate-utils/conf.d.lxc/.calculate_directory
@@ -0,0 +1 @@
+{% calculate path='/etc', name='conf.d', install.os.container.type == 'desktop' and pkg('sys-apps/calculate-utils[client]') %}
diff --git a/merge/sys-apps/calculate-utils/conf.d.lxc/client b/merge/sys-apps/calculate-utils/conf.d.lxc/client
new file mode 100644
index 0000000..658c14c
--- /dev/null
+++ b/merge/sys-apps/calculate-utils/conf.d.lxc/client
@@ -0,0 +1,3 @@
+{% calculate comment='#' %}
+
+rc_keyword="!-lxc"
diff --git a/merge/sys-apps/calculate-utils/conf.d/.calculate_directory b/merge/sys-apps/calculate-utils/conf.d/.calculate_directory
new file mode 100644
index 0000000..208fa70
--- /dev/null
+++ b/merge/sys-apps/calculate-utils/conf.d/.calculate_directory
@@ -0,0 +1 @@
+{% calculate path='/etc' %}
diff --git a/merge/sys-apps/calculate-utils/conf.d/zram b/merge/sys-apps/calculate-utils/conf.d/zram
new file mode 100644
index 0000000..dd6d796
--- /dev/null
+++ b/merge/sys-apps/calculate-utils/conf.d/zram
@@ -0,0 +1,15 @@
+{% calculate not exists('/etc/conf.d/zram'), unbound %}
+# Compression algorithm for zram disk
+COMPRESSION="zstd"
+
+# Zram disk size in percent of RAM or absolute value with suffix (K,M,G)
+DISKSIZE="200%"
+
+# Start zram swap disk
+# swapless - start only for swapless system
+# always - start anyway
+{% if main.cl.chroot_status %}
+START="always"
+{% else %}
+START="swapless"
+{% endif %}
diff --git a/merge/sys-apps/calculate-utils/init.d/.calculate_directory b/merge/sys-apps/calculate-utils/init.d/.calculate_directory
new file mode 100644
index 0000000..459f9b5
--- /dev/null
+++ b/merge/sys-apps/calculate-utils/init.d/.calculate_directory
@@ -0,0 +1 @@
+# Calculate path=/etc
diff --git a/merge/sys-apps/calculate-utils/init.d/zram b/merge/sys-apps/calculate-utils/init.d/zram
new file mode 100644
index 0000000..ea5629e
--- /dev/null
+++ b/merge/sys-apps/calculate-utils/init.d/zram
@@ -0,0 +1,59 @@
+# Calculate chmod=0755
+#!/sbin/openrc-run
+# Copyright 2020 Mir Calculate. http://www.calculate-linux.org
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+depend()
+{
+ after clock root swap
+ before localmount
+ keyword -docker -jail -lxc -openvz -prefix -systemd-nspawn -vserver
+}
+
+start()
+{
+ [[ -d /sys/block/zram0 ]] || modprobe zram
+ if [[ -d /sys/block/zram0 ]]
+ then
+ if [[ $START == "always" ]] || [[ -z $(swapon --noheading) ]]
+ then
+ ebegin "Activating zram swap devices"
+ local disksize;
+ echo ${COMPRESSION:-zstd} >/sys/block/zram0/comp_algorithm
+ if [[ ${DISKSIZE:-200%} =~ ^([0-9]+)%$ ]]
+ then
+ local perc="${BASH_REMATCH[1]}"
+ local memorysize="$(free -b | awk '{if ($1 == "Mem:") {print $2}}')"
+ disksize="$(( $memorysize * $perc / 100 ))"
+ else
+ disksize="${DISKSIZE}"
+ fi
+ echo $disksize >/sys/block/zram0/disksize
+ mkswap -L zramswap /dev/zram0
+ swapon -p 100 /dev/zram0 &>/dev/null
+ fi
+ fi
+ eend 0 # If swapon has nothing todo it errors, so always return 0
+}
+
+stop()
+{
+ if [[ ${RC_RUNLEVEL} != "shutdown" ]] && [[ -n $(swapon --noheading | grep /dev/zram0) ]]
+ then
+ ebegin "Deactivating zram swap devices"
+ swapoff /dev/zram0 &>/dev/null
+ echo 1 >/sys/block/zram0/reset
+ fi
+ eend 0
+}
diff --git a/merge/sys-apps/calculate-utils/org.calculate.Core.service b/merge/sys-apps/calculate-utils/org.calculate.Core.service
new file mode 100644
index 0000000..82068f0
--- /dev/null
+++ b/merge/sys-apps/calculate-utils/org.calculate.Core.service
@@ -0,0 +1,11 @@
+{% calculate format='kde', path='/usr/share/dbus-1/system-services' %}
+[D-BUS Service]
+Name=org.calculate.Core
+{% for pyver in ('3_6', '3_7', '3_8', '3_9') %}
+{% set ptarget = 'python_targets_python_' + pyver|replace('.','_') %}
+{% set python_interpreter = '/usr/bin/python' + pyver %}
+{% if pkg('dev-python/pygobject[%s]' % ptarget) and pkg('dev-python/dbus-python[%s]' % ptarget) %}
+Exec={{ python_interpreter }} /usr/libexec/calculate/cl-dbus-core.py
+{% endif %}
+{% endfor %}
+User=root
diff --git a/merge/sys-apps/calculate-utils/profile.bashrc.d/.calculate_directory b/merge/sys-apps/calculate-utils/profile.bashrc.d/.calculate_directory
new file mode 100644
index 0000000..b8dc96a
--- /dev/null
+++ b/merge/sys-apps/calculate-utils/profile.bashrc.d/.calculate_directory
@@ -0,0 +1 @@
+{% calculate path='/var/lib/calculate' %}
diff --git a/merge/sys-apps/calculate-utils/profile.bashrc.d/30-update-cache b/merge/sys-apps/calculate-utils/profile.bashrc.d/30-update-cache
new file mode 100644
index 0000000..f967515
--- /dev/null
+++ b/merge/sys-apps/calculate-utils/profile.bashrc.d/30-update-cache
@@ -0,0 +1,37 @@
+{% calculate comment='#', unbound %}
+# vim: set syntax=sh
+#
+# Copyright 2015 Calculate Ltd. http://www.calculate-linux.org
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+
+
+update_cache() {
+ [[ -x /usr/libexec/calculate/cl-pkg-cache ]] &&
+ /usr/libexec/calculate/cl-pkg-cache
+}
+
+calculate_configurable_package() {
+ ! [[ -f /var/lib/calculate/calculate-core/cache/merge-setup.list ]] ||
+ grep ${CATEGORY}/${PN} /var/lib/calculate/calculate-core/cache/merge-setup.list &>/dev/null
+}
+
+if [[ ${EBUILD_PHASE} == "setup" ]]
+then
+ if tail -5 /var/log/emerge.log | grep -P "\(1 of.*${CATEGORY}/${P}" &>/dev/null
+ then
+ update_cache
+ fi
+fi
+
+if [[ ${EBUILD_PHASE} == "postrm" ]]
+then
+ if tail -2 /var/log/emerge.log | grep "*** emerge " &>/dev/null
+ then
+ update_cache
+ fi
+fi
diff --git a/merge/sys-apps/calculate-utils/profile.bashrc.d/35-locking b/merge/sys-apps/calculate-utils/profile.bashrc.d/35-locking
new file mode 100644
index 0000000..c5157ef
--- /dev/null
+++ b/merge/sys-apps/calculate-utils/profile.bashrc.d/35-locking
@@ -0,0 +1,28 @@
+{% calculate comment='#', unbound %}
+# vim: set syntax=sh
+#
+# Copyright 2020 Calculate Ltd. http://www.calculate-linux.org
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+
+calculate_lockfile=/var/calculate/tmp/portage/$CATEGORY/.$PN.calculate_lockfile
+
+calculate_lock_setup() {
+ if calculate_configurable_package
+ then
+ flock -x -w 120 $calculate_lockfile true
+ fi
+}
+
+calculate_unlock_setup() {
+ if calculate_configurable_package
+ then
+ rm $calculate_lockfile
+ fi
+}
+
+[[ $EBUILD_PHASE == "instprep" ]] && calculate_lock_setup
diff --git a/merge/sys-apps/calculate-utils/profile.bashrc.d/40-fix-packages b/merge/sys-apps/calculate-utils/profile.bashrc.d/40-fix-packages
new file mode 100644
index 0000000..623723c
--- /dev/null
+++ b/merge/sys-apps/calculate-utils/profile.bashrc.d/40-fix-packages
@@ -0,0 +1,15 @@
+{% calculate comment='#', unbound %}
+# vim: set syntax=sh
+#
+# Copyright 2014 Calculate Ltd. http://www.calculate-linux.org
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+
+if [[ ${CATEGORY}/${PN} == "sys-auth/nss_ldap" ]] && [[ ${EBUILD_PHASE} == "preinst" ]]
+then
+ mv ${D}/etc/ldap.conf ${D}/etc/ldap.conf.example &>/dev/null
+fi
diff --git a/merge/sys-apps/calculate-utils/profile.bashrc.d/40-pack-modules b/merge/sys-apps/calculate-utils/profile.bashrc.d/40-pack-modules
new file mode 100644
index 0000000..f233bd1
--- /dev/null
+++ b/merge/sys-apps/calculate-utils/profile.bashrc.d/40-pack-modules
@@ -0,0 +1,22 @@
+{% calculate comment='#', unbound %}
+# vim: set syntax=sh
+#
+# Copyright 2020 Calculate Ltd. http://www.calculate-linux.org
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+
+if [[ -d ${D}/lib/modules ]] && [[ ${EBUILD_PHASE} == "preinst" ]]
+then
+ if linux_chkconfig_builtin MODULE_COMPRESS_ZSTD
+ then
+ find ${D}/lib/modules -name "*.ko" -exec zstd --rm {} \;
+ fi
+ if linux_chkconfig_builtin MODULE_COMPRESS_XZ
+ then
+ find ${D}/lib/modules -name "*.ko" -exec xz {} \;
+ fi
+fi
diff --git a/merge/sys-apps/calculate-utils/profile.bashrc.d/40-skip-configure b/merge/sys-apps/calculate-utils/profile.bashrc.d/40-skip-configure
new file mode 100644
index 0000000..cd0fa8f
--- /dev/null
+++ b/merge/sys-apps/calculate-utils/profile.bashrc.d/40-skip-configure
@@ -0,0 +1,25 @@
+# Calculate comment=# protected
+# vim: set syntax=sh
+#
+# Copyright 2014 Calculate Ltd. http://www.calculate-linux.org
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+
+
+check_skip() {
+ declare -A SKIPPKGS=(
+ ["calculate-install"]="1"
+ ["calculate-lib"]="1"
+ ["calculate-console"]="1"
+ ["calculate-console-gui"]="1"
+ ["calculate-core"]="1"
+ ["calculate-desktop"]="1"
+ ["calculate-client"]="1"
+ ["calculate-update"]="1" )
+
+ [[ -z ${SKIPPKGS[$PN]} ]]
+}
diff --git a/merge/sys-apps/calculate-utils/profile.bashrc.d/50-config-package b/merge/sys-apps/calculate-utils/profile.bashrc.d/50-config-package
new file mode 100644
index 0000000..fbd2e0e
--- /dev/null
+++ b/merge/sys-apps/calculate-utils/profile.bashrc.d/50-config-package
@@ -0,0 +1,18 @@
+{% calculate comment='#', unbound %}
+# vim: set syntax=sh
+#
+# Copyright 2019 Calculate Ltd. http://www.calculate-linux.org
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+
+CL_CONFIG=/usr/bin/cl-config
+
+post_pkg_config() {
+ [ -f ${CL_CONFIG} ] && ${CL_CONFIG} --no-progress --pkg-version ${PVR} \
+ --pkg-slot ${SLOT/\/*} --pkg-category ${CATEGORY} \
+ --pkg-name ${PN} --verbose
+}
diff --git a/merge/sys-apps/calculate-utils/profile.bashrc.d/50-patch-package b/merge/sys-apps/calculate-utils/profile.bashrc.d/50-patch-package
new file mode 100644
index 0000000..7a86104
--- /dev/null
+++ b/merge/sys-apps/calculate-utils/profile.bashrc.d/50-patch-package
@@ -0,0 +1,30 @@
+{% calculate comment='#', unbound %}
+# vim: set syntax=sh
+#
+# Copyright 2014-2015 Calculate Ltd. http://www.calculate-linux.org
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+
+CL_CORE_PATCH=/usr/bin/cl-core-patch
+[[ -f $CL_CORE_PATCH ]] || CL_CORE_PATCH=/usr/sbin/cl-core-patch
+
+if [[ ${EBUILD_PHASE} == "compile" ]] && [[ -d ${S} ]] && check_skip; then
+ if ! [[ -f /var/lib/calculate/calculate-core/cache/merge-patch.list ]] ||
+ grep ${CATEGORY}/${PN} /var/lib/calculate/calculate-core/cache/merge-patch.list &>/dev/null
+ then
+ [ -f ${CL_CORE_PATCH} ] && ${CL_CORE_PATCH} --no-progress --pkg-version ${PVR} \
+ --pkg-slot ${SLOT/\/*} --pkg-category ${CATEGORY} \
+ --pkg-path ${S} --pkg-name ${PN} --verbose
+ if [[ $? -eq 2 ]]
+ then
+ if /usr/libexec/calculate/cl-variable --value main.cl_template_wrong_patch | grep break &>/dev/null
+ then
+ die "Failed to apply Calculate utilities patch"
+ fi
+ fi
+ fi
+fi
diff --git a/merge/sys-apps/calculate-utils/profile.bashrc.d/50-post-setup-package b/merge/sys-apps/calculate-utils/profile.bashrc.d/50-post-setup-package
new file mode 100644
index 0000000..4d52ec3
--- /dev/null
+++ b/merge/sys-apps/calculate-utils/profile.bashrc.d/50-post-setup-package
@@ -0,0 +1,108 @@
+{% calculate comment='#', unbound %}
+# vim: set syntax=sh
+#
+# Copyright 2014-2015 Calculate Ltd. http://www.calculate-linux.org
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+CL_UPDATE_PROG=/usr/sbin/cl-core
+RUN_CORE="/usr/bin/python2 ${CL_UPDATE_PROG}"
+CORE_METHOD="--method core_setup"
+
+post_setup_package() {
+ local remove_dir_list=""
+ if [ -f ${CL_UPDATE_PROG} ] && [[ $PN == "calculate-utils" ]] && [[ -f /var/lib/calculate/calculate-core/setup-failed.list ]]
+ then
+ while read category pkgname mypvr myslot;do
+ if [[ -n $category ]]
+ then
+ pkg_lockfile_dir=/var/calculate/tmp/portage/$category
+ pkg_lockfile="$pkg_lockfile_dir"/.${pkgname}.calculate_lockfile
+ if ! [[ -d $pkg_lockfile_dir ]]
+ then
+ mkdir -p $pkg_lockfile_dir
+ remove_dir_list="$remove_dir_list $pkg_lockfile_dir"
+ fi
+ (
+ flock -x -w 1 73 || exit 1;
+ fuser /var/db/pkg/$category/.${pkgname}*.portage_lockfile &>/dev/null || CTARGET=${CTARGET} GCC_CONFIG_VER=${GCC_CONFIG_VER} ${RUN_CORE} ${CORE_METHOD} --no-progress --pkg-name $pkgname --pkg-category $category --pkg-slot $myslot --pkg-version $mypvr --pkg-path "/";
+ rm -f /var/lib/calculate/-runlevels-$pkgname
+ rm $pkg_lockfile
+ ) 73>$pkg_lockfile
+ fi
+ done /dev/null
+ then
+ pkg_lockfile_dir=/var/calculate/tmp/portage/$category
+ pkg_lockfile="$pkg_lockfile_dir"/.${pkgname}.calculate_lockfile
+ if ! [[ -d $pkg_lockfile_dir ]]
+ then
+ mkdir -p $pkg_lockfile_dir
+ remove_dir_list="$remove_dir_list $pkg_lockfile_dir"
+ fi
+ (
+ flock -x -w 1 73 || exit 1;
+ fuser /var/db/pkg/$category/.${pkgname}*.portage_lockfile &>/dev/null || CTARGET=${CTARGET} GCC_CONFIG_VER=${GCC_CONFIG_VER} ${RUN_CORE} ${CORE_METHOD} --no-progress --pkg-name $pkgname --pkg-category $category --pkg-path "/";
+ rm $pkg_lockfile
+ ) 73>$pkg_lockfile
+ fi
+ IFS=/
+ done < <(awk '!x[$0]++' /var/lib/calculate/-postmerge)
+ IFS=$OLDIFS
+ fi
+ rm -f /var/lib/calculate/-postmerge
+ [[ -n $remove_dir_list ]] && rmdir $remove_dir_list
+}
+
+fix_kernel_symlink() {
+ # restore kernel symlink to preferred by cl_install_kernel_build variable
+ local kernel_build=$(/usr/libexec/calculate/cl-variable --value install.cl_install_kernel_build 2>/dev/null)
+ if [[ $? -ne 1 ]] && [[ -n $kernel_build ]] && [[ -L /usr/src/linux ]]
+ then
+ [[ "$kernel_build" =~ ^[0-9]+\.[0-9]+$ ]] && kernel_build="${kernel_build}."
+ last_kernel="$(ls -1d /usr/src/linux-${kernel_build}* | sed 's/.*linux-//' | sort -V | tail -1)"
+ if [[ -n $last_kernel ]]
+ then
+ if [[ "$(readlink /usr/src/linux)" != "linux-${last_kernel}" ]]
+ then
+ rm /usr/src/linux
+ ln -sf linux-${last_kernel} /usr/src/linux
+ fi
+ fi
+ fi
+}
+
+clean_binary_bdepends() {
+ local bdeps=$(/usr/libexec/calculate/cl-variable --value update.cl_update_with_bdeps_set 2>/dev/null)
+ local _instmark=/var/db/pkg/$CATEGORY/$PF/EMERGE_FROM
+ echo -n $EMERGE_FROM >$_instmark
+
+ if [[ $EMERGE_FROM == binary ]] && [[ $bdeps == auto ]]
+ then
+ local _bdep=/var/db/pkg/$CATEGORY/$PF/BDEPEND
+ local _dep=/var/db/pkg/$CATEGORY/$PF/DEPEND
+ [[ -f $_bdep ]] && mv $_bdep $_bdep.binary
+ [[ -f $_dep ]] && mv $_dep $_dep.binary
+ fi
+}
+
+post_pkg_postinst() {
+ [[ "$PN" == "calculate-sources" ]] && fix_kernel_symlink
+ post_setup_package
+ calculate_unlock_setup
+ clean_binary_bdepends
+}
diff --git a/merge/sys-apps/calculate-utils/profile.bashrc.d/50-server-distfiles b/merge/sys-apps/calculate-utils/profile.bashrc.d/50-server-distfiles
new file mode 100644
index 0000000..74411bb
--- /dev/null
+++ b/merge/sys-apps/calculate-utils/profile.bashrc.d/50-server-distfiles
@@ -0,0 +1,74 @@
+{% calculate comment='#', pkg('sys-apps/calculate-server'), unbound %}
+# vim: set syntax=sh
+#
+# Copyright 2014 Calculate Ltd. http://www.calculate-linux.org
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+
+# added for calculate server 2.2
+# FUNC: change_permissions
+# DESC: change permissions for all files and directories into specified
+change_permissions() {
+ local directory=$1
+ [[ -d $1 ]] || return
+
+ local out="$(getfacl $directory 2>/dev/null)"
+ if ! (grep -q default:user:900:rwx <<<$out && grep -q ^user:900:rwx <<<$out)
+ then
+ setfacl -R -m d:u:900:rwx,u:900:rwx $directory
+ fi
+
+ addwrite ${directory}
+ # get owner from parent directory
+ local diruid=$(stat -c"%u" ${directory})
+ local dirgid=$(stat -c"%g" ${directory})
+ local dirowner="${diruid}:${dirgid}"
+ # get permissions from parent directory
+ local dirmode=0$(stat -c%a ${directory})
+
+ # turnoff execute for all (permission for files in parent directory)
+ if type bc &>/dev/null;
+ then
+ local filemode=0$(echo "obase=8;$(( $dirmode & 0666 ))" | bc)
+ elif type printf &>/dev/null;
+ then
+ local filemode=$(printf "0%o" $(( $dirmode & 0666 )) )
+ else
+ local filemode=
+ fi
+ # set for all files and directories dirowner
+ find ${directory} \! -uid ${diruid} -o \! -gid ${dirgid} -exec chown ${dirowner} {} \;
+ # set permissions for all directories in parent directory
+ find ${directory} \! -perm ${dirmode} -type d -exec chmod ${dirmode} {} \;
+ if [[ -n $filemode ]]
+ then
+ # set permissions for all files in parent directory
+ find ${directory} \! -perm ${filemode} -type f -exec chmod ${filemode} {} \;
+ fi
+}
+
+# system has "remote" share
+if grep "\[remote\]" /etc/samba/smb.conf &>/dev/null
+then
+ pre_pkg_preinst() {
+ einfo "Performing permissions change for packages directory"
+ change_permissions ${PKGDIR}
+ }
+
+ post_src_unpack() {
+ einfo "Performing permissions change for distdir directory"
+ change_permissions ${PORTAGE_ACTUAL_DISTDIR}
+ }
+else
+ post_src_unpack() {
+ :
+ }
+
+ pre_pkg_preinst() {
+ :
+ }
+fi
diff --git a/merge/sys-apps/calculate-utils/profile.bashrc.d/50-server-protect b/merge/sys-apps/calculate-utils/profile.bashrc.d/50-server-protect
new file mode 100644
index 0000000..fc4926d
--- /dev/null
+++ b/merge/sys-apps/calculate-utils/profile.bashrc.d/50-server-protect
@@ -0,0 +1,93 @@
+{% calculate comment='#', pkg('sys-apps/calculate-server'), unbound %}
+# vim: set syntax=sh
+#
+# Copyright 2016 Calculate Ltd. http://www.calculate-linux.org
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+
+# added for calculate server 2.2
+# FUNC: protect_server_files
+# DESC: protect server changed files from rewrite
+
+protect_server_files() {
+ local protected_files=(
+ "/etc/bind/named.conf"
+ "/etc/conf.d/sortmilter"
+ "/etc/dhcp/dhcpd.conf"
+ "/etc/dhcp/dhcp.ldap"
+ "/etc/dovecot/conf.d/10-auth.conf"
+ "/etc/dovecot/conf.d/10-logging.conf"
+ "/etc/dovecot/conf.d/10-mail.conf"
+ "/etc/dovecot/conf.d/10-master.conf"
+ "/etc/dovecot/conf.d/auth-ldap.conf.ext"
+ "/etc/dovecot/conf.d/auth-system.conf.ext"
+ "/etc/openldap/slapd.conf"
+ "/etc/dovecot/dovecot.conf"
+ "/etc/dovecot/dovecot-ldap.conf"
+ "/etc/jabber/ejabberd.cfg"
+ "/etc/jabber/ejabberd.yml"
+ "/etc/openldap/schema/dnszone.schema"
+ "/etc/openldap/schema/mail.schema"
+ "/etc/postfix/ldap-aliases.cf"
+ "/etc/postfix/ldap-aliases-gr.cf"
+ "/etc/postfix/ldap-aliases-repl.cf"
+ "/etc/postfix/ldap-recipient.cf"
+ "/etc/postfix/ldap-recipient-gr.cf"
+ "/etc/postfix/ldap-recipient-repl.cf"
+ "/etc/postfix/main.cf"
+ "/etc/procmailrc"
+ "/etc/proftpd/proftpd.conf"
+ "/etc/samba/smb.conf"
+ "/etc/squid/squid.conf"
+ "/etc/squid/squid.ldap"
+ )
+ local packages=(
+ "net-ftp/proftpd"
+ "net-fs/samba"
+ "net-mail/dovecot"
+ "net-misc/dhcp"
+ "net-dns/bind"
+ "mail-filter/procmail"
+ "net-im/ejabberd"
+ "mail-mta/postfix"
+ "net-nds/openldap"
+ "net-proxy/squid"
+ )
+ local install_pkg="${CATEGORY}/${PN}"
+ for pkg in ${packages[@]}
+ do
+ if [[ $pkg == $install_pkg ]]
+ then
+ for fn in ${protected_files[@]}
+ do
+ if [[ -f ${D}/$fn ]]
+ then
+ if [[ "$fn" == "/etc/openldap/slapd.conf" ]] && [[ $pkg == "net-nds/openldap" ]]
+ then
+ if [[ -f $fn ]]
+ then
+ contmd5="$(cat /var/db/pkg/net-nds/openldap-*/CONTENTS | grep " /etc/openldap/slapd.conf " | awk '{print $3}')"
+ curmd5="$(md5sum $fn | awk '{print $1}')"
+ if [[ $contmd5 != $curmd5 ]]
+ then
+ mv -- "${D}/$fn" "${D}/${fn}.origin"
+ fi
+ fi
+ cp -- "${D}/$fn" "${D}/${fn}.origin"
+ else
+ mv -- "${D}/$fn" "${D}/${fn}.origin"
+ fi
+ fi
+ done
+ break
+ fi
+ done
+}
+
+post_pkg_preinst() {
+ protect_server_files
+}
diff --git a/merge/sys-apps/calculate-utils/profile.bashrc.d/50-setup-package b/merge/sys-apps/calculate-utils/profile.bashrc.d/50-setup-package
new file mode 100644
index 0000000..81bbdba
--- /dev/null
+++ b/merge/sys-apps/calculate-utils/profile.bashrc.d/50-setup-package
@@ -0,0 +1,105 @@
+{% calculate comment='#', unbound %}
+# vim: set syntax=sh
+
+# Copyright 2014-2015 Calculate Ltd. http://www.calculate-linux.org
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+CL_UPDATE_PROG="/usr/sbin/cl-core"
+RUN_CORE="/usr/bin/python2 ${CL_UPDATE_PROG}"
+CORE_METHOD="--method core_setup"
+[[ -d /var/lib/calculate ]] || mkdir /var/lib/calculate
+
+# setup package and create postmerge package list
+setup_merge_package() {
+ rm -f /var/lib/calculate/-postmerge
+ if ! [[ -f /var/lib/calculate/calculate-core/cache/merge-setup.list ]] ||
+ grep ${CATEGORY}/${PN} /var/lib/calculate/calculate-core/cache/merge-setup.list &>/dev/null
+ then
+ if [ -f ${CL_UPDATE_PROG} ] && check_skip
+ then
+ if ! CTARGET=${CTARGET} GCC_CONFIG_VER=${GCC_CONFIG_VER} ${RUN_CORE} ${CORE_METHOD} --no-progress --pkg-version ${PVR} --pkg-slot ${SLOT/\/*} --pkg-category ${CATEGORY} --pkg-path "/" --pkg-name ${PN}
+ then
+ echo $CATEGORY $PN $PVR ${SLOT/\/*} >>/var/lib/calculate/calculate-core/setup-failed.list
+ return 1
+ fi
+ fi
+ fi
+ rm -f /var/lib/calculate/-runlevels-$PN
+}
+
+# remove mark: package updating
+clean_update_mark() {
+ rm -f /var/lib/calculate/-merge-$PN-*
+}
+
+# remove contents file which need for cl-core-setup
+clean_contents_mark() {
+ rm -f /var/lib/calculate/-CONTENTS-*
+}
+
+# mark: package updating
+mark_update_package() {
+ touch "/var/lib/calculate/-merge-$PN--${SLOT/\/*}-$PPID"
+}
+
+# save services runlevels
+save_runlevels() {
+ find /etc/runlevels/{default,boot,sysinit,shutdown} >/var/lib/calculate/-runlevels-$PN
+}
+
+# dispatching unmerge or update package
+pkg_postrm_dispatch() {
+ if [[ ! -f /var/lib/calculate/-merge-$PN--${SLOT/\/*}-$PPID ]]
+ then
+ pkg_postrm_unmerge
+ else
+ pkg_postrm_update
+ fi
+}
+
+# restore files of packages which stashed for resolve automagic depends
+unstash_automagic_requires() {
+ local automagic_dir=/var/lib/calculate/calculate-builder/automagic-requires
+ if [[ -d $automagic_dir ]]
+ then
+ # -K - need to resolve lib -> lib64 symlink problem
+ # -X - to keep file capabilities
+ /usr/bin/rsync -aXKx ${automagic_dir}/ / && rm -rf ${automagic_dir}
+ fi
+}
+
+# setup package umerging
+pkg_postrm_unmerge() {
+ if ! [[ -f /var/lib/calculate/calculate-core/cache/merge-setup.list ]] ||
+ grep ${CATEGORY}/${PN} /var/lib/calculate/calculate-core/cache/merge-setup.list &>/dev/null
+ then
+ [ -f ${CL_UPDATE_PROG} ] && check_skip && ${RUN_CORE} ${CORE_METHOD} --no-progress --pkg-version ${PVR} --pkg-slot ${SLOT/\/*} --pkg-category ${CATEGORY} --pkg-path / --pkg-name ${PN}
+ fi
+}
+
+# save contents file for correct package updating by cl-core-setup
+pkg_postrm_update() {
+ cp /var/db/pkg/${CATEGORY}/${PF}/CONTENTS /var/lib/calculate/-CONTENTS-$PN
+}
+
+pre_pkg_postrm() {
+ pkg_postrm_dispatch
+ clean_update_mark
+}
+
+pre_pkg_postinst() {
+ setup_merge_package
+ clean_contents_mark
+ clean_update_mark
+ unstash_automagic_requires
+}
+
+pre_pkg_preinst() {
+ mark_update_package
+ save_runlevels
+}
diff --git a/merge/sys-apps/calculate-utils/profile.bashrc.d/60-fix-certgen b/merge/sys-apps/calculate-utils/profile.bashrc.d/60-fix-certgen
new file mode 100644
index 0000000..f612f9e
--- /dev/null
+++ b/merge/sys-apps/calculate-utils/profile.bashrc.d/60-fix-certgen
@@ -0,0 +1,15 @@
+{% calculate comment='#', unbound %}
+# vim: set syntax=sh
+#
+# Copyright 2014 Calculate Ltd. http://www.calculate-linux.org
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+
+if [[ ${EBUILD_PHASE} == "postinst" ]]
+then
+ echo $RANDOM >>${T}/eclass-debug.log
+fi
diff --git a/merge/sys-apps/calculate-utils/profile.bashrc.d/60-fix-libdb_6 b/merge/sys-apps/calculate-utils/profile.bashrc.d/60-fix-libdb_6
new file mode 100644
index 0000000..5ba63c1
--- /dev/null
+++ b/merge/sys-apps/calculate-utils/profile.bashrc.d/60-fix-libdb_6
@@ -0,0 +1,37 @@
+{% calculate comment='#', unbound %}
+# vim: set syntax=sh
+#
+# Copyright 2014 Calculate Ltd. http://www.calculate-linux.org
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+
+if [[ ${CATEGORY}/${PN} == "sys-libs/db" ]]
+then
+fix_libdb_6() {
+ if [[ -f /usr/include/db4.8/db.h ]] &&
+ [[ -f /usr/include/db4.8/db_185.h ]] &&
+ [[ -f /usr/lib/libdb-4.8.so ]]
+ then
+ ln -sf db4.8/db.h /usr/include/db.h
+ ln -sf db4.8/db_185.h /usr/include/db_185.h
+ ln -sf libdb-4.8.so /usr/lib/libdb.so
+ fi
+}
+post_pkg_postrm() {
+ if [[ $PV == '0_rc73' ]]
+ then
+ fix_libdb_6
+ fi
+}
+
+post_pkg_postinst() {
+ if [[ $SLOT == "4.8" ]] && [[ -d /var/db/pkg/sys-libs/db-0_rc73 ]]
+ then
+ fix_libdb_6
+ fi
+}
+fi
diff --git a/merge/sys-apps/calculate-utils/updateSymlinks b/merge/sys-apps/calculate-utils/updateSymlinks
new file mode 100644
index 0000000..607e580
--- /dev/null
+++ b/merge/sys-apps/calculate-utils/updateSymlinks
@@ -0,0 +1,5 @@
+{% calculate exec='/bin/bash', action='!disk' %}
+
+/usr/sbin/cl-core --create-symlink &>/dev/null
+
+true
diff --git a/merge/sys-apps/dbus/.calculate_directory b/merge/sys-apps/dbus/.calculate_directory
new file mode 100644
index 0000000..1dd63b9
--- /dev/null
+++ b/merge/sys-apps/dbus/.calculate_directory
@@ -0,0 +1 @@
+{% calculate name='etc', package='sys-apps/dbus' %}
diff --git a/merge/sys-apps/dbus/boot/.calculate_directory b/merge/sys-apps/dbus/boot/.calculate_directory
new file mode 100644
index 0000000..3e91c01
--- /dev/null
+++ b/merge/sys-apps/dbus/boot/.calculate_directory
@@ -0,0 +1 @@
+{% calculate path='/etc/runlevels' %}
diff --git a/merge/sys-apps/dbus/boot/dbus b/merge/sys-apps/dbus/boot/dbus
new file mode 100644
index 0000000..51db7c9
--- /dev/null
+++ b/merge/sys-apps/dbus/boot/dbus
@@ -0,0 +1,2 @@
+{% calculate append="link", source="/etc/init.d/dbus", custom.runlevels.dbus != 'on' or grep('var/lib/calculate/-runlevels-dbus','/dbus') %}
+{% save.system custom.runlevels.dbus = "on" %}
diff --git a/merge/sys-apps/hdparm/.calculate_directory b/merge/sys-apps/hdparm/.calculate_directory
new file mode 100644
index 0000000..05c88cc
--- /dev/null
+++ b/merge/sys-apps/hdparm/.calculate_directory
@@ -0,0 +1 @@
+{% calculate path='/etc', name='conf.d', package='sys-apps/hdparm' %}
diff --git a/merge/sys-apps/hdparm/hdparm b/merge/sys-apps/hdparm/hdparm
new file mode 100644
index 0000000..730f0c8
--- /dev/null
+++ b/merge/sys-apps/hdparm/hdparm
@@ -0,0 +1,5 @@
+{% calculate format='openrc' %}
+
+pata_all_args="-d1 -X69 -c1"
+sata_all_args=""
+all_args=""
diff --git a/merge/sys-apps/memtest86+/.calculate_directory b/merge/sys-apps/memtest86+/.calculate_directory
new file mode 100644
index 0000000..a0ad96c
--- /dev/null
+++ b/merge/sys-apps/memtest86+/.calculate_directory
@@ -0,0 +1 @@
+{% calculate path='/etc', name='grub.d', package='sys-apps/memtest86+' %}
diff --git a/merge/sys-apps/memtest86+/39_memtest86+ b/merge/sys-apps/memtest86+/39_memtest86+
new file mode 100644
index 0000000..f1b4368
--- /dev/null
+++ b/merge/sys-apps/memtest86+/39_memtest86+
@@ -0,0 +1,6 @@
+{% calculate comment='#', format='regex', multiline, autoupdate %}
+
+(Memtest86\+') (\{)
+\1 --unrestricted \2
diff --git a/merge/sys-apps/memtest86+/memtest.netbsd.remove b/merge/sys-apps/memtest86+/memtest.netbsd.remove
new file mode 100644
index 0000000..959e22e
--- /dev/null
+++ b/merge/sys-apps/memtest86+/memtest.netbsd.remove
@@ -0,0 +1 @@
+{% calculate append='remove', path='/boot/memtest86plus', name='memtest.netbsd' %}
diff --git a/merge/sys-apps/openrc/.calculate_directory b/merge/sys-apps/openrc/.calculate_directory
new file mode 100644
index 0000000..66fc030
--- /dev/null
+++ b/merge/sys-apps/openrc/.calculate_directory
@@ -0,0 +1 @@
+{% calculate name='etc', package='sys-apps/openrc' %}
diff --git a/merge/sys-apps/openrc/boot.runlevels/.calculate_directory b/merge/sys-apps/openrc/boot.runlevels/.calculate_directory
new file mode 100644
index 0000000..3a7df54
--- /dev/null
+++ b/merge/sys-apps/openrc/boot.runlevels/.calculate_directory
@@ -0,0 +1 @@
+{% calculate path='/etc/runlevels', name='boot' %}
diff --git a/merge/sys-apps/openrc/boot.runlevels/consolefont b/merge/sys-apps/openrc/boot.runlevels/consolefont
new file mode 100644
index 0000000..fa11bba
--- /dev/null
+++ b/merge/sys-apps/openrc/boot.runlevels/consolefont
@@ -0,0 +1,2 @@
+{% calculate append="link", source="/etc/init.d/consolefont", custom.runlevels.openrc_consolefont != 'on' or grep('var/lib/calculate/-runlevels-openrc','/consolefont') %}
+{% save.system custom.runlevels.openrc_consolefont = "on" %}
diff --git a/merge/sys-apps/openrc/cache/.calculate_directory b/merge/sys-apps/openrc/cache/.calculate_directory
new file mode 100644
index 0000000..e9b989a
--- /dev/null
+++ b/merge/sys-apps/openrc/cache/.calculate_directory
@@ -0,0 +1 @@
+{% calculate path='/lib/rc' %}
diff --git a/merge/sys-apps/openrc/conf.d/.calculate_directory b/merge/sys-apps/openrc/conf.d/.calculate_directory
new file mode 100644
index 0000000..d2fdcdb
--- /dev/null
+++ b/merge/sys-apps/openrc/conf.d/.calculate_directory
@@ -0,0 +1 @@
+{% calculate path='/etc', name='conf.d' %}
diff --git a/merge/sys-apps/openrc/conf.d/consolefont b/merge/sys-apps/openrc/conf.d/consolefont
new file mode 100644
index 0000000..e9c36a6
--- /dev/null
+++ b/merge/sys-apps/openrc/conf.d/consolefont
@@ -0,0 +1,3 @@
+{% calculate format='openrc' %}
+
+consolefont="ter-v18n"
diff --git a/merge/sys-apps/openrc/conf.d/hostname b/merge/sys-apps/openrc/conf.d/hostname
new file mode 100644
index 0000000..553545c
--- /dev/null
+++ b/merge/sys-apps/openrc/conf.d/hostname
@@ -0,0 +1,3 @@
+{% calculate format='openrc', unbound %}
+
+rc_before="net.lo"
diff --git a/merge/sys-apps/openrc/conf.d/killprocs b/merge/sys-apps/openrc/conf.d/killprocs
new file mode 100644
index 0000000..07bef0d
--- /dev/null
+++ b/merge/sys-apps/openrc/conf.d/killprocs
@@ -0,0 +1,4 @@
+{% calculate comment='#' %}
+# If you wish to pass any options to killall5 during shutdown,
+# you should do so here.
+killall5_opts=""
diff --git a/merge/sys-apps/openrc/conf.d/netmount b/merge/sys-apps/openrc/conf.d/netmount
new file mode 100644
index 0000000..2896c58
--- /dev/null
+++ b/merge/sys-apps/openrc/conf.d/netmount
@@ -0,0 +1,4 @@
+{% calculate comment='#', format='openrc', install.os.container.type == 'desktop' %}
+
+rc_need="net"
+rc_keyword="!-lxc"
diff --git a/merge/sys-apps/openrc/conf.d/swap b/merge/sys-apps/openrc/conf.d/swap
new file mode 100644
index 0000000..9637963
--- /dev/null
+++ b/merge/sys-apps/openrc/conf.d/swap
@@ -0,0 +1,3 @@
+{% calculate format='openrc' %}
+
+rc_after="root"
diff --git a/merge/sys-apps/openrc/init.sh b/merge/sys-apps/openrc/init.sh
new file mode 100644
index 0000000..cb42f20
--- /dev/null
+++ b/merge/sys-apps/openrc/init.sh
@@ -0,0 +1,9 @@
+{% calculate format='regex', path='/lib/rc/sh', name='init.sh' %}
+(cp -p "\$RC_LIBEXECDIR"/cache/\* "\$RC_SVCDIR" 2>/dev/null
+fi
+)(
+echo sysinit >"\$RC_SVCDIR"/softlevel
+exit)
+\1
+rc-update -u
+\2
diff --git a/merge/sys-apps/openrc/modules-load.d/.calculate_directory b/merge/sys-apps/openrc/modules-load.d/.calculate_directory
new file mode 100644
index 0000000..208fa70
--- /dev/null
+++ b/merge/sys-apps/openrc/modules-load.d/.calculate_directory
@@ -0,0 +1 @@
+{% calculate path='/etc' %}
diff --git a/merge/sys-apps/openrc/mtab b/merge/sys-apps/openrc/mtab
new file mode 100644
index 0000000..591bd36
--- /dev/null
+++ b/merge/sys-apps/openrc/mtab
@@ -0,0 +1 @@
+{% calculate append='link', source='/proc/self/mounts', unbound %}
diff --git a/merge/sys-apps/openrc/rc.conf b/merge/sys-apps/openrc/rc.conf
new file mode 100644
index 0000000..f86281f
--- /dev/null
+++ b/merge/sys-apps/openrc/rc.conf
@@ -0,0 +1,10 @@
+{% calculate format='openrc' %}
+#able to press the I key during boot so you can choose to start specific services
+rc_interactive="NO"
+#use all net.* for network atapters (need for CDS)
+rc_parallel="YES"
+{% if pkg('net-vpn/wireguard-tools') %}
+rc_hotplug="!net.wg?"
+{% else %}
+rc_hotplug="*"
+{% endif %}
diff --git a/merge/sys-apps/openrc/runlevels.mtab b/merge/sys-apps/openrc/runlevels.mtab
new file mode 100644
index 0000000..54991ca
--- /dev/null
+++ b/merge/sys-apps/openrc/runlevels.mtab
@@ -0,0 +1 @@
+{% calculate append='remove', path='/etc/runlevels/boot', name='mtab' %}
diff --git a/merge/sys-apps/portage/.calculate_directory b/merge/sys-apps/portage/.calculate_directory
new file mode 100644
index 0000000..95f1501
--- /dev/null
+++ b/merge/sys-apps/portage/.calculate_directory
@@ -0,0 +1 @@
+# Calculate mergepkg()!= append=skip
diff --git a/merge/sys-apps/portage/config/.calculate_directory b/merge/sys-apps/portage/config/.calculate_directory
new file mode 100644
index 0000000..f481624
--- /dev/null
+++ b/merge/sys-apps/portage/config/.calculate_directory
@@ -0,0 +1 @@
+{% calculate path='/usr/share/portage' %}
diff --git a/merge/sys-apps/portage/config/01repos.conf b/merge/sys-apps/portage/config/01repos.conf
new file mode 100644
index 0000000..07e8470
--- /dev/null
+++ b/merge/sys-apps/portage/config/01repos.conf
@@ -0,0 +1,10 @@
+{% calculate format='samba', name='repos.conf' %}
+
+{% set repositories = update.cl.repositories %}
+[gentoo]
+sync-type = git
+{% if repositories and repositories[0].name == 'gentoo' and repositories[0].url %}
+sync-uri = {{ repositories[0].url }}
+{% else %}
+sync-uri = git://git.calculate-linux.org/calculate/gentoo-overlay.git
+{% endif %}
diff --git a/merge/sys-apps/portage/config/02gentoo.conf b/merge/sys-apps/portage/config/02gentoo.conf
new file mode 100644
index 0000000..8e4c6b7
--- /dev/null
+++ b/merge/sys-apps/portage/config/02gentoo.conf
@@ -0,0 +1 @@
+{% calculate format='samba', path='/etc/portage/repos.conf', name='gentoo.conf', source='/usr/share/portage/config/repos.conf', mirror, force %}
diff --git a/merge/sys-apps/portage/gentoo.conf b/merge/sys-apps/portage/gentoo.conf
new file mode 100644
index 0000000..d4265a4
--- /dev/null
+++ b/merge/sys-apps/portage/gentoo.conf
@@ -0,0 +1 @@
+{% calculate append='remove', path='/etc/porage/repos.conf' %}
diff --git a/merge/sys-apps/portage/make.conf.base b/merge/sys-apps/portage/make.conf.base
new file mode 100644
index 0000000..b65f80a
--- /dev/null
+++ b/merge/sys-apps/portage/make.conf.base
@@ -0,0 +1 @@
+{% calculate append='remove', path='/etc/portage/make.conf', name='0-base' %}
diff --git a/merge/sys-apps/portage/syncmodule/.calculate_directory b/merge/sys-apps/portage/syncmodule/.calculate_directory
new file mode 100644
index 0000000..fe9987a
--- /dev/null
+++ b/merge/sys-apps/portage/syncmodule/.calculate_directory
@@ -0,0 +1 @@
+{% calculate append='skip' %}
diff --git a/merge/sys-apps/portage/syncmodule/calculate/.calculate_directory b/merge/sys-apps/portage/syncmodule/calculate/.calculate_directory
new file mode 100644
index 0000000..fe9987a
--- /dev/null
+++ b/merge/sys-apps/portage/syncmodule/calculate/.calculate_directory
@@ -0,0 +1 @@
+{% calculate append='skip' %}
diff --git a/merge/sys-apps/portage/syncmodule/calculate/__init__.py b/merge/sys-apps/portage/syncmodule/calculate/__init__.py
new file mode 100644
index 0000000..7128686
--- /dev/null
+++ b/merge/sys-apps/portage/syncmodule/calculate/__init__.py
@@ -0,0 +1,38 @@
+{% calculate run='/bin/bash' %}
+
+for dn in /usr/lib*/python*/site-packages/portage/sync/modules
+do
+ [[ -d $dn ]] || continue
+ [[ -d $dn/calculate ]] || mkdir -p $dn/calculate
+ cat >$dn/calculate/__init__.py <$dn/calculate/calculate.py <
+ENV_SUPATH\tPATH=/sbin:/bin:/usr/sbin:/usr/bin
+
+
+ENV_SUPATH\tPATH=/usr/sbin:/usr/bin:/sbin:/bin
+
+
+ENV_PATH\tPATH=/bin:/usr/bin
+
+
+ENV_PATH\tPATH=/usr/bin:/bin
+
diff --git a/merge/sys-apps/shadow/subgid b/merge/sys-apps/shadow/subgid
new file mode 100644
index 0000000..abd79ed
--- /dev/null
+++ b/merge/sys-apps/shadow/subgid
@@ -0,0 +1,2 @@
+{% calculate path='/etc', (not exists('/etc/subuid')), unbound %}
+root:1000000:65536
diff --git a/merge/sys-apps/shadow/subuid b/merge/sys-apps/shadow/subuid
new file mode 100644
index 0000000..abd79ed
--- /dev/null
+++ b/merge/sys-apps/shadow/subuid
@@ -0,0 +1,2 @@
+{% calculate path='/etc', (not exists('/etc/subuid')), unbound %}
+root:1000000:65536
diff --git a/merge/sys-apps/sysvinit/.calculate_directory b/merge/sys-apps/sysvinit/.calculate_directory
new file mode 100644
index 0000000..cfdf973
--- /dev/null
+++ b/merge/sys-apps/sysvinit/.calculate_directory
@@ -0,0 +1 @@
+{% calculate name='etc', package='sys-apps/sysvinit' %}
diff --git a/merge/sys-apps/sysvinit/inittab b/merge/sys-apps/sysvinit/inittab
new file mode 100644
index 0000000..972c545
--- /dev/null
+++ b/merge/sys-apps/sysvinit/inittab
@@ -0,0 +1,12 @@
+{% calculate format='regex', comment='#' %}
+(si::sysinit:/sbin/(?:open)?rc sysinit
+)
+(# Further system initialization, brings up the boot runlevel.)
+([\s\S]+?)
+([^\n]+tty2 linux[\s\S]+tty6 linux)
+\1
+# TERMINALS
+\4
+
+\2
+\3