Skip to content

Commit

Permalink
General fixes & optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
VR-25 committed Nov 6, 2021
1 parent 1227eda commit bdb5602
Show file tree
Hide file tree
Showing 5 changed files with 217 additions and 11 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
*.zip
update-binary
customize.sh
104 changes: 104 additions & 0 deletions META-INF/com/google/android/update-binary
Original file line number Diff line number Diff line change
@@ -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!"
104 changes: 104 additions & 0 deletions customize.sh
Original file line number Diff line number Diff line change
@@ -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!"
2 changes: 1 addition & 1 deletion zip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/\*
16 changes: 8 additions & 8 deletions zram-swap-manager.sh
Original file line number Diff line number Diff line change
@@ -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+
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
}
Expand Down

0 comments on commit bdb5602

Please sign in to comment.