[script] clean up SWAP partition bash script - Motorola Droid and Milestone General

Hello there,
this is a simple script how to clean up the swap partition without restart or typing commands in the terminal.
Tested on:
- CM9 (Milestone A853)
Requirements:
- rooted device
- swap partition (/dev/block/mmcblk0p3)
- GScript Application (thanks to rogro82) http://forum.xda-developers.com/showthread.php?t=486486
Make sure GScript has root access and the script in the application has su rights.
Here comes the script:
Code:
if [ -e "/sdcard/swapre/" ];then
echo "folder exists, we are good to go"
else
mkdir /sdcard/swapre/
touch /sdcard/swapre/log.txt
fi
swapoff /dev/block/mmcblk0p3
echo "swap is off, please wait"
echo "swap is off" > /sdcard/swapre/log.txt
swapon /dev/block/mmcblk0p3
echo "swap is on, hold a second to finish"
echo "swap is on" >> /sdcard/swapre/log.txt
echo "swap was restarted at:" >> /sdcard/swapre/log.txt
date -u >> /sdcard/swapre/log.txt
7z version -> https://dl.dropbox.com/u/2969199/swp.7z
the script will crate a folder on the sd card, with a log file within. Just in case you want to see what happened
I recommend to create a shortcut on the desktop, after you installed GScript and the script, for easier access.
You should be fine with your device and it should work
well, have fun.

Related

[Solved]Help to mount SDcard

Hi I built a little script to mount my SDcard @ startup of the phone and install some apps.
here it is:
Code:
sleep 2
busybox mount > /data/mount.txt
busybox ls /dev/block/vold >> /data/mount.txt
busybox mount -t vfat -o rw,dirsync,nosuid,nodev,noexec,uid=1000,gid=1015,fmask=0702,dmask=0702,allow_utime=0020,shortname=mixed,utf8 /dev/block/vold/179:1 /sdcard >> /data/mount.txt
busybox mount >> /data/mount.txt
sleep 3
echo "APPS installation"
if [ -e /sdcard/Apps-install/install.txt ];
then
echo "found file" > /sdcard/Apps-install/install.txt
cd /sdcard/Apps-install
ls *.apk > ./apps.txt
for line in $(cat apps.txt); do install -c -D /sdcard/Apps-install/"$line" /data/app >> /sdcard/Apps-install/install.txt; done
echo "ok" >> /sdcard/Apps-install/install.txt
else
echo "file not found" > /sdcard/Apps-install/install.txt
fi;
sleep 2
echo "Finish"
if [ -e /data/firstboot.sh ];
then
busybox rm -f /data/firstboot.sh;
busybox rm -f /sdcard/Apps-install/apps.txt;
fi;
echo "Restart"
sleep 1
reboot
I'm sure that the code is well executed (as is have data in /data/mount.txt) but the mount of the SD and so every work related to the SD
What is strange is that script work if i execute it after the phone has completely started.
Can someone help please.
Bye
Herc.8)
A Little up for a little help
Hi,
I still need help,
thx by advance
Bye
Herc. 8)
Ok finally found bye myself.
I changed the device: /dev/block/vold/179:1 for /dev/block/mmcblk0p1
That's all.
Bye
Herc. 8)

What replaces stagefright?

