Skip to content

Instantly share code, notes, and snippets.

@karpatic
Last active September 3, 2024 16:34
Show Gist options
  • Save karpatic/aa0ebbb5dfd676ec62d6c8ad07ee438c to your computer and use it in GitHub Desktop.
Save karpatic/aa0ebbb5dfd676ec62d6c8ad07ee438c to your computer and use it in GitHub Desktop.
Instructions for setting up a Termux script to send a file to a specific domain with a single button on your Android homescreen using Termux:Widget.
to set up a script in Termux that can be run with a single button on your Android homescreen to send a file to a specific domain.
- Install Termux from F-Droid (or Google Play if available).
- Install Termux:Widget to create the button on the homescreen.
Complete Instructions: [here](https://github.com/termux/termux-widget)
When you install the Termux:Widget, it expects scripts (bash scripts with a .sh extension) to be located in a specific directory
(~/.shortcuts/). Any script you place in that directory will be automatically recognized by Termux:Widget and
will be available for you to place as a widget on your Android homescreen.
https://www.reddit.com/r/termux/comments/nun3qg/termuxwidget_doesnt_seem_to_do_anything_when_i/
Scripts in ~/.shortcuts/tasks run in background, that's why you only get a flash and a notification. It likely says 0 tasks since script quickly finishes and you don't notice the change... Add your scripts in ~/.shortcuts if you want the scripts to run in foreground terminal
1. Create the Shortcut Script:
nano ~/.shortcuts/send-to-website-main.sh
2. Use it to redirect to script in shared directory
```
#!/bin/sh
~/scripts/send-to-website-main.sh
```
3. Make Executable
`chmod +x ~/.shortcuts/send-to-website-main.sh`
4. Connect phone and create Main Script on PC. (or from terminal)
`nano ~/scripts/send-to-website.sh`
```
#!/bin/sh
curl -X POST -F "file=@[PATH_TO_YOUR_FILE]" https://charleskarpati.com/[ENDPOINT]
```
5. Make Executable
`chmod +x ~/scripts/send-to-website.sh`
Helpful
cd ~/storage/shared/
cd ./scripts
cd ./downloads/EUC World
nano ~/.shortcuts/copy_scripts.sh
chmod -x ~/.shortcuts/copy_scripts.sh
#!/bin/bash
# Path for the scripts folder in the home directory
TARGET_DIR=~/scripts
# Path for the scripts folder in shared storage
SOURCE_DIR=~/storage/shared/scripts
# Check if the ~/scripts folder exists
if [ -d "$TARGET_DIR" ]; then
echo "Deleting existing ~/scripts folder..."
rm -rf "$TARGET_DIR"
fi
# Copy ~/storage/shared/scripts to ~/scripts
echo "Copying $SOURCE_DIR to $TARGET_DIR..."
cp -r "$SOURCE_DIR" "$TARGET_DIR"
echo "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment