From f56c36fe1e2157df3260263d48b68ce421354f94 Mon Sep 17 00:00:00 2001 From: Dmitry Puzyrkov <dmitry.puzyrkov@demlabs.net> Date: Thu, 26 May 2022 14:34:04 +0000 Subject: [PATCH] [*] bin/python permissions in postintall. --- linux/debian/conf/dependencies | 2 +- linux/debian/essentials/postinst | 170 ++++++++++++----------- linux/debian/scripts/compile_and_pack.sh | 16 +-- linux/ubuntu/conf/dependencies | 2 +- 4 files changed, 98 insertions(+), 92 deletions(-) diff --git a/linux/debian/conf/dependencies b/linux/debian/conf/dependencies index 69465a4..7e9e382 100644 --- a/linux/debian/conf/dependencies +++ b/linux/debian/conf/dependencies @@ -1 +1 @@ -PKG_DEPS="libjson-c-dev libsqlite3-dev libmagic-dev libcurl4-gnutls-dev traceroute libpq-dev libzip-dev libz-dev zlib1g-dev" +PKG_DEPS="libsqlite3-dev libmagic-dev libcurl4-gnutls-dev traceroute libpq-dev libzip-dev libz-dev zlib1g-dev" diff --git a/linux/debian/essentials/postinst b/linux/debian/essentials/postinst index f47f389..0630806 100755 --- a/linux/debian/essentials/postinst +++ b/linux/debian/essentials/postinst @@ -2,13 +2,13 @@ . /usr/share/debconf/confmodule DAP_CHAINS_NAME="cellframe" -DAP_APP_NAME="$DAP_CHAINS_NAME-node" -DAP_PREFIX="/opt/$DAP_APP_NAME" +DAP_APP_NAME="${DAP_CHAINS_NAME}-node" +DAP_PREFIX="/opt/${DAP_APP_NAME}" -DAP_CFG_TPL="$DAP_PREFIX/share/configs/$DAP_APP_NAME.cfg.tpl" +DAP_CFG_TPL="${DAP_PREFIX}/share/configs/${DAP_APP_NAME}.cfg.tpl" # Store write config to new if present smth -DAP_CFG="$DAP_PREFIX/etc/$DAP_APP_NAME.cfg" +DAP_CFG="${DAP_PREFIX}/etc/${DAP_APP_NAME}.cfg" #fixed link with python library #BUILD_PYTHON_VERSION=/usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0 @@ -27,58 +27,58 @@ DAP_CFG="$DAP_PREFIX/etc/$DAP_APP_NAME.cfg" #fi # Check profile.d symlink -[ -e "/etc/profile.d/$DAP_APP_NAME.sh" ] || ln -sf $DAP_PREFIX/share/profile.d/$DAP_APP_NAME.sh /etc/profile.d/$DAP_APP_NAME.sh +[ -e "/etc/profile.d/${DAP_APP_NAME}.sh" ] || ln -sf ${DAP_PREFIX}/share/profile.d/${DAP_APP_NAME}.sh /etc/profile.d/${DAP_APP_NAME}.sh # Init node config -if [ -e "$DAP_CFG" ]; then - DAP_CFG="$DAP_PREFIX/etc/$DAP_APP_NAME.cfg.dpkg-new" +if [ -e "${DAP_CFG}" ]; then + DAP_CFG="${DAP_PREFIX}/etc/${DAP_APP_NAME}.cfg.dpkg-new" else - DAP_CFG="$DAP_PREFIX/etc/$DAP_APP_NAME.cfg" + DAP_CFG="${DAP_PREFIX}/etc/${DAP_APP_NAME}.cfg" fi -cat $DAP_CFG_TPL > $DAP_CFG || true +cat ${DAP_CFG_TPL} > ${DAP_CFG} || true -sed -i "s/{PREFIX}/\/opt\/$DAP_APP_NAME/g" $DAP_CFG || true +sed -i "s/{PREFIX}/\/opt\/${DAP_APP_NAME}/g" ${DAP_CFG} || true db_get cellframe-node/debug_mode || true -sed -i "s/{DEBUG_MODE}/$RET/g" $DAP_CFG || true +sed -i "s/{DEBUG_MODE}/${RET}/g" ${DAP_CFG} || true db_get cellframe-node/auto_online || true -sed -i "s/{AUTO_ONLINE}/$RET/g" $DAP_CFG || true +sed -i "s/{AUTO_ONLINE}/${RET}/g" ${DAP_CFG} || true db_get cellframe-node/server_enabled || true -sed -i "s/{SERVER_ENABLED}/$RET/g" $DAP_CFG || true +sed -i "s/{SERVER_ENABLED}/${RET}/g" ${DAP_CFG} || true db_get cellframe-node/server_port || true -sed -i "s/{SERVER_PORT}/$RET/g" $DAP_CFG || true +sed -i "s/{SERVER_PORT}/${RET}/g" ${DAP_CFG} || true db_get cellframe-node/server_addr || true -sed -i "s/{SERVER_ADDR}/$RET/g" $DAP_CFG || true +sed -i "s/{SERVER_ADDR}/${RET}/g" ${DAP_CFG} || true db_get cellframe-node/notify_srv_addr || true -sed -i "s/{NOTIFY_SRV_ADDR}/$RET/g" $DAP_CFG || true +sed -i "s/{NOTIFY_SRV_ADDR}/${RET}/g" ${DAP_CFG} || true db_get cellframe-node/notify_srv_port || true -sed -i "s/{NOTIFY_SRV_PORT}/$RET/g" $DAP_CFG || true +sed -i "s/{NOTIFY_SRV_PORT}/${RET}/g" ${DAP_CFG} || true # Init subzero NET_NAME="subzero" db_get cellframe-node/subzero_enabled || true -if [ "$RET" = "true" ]; then - DAP_CFG_NET="$DAP_PREFIX/etc/network/$NET_NAME.cfg" - DAP_CFG_NET_TPL="$DAP_PREFIX/share/configs/network/$NET_NAME.cfg.tpl" +if [ "${RET}" = "true" ]; then + DAP_CFG_NET="${DAP_PREFIX}/etc/network/${NET_NAME}.cfg" + DAP_CFG_NET_TPL="${DAP_PREFIX}/share/configs/network/${NET_NAME}.cfg.tpl" DAP_NET_CFG="" if [ -e "$DAP_CFG_NET" ]; then - DAP_NET_CFG="$DAP_PREFIX/etc/network/$NET_NAME.cfg.dpkg-new" + DAP_NET_CFG="${DAP_PREFIX}/etc/network/${NET_NAME}.cfg.dpkg-new" else - DAP_NET_CFG="$DAP_PREFIX/etc/network/$NET_NAME.cfg" + DAP_NET_CFG="${DAP_PREFIX}/etc/network/${NET_NAME}.cfg" fi - cat $DAP_CFG_NET_TPL > $DAP_NET_CFG || true + cat ${DAP_CFG_NET_TPL} > ${DAP_NET_CFG} || true db_get cellframe-node/subzero_node_type || true - NODE_TYPE=$RET - sed -i "s/{NODE_TYPE}/$NODE_TYPE/g" $DAP_NET_CFG || true + NODE_TYPE=${RET} + sed -i "s/{NODE_TYPE}/${NODE_TYPE}/g" ${DAP_NET_CFG} || true echo "[*] Enabled subzero" fi @@ -87,19 +87,19 @@ NET_NAME="mileena" db_get cellframe-node/mileena_enabled || true if [ "$RET" = "true" ]; then - DAP_CFG_NET="$DAP_PREFIX/etc/network/$NET_NAME.cfg" - DAP_CFG_NET_TPL="$DAP_PREFIX/share/configs/network/$NET_NAME.cfg.tpl" + DAP_CFG_NET="${DAP_PREFIX}/etc/network/${NET_NAME}.cfg" + DAP_CFG_NET_TPL="${DAP_PREFIX}/share/configs/network/${NET_NAME}.cfg.tpl" DAP_NET_CFG="" - if [ -e "$DAP_CFG_NET" ]; then - DAP_NET_CFG="$DAP_PREFIX/etc/network/$NET_NAME.cfg.dpkg-new" + if [ -e "${DAP_CFG_NET}" ]; then + DAP_NET_CFG="${DAP_PREFIX}/etc/network/${NET_NAME}.cfg.dpkg-new" else - DAP_NET_CFG="$DAP_PREFIX/etc/network/$NET_NAME.cfg" + DAP_NET_CFG="${DAP_PREFIX}/etc/network/${NET_NAME}.cfg" fi - cat $DAP_CFG_NET_TPL > $DAP_NET_CFG || true + cat ${DAP_CFG_NET_TPL} > ${DAP_NET_CFG} || true db_get cellframe-node/mileena_node_type || true - NODE_TYPE=$RET - sed -i "s/{NODE_TYPE}/$NODE_TYPE/g" $DAP_NET_CFG || true + NODE_TYPE=${RET} + sed -i "s/{NODE_TYPE}/${NODE_TYPE}/g" ${DAP_NET_CFG} || true echo "[*] Enabled mileena" fi @@ -107,20 +107,20 @@ fi NET_NAME="kelvpn-minkowski" db_get cellframe-node/kelvpn_minkowski_enabled || true -if [ "$RET" = "true" ]; then - DAP_CFG_NET="$DAP_PREFIX/etc/network/$NET_NAME.cfg" - DAP_CFG_NET_TPL="$DAP_PREFIX/share/configs/network/$NET_NAME.cfg.tpl" +if [ "${RET}" = "true" ]; then + DAP_CFG_NET="${DAP_PREFIX}/etc/network/${NET_NAME}.cfg" + DAP_CFG_NET_TPL="${DAP_PREFIX}/share/configs/network/${NET_NAME}.cfg.tpl" DAP_NET_CFG="" if [ -e "$DAP_CFG_NET" ]; then - DAP_NET_CFG="$DAP_PREFIX/etc/network/$NET_NAME.cfg.dpkg-new" + DAP_NET_CFG="${DAP_PREFIX}/etc/network/${NET_NAME}.cfg.dpkg-new" else - DAP_NET_CFG="$DAP_PREFIX/etc/network/$NET_NAME.cfg" + DAP_NET_CFG="${DAP_PREFIX}/etc/network/${NET_NAME}.cfg" fi - cat $DAP_CFG_NET_TPL > $DAP_NET_CFG || true + cat ${DAP_CFG_NET_TPL} > ${DAP_NET_CFG} || true db_get cellframe-node/kelvpn_minkowski_node_type || true - NODE_TYPE=$RET - sed -i "s/{NODE_TYPE}/$NODE_TYPE/g" $DAP_NET_CFG || true + NODE_TYPE=${RET} + sed -i "s/{NODE_TYPE}/${NODE_TYPE}/g" ${DAP_NET_CFG} || true echo "[*] Enabled subzero" fi @@ -128,76 +128,82 @@ fi NET_NAME="Backbone" db_get cellframe-node/backbone_enabled || true -if [ "$RET" = "true" ]; then - DAP_CFG_NET="$DAP_PREFIX/etc/network/$NET_NAME.cfg" - DAP_CFG_NET_TPL="$DAP_PREFIX/share/configs/network/$NET_NAME.cfg.tpl" +if [ "${RET}" = "true" ]; then + DAP_CFG_NET="${DAP_PREFIX}/etc/network/${NET_NAME}.cfg" + DAP_CFG_NET_TPL="${DAP_PREFIX}/share/configs/network/${NET_NAME}.cfg.tpl" DAP_NET_CFG="" - if [ -e "$DAP_CFG_NET" ]; then - DAP_NET_CFG="$DAP_PREFIX/etc/network/$NET_NAME.cfg.dpkg-new" + if [ -e "${DAP_CFG_NET}" ]; then + DAP_NET_CFG="${DAP_PREFIX}/etc/network/${NET_NAME}.cfg.dpkg-new" else - DAP_NET_CFG="$DAP_PREFIX/etc/network/$NET_NAME.cfg" + DAP_NET_CFG="${DAP_PREFIX}/etc/network/${NET_NAME}.cfg" fi - cat $DAP_CFG_NET_TPL > $DAP_NET_CFG || true + cat ${DAP_CFG_NET_TPL} > ${DAP_NET_CFG} || true db_get cellframe-node/backbone_node_type || true NODE_TYPE=$RET - sed -i "s/{NODE_TYPE}/$NODE_TYPE/g" $DAP_NET_CFG || true + sed -i "s/{NODE_TYPE}/${NODE_TYPE}/g" ${DAP_NET_CFG} || true echo "[*] Enabled Backbone" fi -mkdir -p $DAP_PREFIX/var/log || true -mkdir -p $DAP_PREFIX/var/plugins || true +mkdir -p ${DAP_PREFIX}/var/log || true +mkdir -p ${DAP_PREFIX}/var/plugins || true #Set up Python plugins db_get cellframe-node/enable_python_plugins || true -if [ "$RET" = "true" ]; then - sed -i 's/#\[plugins\]/\[plugins\]/g' $DAP_CFG || true - sed -i 's/#py_load=.*/py_load=true/g' $DAP_CFG || true +if [ "${RET}" = "true" ]; then + sed -i 's/#\[plugins\]/\[plugins\]/g' ${DAP_CFG} || true + sed -i 's/#py_load=.*/py_load=true/g' ${DAP_CFG} || true db_get cellframe-node/python_plugins_path || true - sed -i "s|#py_path=.*|py_path=$RET|g" $DAP_CFG || true + sed -i "s|#py_path=.*|py_path=${RET}|g" ${DAP_CFG} || true echo "[*] Enabled Python plugins" fi cat /etc/passwd| grep cellframe-node || adduser --system --no-create-home --group --home /opt/cellframe-node cellframe-node || true -echo "[*] Check /etc/systemd/system/$DAP_APP_NAME.service file..." -if [ -e /etc/systemd/system/$DAP_APP_NAME.service ]; then - echo "[*] Restarting $DAP_APP_NAME to implement changes" - systemctl --system stop $DAP_APP_NAME >> /dev/null|| true - echo "[*] Stopped $DAP_APP_NAME" +echo "[*] Check /etc/systemd/system/${DAP_APP_NAME}.service file..." +if [ -e /etc/systemd/system/${DAP_APP_NAME}.service ]; then + echo "[*] Restarting ${DAP_APP_NAME} to implement changes" + systemctl --system stop ${DAP_APP_NAME} >> /dev/null|| true + echo "[*] Stopped ${DAP_APP_NAME}" systemctl daemon-reload || true - systemctl --system start $DAP_APP_NAME || true - echo "[*] Started $DAP_APP_NAME" + systemctl --system start ${DAP_APP_NAME} || true + echo "[*] Started ${DAP_APP_NAME}" else - echo "[!] Installing $DAP_APP_NAME as systemd service (haven't found /etc/systemd/system/$DAP_APP_NAME.service)" - ln -sf $DAP_PREFIX/share/$DAP_APP_NAME.service /etc/systemd/system/$DAP_APP_NAME.service || true - systemctl --system enable $DAP_PREFIX/share/$DAP_APP_NAME.service || true -# systemctl --system start $DAP_APP_NAME - echo "[ ] Execute 'systemctl start $DAP_APP_NAME' to start $DAP_APP_NAME service" + echo "[!] Installing ${DAP_APP_NAME} as systemd service (haven't found /etc/systemd/system/${DAP_APP_NAME}.service)" + ln -sf $DAP_PREFIX/share/${DAP_APP_NAME}.service /etc/systemd/system/${DAP_APP_NAME}.service || true + systemctl --system enable ${DAP_PREFIX}/share/${DAP_APP_NAME}.service || true + + echo "[ ] Execute 'systemctl start ${DAP_APP_NAME}' to start ${DAP_APP_NAME} service" #USERMAN=`users | awk '{print $1}'` echo "[ ] Enabling logrotate" - ln -sf $DAP_PREFIX/share/logrotate/$DAP_APP_NAME /etc/logrotate.d/$DAP_APP_NAME || true + ln -sf ${DAP_PREFIX}/share/logrotate/${DAP_APP_NAME} /etc/logrotate.d/${DAP_APP_NAME} || true adduser --system --no-create-home --group --home /opt/cellframe-node cellframe-node || true - #usermod -aG $DAP_CHAINS_NAME `users | awk '{print $1}'` + for username in $(cat /etc/passwd | grep "/home" | cut -d ':' -f1); do - usermod -aG cellframe-node $username || true + usermod -aG cellframe-node ${username} || true done - mkdir -p $DAP_PREFIX/var/{run,lib/wallet,lib/global_db,var/plugins} || true - #mkdir -p $DAP_PREFIX/var/{run,lib/ca,lib/wallet,lib/global_db,var/plugins} || true - touch $DAP_PREFIX/var/run/cellframe-node.pid || true - #chown -R $USERMAN:$USERMAN $DAP_PREFIX - for filename in $(find $DAP_PREFIX | grep -v bugreport); do - if [ -d $filename ]; then - chmod 0775 $filename 2>/dev/null || true + + mkdir -p ${DAP_PREFIX}/var/{run,lib/wallet,lib/global_db,var/plugins} || true + touch ${DAP_PREFIX}/var/run/cellframe-node.pid || true + + for filename in $(find ${DAP_PREFIX} | grep -v bugreport); do + if [ -d ${filename} ]; then + chmod 0775 ${filename} 2>/dev/null || true else - chmod 0664 $filename 2>/dev/null || true + chmod 0664 ${filename} 2>/dev/null || true fi done - chmod 0666 $DAP_CFG - chmod 0666 $DAP_CFG_TPL - chmod 0774 $DAP_PREFIX/bin/* || true - chmod 0777 $DAP_PREFIX/bin/$DAP_APP_NAME-cli $DAP_PREFIX/bin/pip3* $DAP_PREFIX/bin/python3* || true + + chmod 0666 ${DAP_CFG} + chmod 0666 ${DAP_CFG_TPL} + chmod 0774 ${DAP_PREFIX}/bin/* || true + + #set python permissions + find ${DAP_PREFIX}/bin/python -type d -exec chmod 755 {} + + chmod 774 ${DAP_PREFIX}/bin/python/bin/* + + service cellframe-node start || true systemctl restart cellframe-node || true echo "[!] Done" diff --git a/linux/debian/scripts/compile_and_pack.sh b/linux/debian/scripts/compile_and_pack.sh index cdfbd93..8cfed78 100755 --- a/linux/debian/scripts/compile_and_pack.sh +++ b/linux/debian/scripts/compile_and_pack.sh @@ -51,15 +51,15 @@ substitute_pkgname_postfix && mkdir -p build && cd build echo $error if [[ $ARCH_VERSION == "arm" ]]; then export LD_LIBRARY_PATH=$LD_LIBRARY_PATH_ARM64 - ${CMAKE_PATH}cmake -DCMAKE_C_COMPILER=$ARM64_C_COMPILER -DCMAKE_CXX_COMPLIER=$ARM64_CXX_COMPILER -DCMAKE_TARGET_ARCH="arm64" .. && make -j$(nproc) && \ + ${CMAKE_PATH}cmake -DCMAKE_C_COMPILER=$ARM64_C_COMPILER -DCMAKE_CXX_COMPLIER=$ARM64_CXX_COMPILER -DCMAKE_TARGET_ARCH="arm64" .. && make && \ ${CMAKE_PATH}cpack && repack *.deb && mv -v *.deb ../packages/ && rm -r * && \ - ${CMAKE_PATH}cmake -DCMAKE_C_COMPILER=$ARM64_C_COMPILER -DCMAKE_CXX_COMPLIER=$ARM64_CXX_COMPILER -DCMAKE_TARGET_ARCH="arm64" -DCMAKE_BUILD_TYPE=Debug ../ && make -j$(nproc) && ${CMAKE_PATH}cpack && repack *.deb && mv -v *.deb ../packages/ && rm -r * || error=$? + ${CMAKE_PATH}cmake -DCMAKE_C_COMPILER=$ARM64_C_COMPILER -DCMAKE_CXX_COMPLIER=$ARM64_CXX_COMPILER -DCMAKE_TARGET_ARCH="arm64" -DCMAKE_BUILD_TYPE=Debug ../ && make && ${CMAKE_PATH}cpack && repack *.deb && mv -v *.deb ../packages/ && rm -r * || error=$? unset LD_LIBRARY_PATH export LD_LIBRARY_PATH=$LD_LIBRARY_PATH_ARMHF - ${CMAKE_PATH}cmake -DCMAKE_C_COMPILER=$ARMHF_C_COMPILER -DCMAKE_CXX_COMPLIER=$ARMHF_CXX_COMPILER -DCMAKE_TARGET_ARCH="armhf" .. && make -j$(nproc) && \ + ${CMAKE_PATH}cmake -DCMAKE_C_COMPILER=$ARMHF_C_COMPILER -DCMAKE_CXX_COMPLIER=$ARMHF_CXX_COMPILER -DCMAKE_TARGET_ARCH="armhf" .. && make && \ ${CMAKE_PATH}cpack && repack *.deb && mv -v *.deb ../packages/ && rm -r * && \ - ${CMAKE_PATH}cmake -DCMAKE_C_COMPILER=$ARMHF_C_COMPILER -DCMAKE_CXX_COMPLIER=$ARMHF_CXX_COMPILER -DCMAKE_TARGET_ARCH="armhf" -DCMAKE_BUILD_TYPE=Debug ../ && make -j$(nproc) && ${CMAKE_PATH}cpack && repack *.deb && mv -v *.deb ../packages/ && rm -r * || error=$? + ${CMAKE_PATH}cmake -DCMAKE_C_COMPILER=$ARMHF_C_COMPILER -DCMAKE_CXX_COMPLIER=$ARMHF_CXX_COMPILER -DCMAKE_TARGET_ARCH="armhf" -DCMAKE_BUILD_TYPE=Debug ../ && make && ${CMAKE_PATH}cpack && repack *.deb && mv -v *.deb ../packages/ && rm -r * || error=$? unset LD_LIBRARY_PATH fi @@ -67,11 +67,11 @@ if [[ $ARCH_VERSION == "amd64" ]]; then sed -i 's/#set(BUILD_WITH_PYTHON_ENV ON)/set(BUILD_WITH_PYTHON_ENV ON)/' ../CMakeLists.txt || error=$? #sed -i 's/target_link_libraries(${NODE_TARGET} ${NODE_LIBRARIES} pthread )/target_link_libraries(${NODE_TARGET} ${NODE_LIBRARIES} pthread z util expat )/' ../CMakeLists.txt || error=$?cd - ${CMAKE_PATH}cmake ../ && make -j$(nproc) && ${CMAKE_PATH}cpack && repack *.deb && mv -v *.deb ../packages/ && rm -r * \ - && ${CMAKE_PATH}cmake -DCMAKE_BUILD_TYPE=Debug ../ && make -j$(nproc) && ${CMAKE_PATH}cpack && repack *.deb && mv -v *.deb ../packages/ && rm -r * || error=$? + ${CMAKE_PATH}cmake ../ && make && ${CMAKE_PATH}cpack && repack *.deb && mv -v *.deb ../packages/ && rm -r * \ + && ${CMAKE_PATH}cmake -DCMAKE_BUILD_TYPE=Debug ../ && make && ${CMAKE_PATH}cpack && repack *.deb && mv -v *.deb ../packages/ && rm -r * || error=$? sed -ibak 's/#set(BUILD_WITH_GDB_DRIVER_PGSQL ON)/set(BUILD_WITH_GDB_DRIVER_PGSQL ON)/' ../CMakeLists.txt || error=$? - ${CMAKE_PATH}cmake ../ && make -j$(nproc) && ${CMAKE_PATH}cpack && repack *.deb && mv -v *.deb ../packages/ && rm -r * \ - && ${CMAKE_PATH}cmake -DCMAKE_BUILD_TYPE=Debug ../ && make -j$(nproc) && ${CMAKE_PATH}cpack && repack *.deb && mv -v *.deb ../packages/ && rm -r * || error=$? + ${CMAKE_PATH}cmake ../ && make && ${CMAKE_PATH}cpack && repack *.deb && mv -v *.deb ../packages/ && rm -r * \ + && ${CMAKE_PATH}cmake -DCMAKE_BUILD_TYPE=Debug ../ && make && ${CMAKE_PATH}cpack && repack *.deb && mv -v *.deb ../packages/ && rm -r * || error=$? fi cd .. && rm -r build diff --git a/linux/ubuntu/conf/dependencies b/linux/ubuntu/conf/dependencies index 0435759..f279d9b 100644 --- a/linux/ubuntu/conf/dependencies +++ b/linux/ubuntu/conf/dependencies @@ -1 +1 @@ -PKG_DEPS="cmake libjson-c-dev libsqlite3-dev libmagic-dev libcurl4-gnutls-dev traceroute libz-dev" +PKG_DEPS="cmake libsqlite3-dev libmagic-dev libcurl4-gnutls-dev traceroute libz-dev" -- GitLab