I found a script that adds boot audio. In it there is a line calling stagefright, stagefright either doesn't exist on my ROM and I have no clue as to add it. Here is the script in question which I don't know the original author however lithid from http://forum.cyanogenmod.org did some work on it and was close to creating a updater-script. Please Help Me as I know some scripting but not a lot
PS I was advised to ask this question to the devs by a cyanogenmod.org mod named bassmadrigal
Code:
#!/system/bin/sh
#I just made this into a script this was from a post on XDA by spiicytuna
#http://forum.xda-developers.com/showpost.php?p=8274824&postcount=2
#Please give the credit to him not me.
echo "preparing system..."
#Setting up the system for read/write access
mount -o remount,rw /system
#linking busybox mkdir (broken in rc2)
rm /system/bin/mkdir
ln -s /system/xbin/mkdir /system/bin/mkdir
mkdir -p /data/local/boot
echo "checking for previous bootsound installation..."
if [ -e /system/bin/bootsound ];
then
echo "bootsound already enabled, exiting.."
mount -o remount,ro /system
exit
fi
if [ "`ls /sbin|grep -q recovery;echo $?`" = "0" ];
then
mount -a > /dev/null
recoverymode=y
else
mount -o rw,remount /system
recoverymode=n
fi
echo "preparing startup scripts..."
#This is to create the needed scripts in init.local.rc
echo '' >> /system/etc/init.local.rc
echo '' >> /system/etc/init.local.rc
echo '###Bootsound - Safe to Delete: Start ###' >> /system/etc/init.local.rc
echo "" >> /system/etc/init.local.rc
echo 'service bootsound /system/bin/bootsound' >> /system/etc/init.local.rc
echo ' user media' >> /system/etc/init.local.rc
echo ' group audio' >> /system/etc/init.local.rc
echo ' disabled' >> /system/etc/init.local.rc
echo ' oneshot' >> /system/etc/init.local.rc
echo '' >> /system/etc/init.local.rc
echo 'on property:init.svc.bootanim=running # to correct timin' >> /system/etc/init.local.rc
echo ' start bootsound' >> /system/etc/init.local.rc
echo '' >> /system/etc/init.local.rc
echo 'on property:dev.bootcomplete=1' >> /system/etc/init.local.rc
echo ' stop bootsound' >> /system/etc/init.local.rc
echo '### Bootsound - Safe to Delete: End ###' >> /system/etc/init.local.rc
echo "creating script for bootsound in /system/bin..."
echo '#Now creating the bootsound script'
touch /system/bin/bootsound
echo '#!/system/bin/sh' >> /system/bin/bootsound
echo '' >> /system/bin/bootsound
echo 'bprop=/system/build.prop' >> /system/bin/bootsound
echo '' >> /system/bin/bootsound
echo 'play=$(cat $bprop | egrep -c -i -o ro.config.play.bootsound=1)' >> /system/bin/bootsound
echo 'if [ "$play" = "1" ]; then' >> /system/bin/bootsound
echo ' stagefright -a -o /system/media/android_audio.mp3' >> /system/bin/bootsound #this is the line that breaks the code
echo 'fi' >> /system/bin/bootsound
echo 'exit 0' >> /system/bin/bootsound
#Changing some permissions
chmod 777 /system/bin/bootsound
chown root:shell /system/bin/bootsound
echo '' >> /system/build.pro
echo 'ro.config.play.bootsound=1' >> /system/build.prop
echo 'media.stagefright.enable-player=true' >> /system/build.prop
echo 'media.stagefright.enable-meta=true' >> /system/build.prop
echo 'media.stagefright.enable-scan=true' >> /system/build.prop
echo 'media.stagefright.enable-http=true' >> /system/build.prop
#removed self-destruct, script checks for previous install
sleep 1
mount -o ro,remount /system
echo "done."
exit
ethan_hines said:
I found a script that adds boot audio. In it there is a line calling stagefright, stagefright either doesn't exist on my ROM and I have no clue as to add it. Here is the script in question which I don't know the original author however lithid from http://forum.cyanogenmod.org did some work on it and was close to creating a updater-script. Please Help Me as I know some scripting but not a lot
PS I was advised to ask this question to the devs by a cyanogenmod.org mod named bassmadrigal
Click to expand...
Click to collapse
Not sure if this works , but I will eventually try it , but not now , on my free time.
stagefright indeed is not included , my phone too doesn't have stagefright , if you go to youtube and search for android developement tutorials by "thenewboston" . you'll find 200 videos series , just watch the first 20 ones and you'll learn to use Media which replaces stagefright...I didn't try it yet.
It includes
Our_Player and Media Player and the directory of the song....check it out and give us heads ups!
thethiny said:
Not sure if this works , but I will eventually try it , but not now , on my free time.
stagefright indeed is not included , my phone too doesn't have stagefright , if you go to youtube and search for android developement tutorials by "thenewboston" . you'll find 200 videos series , just watch the first 20 ones and you'll learn to use Media which replaces stagefright...I didn't try it yet.
It includes
Our_Player and Media Player and the directory of the song....check it out and give us heads ups!
Click to expand...
Click to collapse
I appreciate the info, I took a look at his tutorials esp the ones involving animation, he really knows his stuff. I am not a Java programmer by any means and to be honest I find it quite tedious, it's like trying to teach a baby (this case the Dalvik VM) to do basic stuff like draw a green ball took like 20 lines of code!
What I need to know essentially is, do I have to use JAVA to get this to work now? In the past ie ICS and lower, there wasn't a problem with Custom Boot Audio, now with JB it seems it has disappeared from the radar.
I know the binary /system/bin/bootanimation (is this written in JAVA?, is there a source code for this bin?) is called at boot time by init.rc in the following manner:
Code:
service bootanim /system/bin/bootanimation
class main
user graphics
group graphics
disabled
oneshot
/system/bin/bootanimation (at least from what I gather) looks in /system/media for bootanimation.zip (zipped in store mode) decompresses it , looks at desc.txt for the code and displays the animation png by png.
In some desc.txt there is an s line, example:
Code:
# mobility
p 1 0 SOUND
s transdroid.mp3
which is SUPPOSED TO call a custom boot audio from /system/media (.mp3?) at the same time. This appears not to work. So logicaly I think the binary needs some tweaking. Can you offer any suggestions?
As you can see I have spent ALLOT of time mulling over why this,one would think, simple task: display a series of images and play audio at boot time I mean how hard can that be?
I am not trying to be a pest I just need to know WHY this doesn't work in JB (CM10.1)

