diff --git a/.gitignore b/.gitignore index 1cd8a2a..c4c4ffc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1 @@ *.zip -update-binary -customize.sh diff --git a/META-INF/com/google/android/update-binary b/META-INF/com/google/android/update-binary new file mode 100644 index 0000000..ca3cf8a --- /dev/null +++ b/META-INF/com/google/android/update-binary @@ -0,0 +1,104 @@ +#!/usr/bin/env sh + +[ $(id -u) -eq 0 ] || { + printf "\n(!) must run as root\n\n" + exit 2 +} + +# set source code directory +src="$(cd "${0%/*}" 2>/dev/null; echo "$PWD")" + +# for magisk +SKIPUNZIP=1 + +patch_cfg() { + if [ -f $cfg ] && [ "$1" != r ]; then + if grep -Eq '^# :|mem_total' $cfg; then + patch_cfg r + else + config_ver=0$(sed -n '/^config_ver=/s/.*=//p' $cfg) + if [ $config_ver -lt 0202110290 ]; then + sed -i -e '1iconfig_ver=202110290\n' -e '/^comp_a/s/=.*/=auto/' -e '/^vm=/s/e=200\"/e=200 page-cluster=0\"/' $cfg + fi + fi + else + install -m 644 $src/zram-swap-manager.conf $cfg + fi +} + +if [ -d /data/adb ]; then + + # android + + # extract flashable zip if source code is unavailable + [ -f $src/TODO ] || { + src=/dev/.vr25-zsm-install + on_exit() { rm -rf ${src:-//} 2>/dev/null; } + on_exit + trap on_exit EXIT + mkdir $src + unzip "${3:-${ZIPFILE}}" -d $src/ >&2 + } + + . $src/busybox.sh + + install_dir=/data/adb/modules/zram-swap-manager + data_dir=/data/adb/vr25/zram-swap-manager-data + cfg=/data/adb/vr25/zram-swap-manager-data/config.txt + + rm -rf $install_dir 2>/dev/null + mkdir -p $install_dir/system/bin $data_dir + + cp $src/zram-swap-manager.sh $install_dir/ + ln -sf $install_dir/zram-swap-manager.sh $install_dir/system/bin/zram-swap-manager + ln -sf $install_dir/zram-swap-manager.sh $install_dir/system/bin/zsm + ln -sf $install_dir/zram-swap-manager.sh /sbin/zram-swap-manager 2>/dev/null \ + && ln -sf $install_dir/zram-swap-manager.sh /sbin/zsm + + [ -f $data_dir/config.txt ] || cp $src/zram-swap-manager.conf $data_dir/config.txt + + cp $src/uninstall.sh $install_dir/ + ln -sf $install_dir/uninstall.sh $install_dir/system/bin/zram-swap-manager-uninstall + ln -sf $install_dir/uninstall.sh /sbin/zram-swap-manager-uninstall 2>/dev/null + + for i in $install_dir/*.sh; do + sed -i 's|^#!/.*|#!/system/bin/sh|' $i + done + + i="$PWD" + cd $src/ + cp busybox.sh module.prop service.sh $install_dir/ + cd "$i" + unset i + + patch_cfg + + chmod +x $install_dir/*.sh + [ ".$1" != .--start ] || $install_dir/service.sh + +else + + # gnu/linux + + cfg=/etc/zram-swap-manager.conf + [ -f $cfg ] && upgrade=true + + sh $src/uninstall.sh --keep-config >/dev/null 2>&1 + mkdir -p /usr/local/bin/ + + install -m 644 $src/zram-swap-manager.service /etc/systemd/system/zram-swap-manager.service + + install -m 755 $src/zram-swap-manager.sh /usr/local/bin/zram-swap-manager + ln -s /usr/local/bin/zram-swap-manager /usr/local/bin/zsm + + ${upgrade:-false} || patch_cfg r + install -m 755 $src/uninstall.sh /usr/local/bin/zram-swap-manager-uninstall + + patch_cfg + + systemctl enable zram-swap-manager + [ ".$1" != .--start ] || zram-swap-manager -r + +fi + +echo "Done!" diff --git a/customize.sh b/customize.sh new file mode 100644 index 0000000..ca3cf8a --- /dev/null +++ b/customize.sh @@ -0,0 +1,104 @@ +#!/usr/bin/env sh + +[ $(id -u) -eq 0 ] || { + printf "\n(!) must run as root\n\n" + exit 2 +} + +# set source code directory +src="$(cd "${0%/*}" 2>/dev/null; echo "$PWD")" + +# for magisk +SKIPUNZIP=1 + +patch_cfg() { + if [ -f $cfg ] && [ "$1" != r ]; then + if grep -Eq '^# :|mem_total' $cfg; then + patch_cfg r + else + config_ver=0$(sed -n '/^config_ver=/s/.*=//p' $cfg) + if [ $config_ver -lt 0202110290 ]; then + sed -i -e '1iconfig_ver=202110290\n' -e '/^comp_a/s/=.*/=auto/' -e '/^vm=/s/e=200\"/e=200 page-cluster=0\"/' $cfg + fi + fi + else + install -m 644 $src/zram-swap-manager.conf $cfg + fi +} + +if [ -d /data/adb ]; then + + # android + + # extract flashable zip if source code is unavailable + [ -f $src/TODO ] || { + src=/dev/.vr25-zsm-install + on_exit() { rm -rf ${src:-//} 2>/dev/null; } + on_exit + trap on_exit EXIT + mkdir $src + unzip "${3:-${ZIPFILE}}" -d $src/ >&2 + } + + . $src/busybox.sh + + install_dir=/data/adb/modules/zram-swap-manager + data_dir=/data/adb/vr25/zram-swap-manager-data + cfg=/data/adb/vr25/zram-swap-manager-data/config.txt + + rm -rf $install_dir 2>/dev/null + mkdir -p $install_dir/system/bin $data_dir + + cp $src/zram-swap-manager.sh $install_dir/ + ln -sf $install_dir/zram-swap-manager.sh $install_dir/system/bin/zram-swap-manager + ln -sf $install_dir/zram-swap-manager.sh $install_dir/system/bin/zsm + ln -sf $install_dir/zram-swap-manager.sh /sbin/zram-swap-manager 2>/dev/null \ + && ln -sf $install_dir/zram-swap-manager.sh /sbin/zsm + + [ -f $data_dir/config.txt ] || cp $src/zram-swap-manager.conf $data_dir/config.txt + + cp $src/uninstall.sh $install_dir/ + ln -sf $install_dir/uninstall.sh $install_dir/system/bin/zram-swap-manager-uninstall + ln -sf $install_dir/uninstall.sh /sbin/zram-swap-manager-uninstall 2>/dev/null + + for i in $install_dir/*.sh; do + sed -i 's|^#!/.*|#!/system/bin/sh|' $i + done + + i="$PWD" + cd $src/ + cp busybox.sh module.prop service.sh $install_dir/ + cd "$i" + unset i + + patch_cfg + + chmod +x $install_dir/*.sh + [ ".$1" != .--start ] || $install_dir/service.sh + +else + + # gnu/linux + + cfg=/etc/zram-swap-manager.conf + [ -f $cfg ] && upgrade=true + + sh $src/uninstall.sh --keep-config >/dev/null 2>&1 + mkdir -p /usr/local/bin/ + + install -m 644 $src/zram-swap-manager.service /etc/systemd/system/zram-swap-manager.service + + install -m 755 $src/zram-swap-manager.sh /usr/local/bin/zram-swap-manager + ln -s /usr/local/bin/zram-swap-manager /usr/local/bin/zsm + + ${upgrade:-false} || patch_cfg r + install -m 755 $src/uninstall.sh /usr/local/bin/zram-swap-manager-uninstall + + patch_cfg + + systemctl enable zram-swap-manager + [ ".$1" != .--start ] || zram-swap-manager -r + +fi + +echo "Done!" diff --git a/zip.sh b/zip.sh index f00b2a6..efaf1b5 100644 --- a/zip.sh +++ b/zip.sh @@ -3,4 +3,4 @@ { cd "${0%/*}" cp -u install.sh customize.sh cp -u install.sh META-INF/com/google/android/update-binary; } 2>/dev/null -zip -r9 zsm-magisk-$(date +%Y%m%d%H%m%S).zip * .git* -x \*.zip -x .git/\* +zip -r9 zsm-magisk-$(date +%Y%m%d%H%M%S).zip * .git* -x \*.zip -x .git/\* diff --git a/zram-swap-manager.sh b/zram-swap-manager.sh index b2915ad..f024ff3 100644 --- a/zram-swap-manager.sh +++ b/zram-swap-manager.sh @@ -1,6 +1,6 @@ #!/usr/bin/env sh -version="v2021.10.29-beta (202110290)" +version="v2021.11.6-beta (202111060)" info="zRAM Swap Manager $version Copyright (C) 2021, VR25 License: GPLv3+ @@ -22,7 +22,7 @@ edit_config() { eval "$* $config" else for i in $EDITOR vim vi nano; do - which ${i%% *} && { + which ${i%% *} >/dev/null && { eval "$i $config" break } @@ -55,23 +55,23 @@ prep_exec() { [ -d /data/adb ] && { mkswap() { for exec in /data/adb/vr25/bin/mkswap /system/*bin/mkswap /sbin/mkswap "busybox mkswap"; do - [ -x ${exec%% *} ] && { + if [ -x ${exec%% *} ] || which ${exec%% *} >/dev/null; then eval $exec "$@" && break || echo "(i) Trying alternative..." - } + fi done } swapoff() { for exec in /data/adb/vr25/bin/swapoff /system/*bin/swapoff /sbin/swapoff "busybox swapoff"; do - [ -x ${exec%% *} ] && { + if [ -x ${exec%% *} ] || which ${exec%% *} >/dev/null; then eval $exec "$@" && break || echo "(i) Trying alternative..." - } + fi done } swapon() { for exec in /data/adb/vr25/bin/swapon /system/*bin/swapon /sbin/swapon "busybox swapon"; do - [ -x ${exec%% *} ] && { + if [ -x ${exec%% *} ] || which ${exec%% *} >/dev/null; then eval $exec "$@" && break || echo "(i) Trying alternative..." - } + fi done } }