[Script]DSploit Updater

Dsploit is not an application I made, all credit belongs to evilsocket. I only made this script to update the apk.
Every hour or so, everytime the source code of the app changes. A apk is generated automatically.
So this script updates the apk every time you type the command in android terminal emulator.
HOW TO INSTALL?
1) Download the dsupdate.zip
2) Flash it in recovery mode.
HOW TO USE?
1) Download Android Terminal Emulator from the playstore if you had not done so..
2) Open the app
3) Type the following:-
su -
dsupdate
*NOTE Ignore the app_process warnings
4) That's it. You successfully updated the app.
What this script currently does?
1) Backs up the current apk.
2) Downloads the latest apk.
3) Installs the latest version.
This is the current script, if anyone has any suspicions...
Code:
#!/system/bin/sh
DT=$(busybox date)
echo "Script Made By La2o"
echo "Script started at:- $DT"
echo "Checking if old backup exists..."
if [ -e /data/app/it.evilsocket.dsploit-1.apk.bak ]; then
echo "Backup found! Deleting..."
rm -f /data/app/it.evilsocket.dsploit-1.apk.bak
fi
echo "Making a backup of the current apk..."
cp /data/app/it.evilsocket.dsploit-1.apk /data/app/it.evilsocket.dsploit-1.apk.bak
chmod 0644 /data/app/it.evilsocket.dsploit-1.apk.bak
echo "Done!"
cd sdcard
echo "Downloading Nightly APK"
busybox wget "http://94.75.228.27/dsploit/dSploit-nightly.apk"
echo "Installing!"
pm uninstall it.evilsocket.dsploit
pm install dSploit-nightly.apk
echo "Done..."
echo "Deleting Downloaded APK";
rm -f dSploit-nightly.apk
echo "Checking if the app installed correctly..."
cd ..
cd /data/app
ls -a -l | grep dsploit
echo "Done"

[SOLVED] Cannot change LMK minfree values with script in /magisk/.core/service.d

Dear Community, dear Developers outside..
I'm using Magisk 14.0 on a Redmi Note 4 Snapdragon and super satisfied with it.
I just want to make simple changes like changing the lowmemorykiller minfree parameters - just like an init.d script in Kernel Adiutor..
Most of the commands are effective - but some of them are not..
This is what I want to apply for example:
chmod 666 /sys/module/lowmemorykiller/parameters/minfree
chown root /sys/module/lowmemorykiller/parameters/minfree
echo '7283,14566,21849,28928,36415,43698' > /sys/module/lowmemorykiller/parameters/minfree
..but does not work..
But these, for example.. these are working just fine:
echo '30' > /proc/sys/vm/swappiness
echo '0' > /sys/module/lowmemorykiller/parameters/enable_adaptive_lmk
echo '80' > /proc/sys/vm/overcommit_ratio
echo '400' > /proc/sys/vm/vfs_cache_pressure
echo '2430' > /proc/sys/vm/extra_free_kbytes
echo '4096' > /proc/sys/kernel/random/write_wakeup_threshold
echo '1024' > /sys/block/mmcblk0/queue/read_ahead_kb
echo '0' > /sys/block/mmcblk0/queue/iostats
echo '1' > /sys/block/mmcblk0/queue/add_random
echo '1024' > /sys/block/mmcblk1/queue/read_ahead_kb
echo '0' > /sys/block/mmcblk1/queue/iostats
echo '1' > /sys/block/mmcblk1/queue/add_random
swapoff /dev/block/zram0 > /dev/null 2>&1
echo '1' > /sys/block/zram0/reset
echo '0' > /sys/block/zram0/disksize
echo '1' > /sys/block/zram0/max_comp_streams
echo '524288000' > /sys/block/zram0/disksize
mkswap /dev/block/zram0 > /dev/null 2>&1
swapon /dev/block/zram0 > /dev/null 2>&1
echo '4096' > /proc/sys/kernel/random/read_wakeup_threshold
echo '4096' > /proc/sys/vm/min_free_kbytes
echo '0' > /proc/sys/vm/oom_kill_allocating_task
echo '90' > /proc/sys/vm/dirty_ratio
echo '70' > /proc/sys/vm/dirty_background_ratio
I do know that all I have to do is to put my script to one of these dirs - depending on when I want to run the scripts:
/magisk/.core/service.d
/magisk/.core/post-fs-data.d
But, as I mentioned - most of them has effect, some of them has no..
Any comment, any suggestion is more than appreciated.
Thank you!
[SOLVED] - solution is in post #5
Desperate bump..
I searched for help docs for service.d and post-fs-data.d but counldn't find them, can I ask you when each folder is executed, also does the scripts inside them must have .sh extension or not ?
I want to restart my systemui after boot complete, can you tell me if this script is ok ?
Code:
#!system/bin/sh
sleep 20
su
pkill -l TERM -f com.android.systemui
ps : the pkill command works fine after an "su" in terminal emulator
sorry for the offtopic !
@sheraro
https://github.com/topjohnwu/Magisk/blob/master/docs/README.MD
First of all: the solution for my issue was a simple sleep 30 in the services.sh to delay the start.. and I used an auxiliary file as well to make the changes (called from services.sh with 30sec delay, copied with the update-binary file directly, set permission to 0777 via config.sh) after that is all started working..
sheraro said:
I searched for help docs for service.d and post-fs-data.d but counldn't find them, can I ask you when each folder is executed, also does the scripts inside them must have .sh extension or not ?
I want to restart my systemui after boot complete, can you tell me if this script is ok ?
Code:
#!system/bin/sh
sleep 20
su
pkill -l TERM -f com.android.systemui
ps : the pkill command works fine after an "su" in terminal emulator
sorry for the offtopic !
Click to expand...
Click to collapse
So, second thing, @sheraro, I think you should delete the command su from your script because Magisk scripts are running as root anyway and if you issue su command it will start a shell with elevated privileges - an interactive shell, not what you want here, a sudo like command.. it works in the terminal because it is interactive but in the shell script if you start su it starts an interactive shell and it halts your script because it won't exit the shell you started.. and the next command will never run.. if you know what I mean.. but you don't need it anyway, because - as I mentioned - it is running as root anyway. +1: The syntax of the shebang is bad in your example, it is missing an exclamation mark. Can you re-test it like this:
Code:
#!/system/bin/sh
sleep 20
pkill -l TERM -f com.android.systemui
exit 0
.sh extension is not needed, the thing is: you have to set the correct permission in the config.sh like this:
Code:
set_permissions() {
# Default permissions, don't remove them
set_perm_recursive $MODPATH 0 0 0777 0777
[..omitted..]
Thing is: the files must have execute priv. and you can execute them like
Code:
$MODDIR/./desiredfilename
in the services.sh script.
Hope this helps.
crok.bic said:
.sh extension is not needed, the thing is: you have to set the correct permission in the config.sh like this:
Code:
set_permissions() {
# Default permissions, don't remove them
set_perm_recursive $MODPATH 0 0 0777 0777
[..omitted..]
Thing is: the files must have execute priv. and you can execute them like
Code:
$MODDIR/./desiredfilename
in the services.sh script.
Hope this helps.
Click to expand...
Click to collapse
I'm just pasting my script in service.d only, set permissions manually to 0777, corrected !#/system typo, removed su command, but no luck...
Where's services.sh and config.sh ?
sheraro said:
I'm just pasting my script in service.d only, set permissions manually to 0777, corrected !#/system typo, removed su command, but no luck...
Where's services.sh and config.sh ?
Click to expand...
Click to collapse
Reading your comment I think you are not developing a Magisk module, do you?
I do and this is why you have no idea where is config.sh, services.sh and the others I think.
If you just want to have some kind of "init.d script" support and run the script in your own phone *only* then your script should be in the folder /magisk/.core/service.d and it should have execute permission. That's all what you need - probably the sleep 20 is not enough, increase it to sleep 30 for instance.
If this is still not enough info I would suggest to read the Magisk documentation thoroughly (linked in post #4) and if you still stuck I suggest you to open your own thread, describe your problem thoroughly (what is your goal? what would you like to achive? how did you already try? what is happening but should not or not happening but you think it should happen? you know what I mean..) and ask the community. Probably you will be able to solve your issue in minutes/hours.
I changed it to sleep 100, same problem, you're right I should create a new thread for this.
I have a theme installed that mimics oreo style, but the systemUI is not themed until it's restarted, so I thought about a script executed after boot, anyway thanks for your help
It seems that sleep will delay the run of other modules' service.sh. is there any solution that will not affect other module?
nicorg3221 said:
It seems that sleep will delay the run of other modules' service.sh. is there any solution that will not affect other module?
Click to expand...
Click to collapse
I don't experience this behavior - what you described is the post-fs-data behavior.
I did the trick with a separate ("auxiliary") file and tried to explain how in post #5 but let me try again:
- created a file in the module's common folder (I gave the name `tweak`)
- this file starts with a shebang (it's a script..) and continues with a sleep 30 then comes my commands..
- then copied the file from the module to the Magisk module directory into /magisk/$MODDIR with the module file META-INF/com/google/android/update-binary (I added it to the copy section, manually.. I know, I know, it should work automagically anyway, but did not work and I was fed up with the coding, so hardcoded it.. sorry)
- I set the default file permission to 0777 in config.sh (yes, 0777, this is loose AF but works.. and I don't really care, the file contains code that can make the device *better* and has no suid bit set, so there is only little to no room to harm anything..)
- then I included a call in my module's common/service.sh like $MODDIR/./tweak to start my script
- when the tweak script starts it will start with the sleep 30 so implements the delay.. BUT!
- Because services.sh files from the modules are called parallelly by Magisk (by default, by it's nature, by it's code.. you got it) my module does not delays others - but still has the delay.
Hope this helps.
sheraro said:
I changed it to sleep 100, same problem, you're right I should create a new thread for this.
I have a theme installed that mimics oreo style, but the systemUI is not themed until it's restarted, so I thought about a script executed after boot, anyway thanks for your help
Click to expand...
Click to collapse
Pleased to help you - but honestly, if the only task you need is to kill and restart systemUI then I would do it via init.d script run by an app that mimics init.d scripting, or using a kernel that supports init.d scripts (if only you want to use that theme). It's just less complex for you I think, but honestly, a simple script file that has execute permission in /magisk/.core/services.d/ gives you 100% the same solution.
crok.bic said:
I don't experience this behavior - what you described is the post-fs-data behavior.
I did the trick with a separate ("auxiliary") file and tried to explain how in post #5 but let me try again:
- created a file in the module's common folder (I gave the name `tweak`)
- this file starts with a shebang (it's a script..) and continues with a sleep 30 then comes my commands..
- then copied the file from the module to the Magisk module directory into /magisk/$MODDIR with the module file META-INF/com/google/android/update-binary (I added it to the copy section, manually.. I know, I know, it should work automagically anyway, but did not work and I was fed up with the coding, so hardcoded it.. sorry)
- I set the default file permission to 0777 in config.sh (yes, 0777, this is loose AF but works.. and I don't really care, the file contains code that can make the device *better* and has no suid bit set, so there is only little to no room to harm anything..)
- then I included a call in my module's common/service.sh like $MODDIR/./tweak to start my script
- when the tweak script starts it will start with the sleep 30 so implements the delay.. BUT!
- Because services.sh files from the modules are called parallelly by Magisk (by default, by it's nature, by it's code.. you got it) my module does not delays others - but still has the delay.
Hope this helps.
Click to expand...
Click to collapse
I have my script in starting in .Core. Maybe that's the problem
nicorg3221 said:
I have my script in starting in .Core. Maybe that's the problem
Click to expand...
Click to collapse
..then it is in the wrong dir.. it is clearly described in the Magisk documentation.
I have researched a bit. I think you can use getprop sys.boot_completed to check if boot is completed. We should run init.d scripts after boot is completed instead of just wait for 30/100 seconds.
I place all my init.d scripts I want to run in /magisk/.core/service.d/init.d.
Then, I have a service.d script [exec_init_d.sh] in /magisk/.core/service.d. Magisk will run exec_init_d.sh when boot.
exec_init_d.sh will wait for sys.boot_completed and run all the files in /magisk/.core/service.d/init.d after boot completed
exec_init_d.sh
Code:
#!/system/bin/sh
# Please don't hardcode /magisk/modname/... ; instead, please use $MODDIR/...
# This will make your scripts compatible even if Magisk change its mount point in the future
MODDIR=${0%/*}
# This script will be executed in late_start service mode
# More info in the main Magisk thread
if [ "$1" != "1" ]; then
$0 1 &
log -p i -t Magisk "start new instance to let Magisk boot stages proceed"
exit
fi
#param
RUNLOG=0
RETRY_INTERVAL=5 #in seconds
MAX_RETRY=60
EXEC_WAIT=3 #in seconds
INIT_D_DIR=$MODDIR/init.d
LOG_PATH=$MODDIR/debug.log
#init
retry=${MAX_RETRY}
#wait for boot completed
log -p i -t Magisk "wait for boot completed"
while (("$retry" > "0")) && [ "$(getprop sys.boot_completed)" != "1" ]; do
sleep ${RETRY_INTERVAL}
((retry--))
done
if (("$retry" == "0")); then
log -p i -t Magisk "boot not completed within maximum number of retry"
else
log -p i -t Magisk "boot completed"
fi
sleep ${EXEC_WAIT}
log -p i -t Magisk "init.d execution started from ${INIT_D_DIR}"
if (("${RUNLOG}" == "1")); then
/data/magisk/busybox run-parts $INIT_D_DIR &> $LOG_PATH
log -p i -t Magisk "init.d execution output written to $LOG_PATH"
else
/data/magisk/busybox run-parts $INIT_D_DIR
fi
log -p i -t Magisk "init.d execution completed"

Badly made antivirus script I created

Bash:
#This script is satire. This is, like, the worst antivirus ever.
tput setaf 2
echo "Welcome to Web Antivirus."
echo "Make sure you are running this from a live Linux image as the root user."
lsblk
echo "Select your Windows drive: "
read drive
mount $drive /mnt
cd /mnt/Windows/system32/etc
wget https://github.com/T145/black-mirror/releases/download/latest/black_domain.txt >> /dev/null
wget https://github.com/T145/black-mirror/releases/download/latest/black_ipv4.txt >> /dev/null
echo "Downloaded blacklists."
cp hosts.txt hosts.txt.bak
mawk '{print "0.0.0.0 " $0}' black_domain.txt >> hosts.txt
echo "Wrote domain blacklist."
mawk '{print "0.0.0.0 " $0}' black_ipv4.txt >> hosts.txt
echo "Wrote IPv4 blacklist"
rm -f black_domain.txt black_ipv4.txt
echo "Deleted temporary files."
cd /mnt
echo "@echo off" > clean.bat
echo "del %userprofile%\\Downloads\\*.exe" >> clean.bat
echo "Created cleaner script."
echo "Put this in Task Scheduler so it runs at regular intervals."
echo "Options:"
echo "Type \"restore\" to restore original /etc/hosts."
echo "Type \"exit\" to leave."
echo "Select an option: "
alias restore="rm -f hosts.txt && mv hosts.txt.bak hosts.txt"
read option
$option

Categories

Resources