From e49289ab20b256f6b93b08226075765a0f7eef41 Mon Sep 17 00:00:00 2001 From: Patrick Mulligan Date: Sat, 21 Jun 2025 17:10:20 +0200 Subject: [PATCH 1/5] update readme; include script for changing extension name fix update update --- README.md | 37 ++++++++++++++++++++++++++++++------- updateExtensionName.sh | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 updateExtensionName.sh diff --git a/README.md b/README.md index adc2dd0..95e82c1 100644 --- a/README.md +++ b/README.md @@ -8,12 +8,35 @@ Ready to start hacking? Once you've forked this extension, you can incorporate f ### How to Use This Template -> This guide assumes you're using this extension as a base for a new one, and have installed LNbits using https://github.com/lnbits/lnbits/blob/main/docs/guide/installation.md#option-1-recommended-poetry. +> [!IMPORTANT] the sequence of steps is very important so as not to run into issues! -* Stop LNbits -* Clone this extension into the extension folder -* Make your changes to models.py/migration.py (if you run without making your changes it will build the db and you will likely have to delete later - no biggie, but making the chnages first helps) -* Hack about building your awesome new extension. Start/stop LNbits as you are hacking. -* Share. Profit. Innovate. Win! +> [!NOTE] You may want to modify your models.py/migration.py before installing the extension on your lnbits server (between steps -IMPORTANT: If you want your extension to be added to the official LNbits manifest, please follow the guidelines here: https://github.com/lnbits/lnbits-extensions#important +> This guide assumes you're using this extension as a base for a new one, and have installed LNbits using . + +1. Fork this extension to your Github repo with the name you want, e.g., `yourextensionname` -> (do not include hyphens as they can cause issues!) + +1. Clone the Repository to your local computer. `git clone git@github.com/yourgithubuersname/yourextensionname` + +1. `cd` into the folder `yourextensionname` and delete the `.git` folder with `rm -rf .git` + +1. run `./updateExtensionName.sh myextension: myExtension: MyExtension:` (to replace all variations) + +1. edit `./manifest.json` and replace the organization `lnbits` with `` + +1. (Optional) Modify your models.py/migration.py file to create your own database tables, or just play with the already existing ones + +1. Re-initialize a git repo with `git init && git add . && git commit -m "initial commit"` + +1. [!IMPORTANT] **you must create a release** *in your github repo* in order for it to show up in your lnbits extensions! + +1. Start up your lnbits server and go to the Settings -> EXTENSIONS and add your manifest to the extension sources. It should be `https://raw.githubusercontent.com///main/manifest.json` (going to this link should show your updated manifest) and **save**. ![Extension Sources](https://i.imgur.com/MUGwAU3.png) +1. Great! Now if you go to the **Extensions** and go to the **ALL** tab, you should see your extension available for installing! (note that Github has an API rate limit, and you may want to include an API key generated from your github account in the `.env` file) + +1. Remove the installed extension from `lnbits/lnbits/extensions`. + +1. Create a symbolic link using `ln -s /home/ben/Projects/ /home/ben/Projects/lnbits/lnbits/extensions`. + +1. Restart your LNbits installation. You can now modify your extension and the changes will appear on your LNbits instance (stop & restart your lnbits for full initialization of all files if needed, e.g., for migration to take effect). You can also `git push` changes to your new repo and create a release *in your github repo* if you want to install it from a fresh lnbits! + +1. IMPORTANT: If you want your extension to be added to the official LNbits manifest, please follow the guidelines here: diff --git a/updateExtensionName.sh b/updateExtensionName.sh new file mode 100644 index 0000000..3b44c38 --- /dev/null +++ b/updateExtensionName.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +set -euo pipefail + +for pair in "$@"; do + OLD="${pair%%:*}" + NEW="${pair##*:}" + + echo "🔁 Replacing $OLD with $NEW..." + + # Replace in filenames + find . -type f -name "*${OLD}*" | while read -r file; do + dir=$(dirname "$file") + base=$(basename "$file") + new_base="${base//$OLD/$NEW}" + new_path="$dir/$new_base" + mv "$file" "$new_path" + echo "Renamed file: $file -> $new_path" + done + + # Replace in file contents + find . -type f -print0 | xargs -0 sed -i "s/${OLD}/${NEW}/g" + + # Rename dirs + find . -depth -type d -name "*${OLD}*" | while read -r dir; do + parent=$(dirname "$dir") + base=$(basename "$dir") + new_base="${base//$OLD/$NEW}" + new_path="$parent/$new_base" + mv "$dir" "$new_path" + echo "Renamed directory: $dir -> $new_path" + done + +done + +echo "✅ Done with all replacements." From 606038165859bb12c04ee5e644e58345352fa16a Mon Sep 17 00:00:00 2001 From: Patrick Mulligan Date: Sun, 22 Jun 2025 09:50:58 +0200 Subject: [PATCH 2/5] make executable --- updateExtensionName.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 updateExtensionName.sh diff --git a/updateExtensionName.sh b/updateExtensionName.sh old mode 100644 new mode 100755 From d8fdf7593ea307dc23072ac116e818b65d3a7dbd Mon Sep 17 00:00:00 2001 From: Patrick Mulligan Date: Mon, 23 Jun 2025 18:14:52 +0200 Subject: [PATCH 3/5] update --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 95e82c1..994293d 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,8 @@ Ready to start hacking? Once you've forked this extension, you can incorporate f 1. Re-initialize a git repo with `git init && git add . && git commit -m "initial commit"` +1. Push to your github repo + 1. [!IMPORTANT] **you must create a release** *in your github repo* in order for it to show up in your lnbits extensions! 1. Start up your lnbits server and go to the Settings -> EXTENSIONS and add your manifest to the extension sources. It should be `https://raw.githubusercontent.com///main/manifest.json` (going to this link should show your updated manifest) and **save**. ![Extension Sources](https://i.imgur.com/MUGwAU3.png) From 29e42d13dbb6bc1a0cc72c28177f910136e5f45a Mon Sep 17 00:00:00 2001 From: Patrick Mulligan Date: Tue, 24 Jun 2025 08:46:27 +0200 Subject: [PATCH 4/5] ignore .git folder when renaming --- updateExtensionName.sh | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/updateExtensionName.sh b/updateExtensionName.sh index 3b44c38..9c335c6 100755 --- a/updateExtensionName.sh +++ b/updateExtensionName.sh @@ -1,14 +1,18 @@ #!/usr/bin/env bash + +# Usage: ./rename-plugin.sh oldname:newname [old2:new2 ...] + set -euo pipefail -for pair in "$@"; do - OLD="${pair%%:*}" - NEW="${pair##*:}" +# Function to rename files, contents, and directories +rename_pair() { + local OLD="$1" + local NEW="$2" - echo "🔁 Replacing $OLD with $NEW..." + echo "🔁 Replacing '$OLD' with '$NEW'..." - # Replace in filenames - find . -type f -name "*${OLD}*" | while read -r file; do + # 1. Rename files with OLD in the name + find . -type f -not -path "*/.git/*" -name "*${OLD}*" | while read -r file; do dir=$(dirname "$file") base=$(basename "$file") new_base="${base//$OLD/$NEW}" @@ -17,11 +21,11 @@ for pair in "$@"; do echo "Renamed file: $file -> $new_path" done - # Replace in file contents - find . -type f -print0 | xargs -0 sed -i "s/${OLD}/${NEW}/g" + # 2. Replace inside file content + find . -type f -not -path "*/.git/*" -print0 | xargs -0 sed -i "s/${OLD}/${NEW}/g" - # Rename dirs - find . -depth -type d -name "*${OLD}*" | while read -r dir; do + # 3. Rename directories (bottom-up) + find . -depth -type d -not -path "*/.git/*" -name "*${OLD}*" | while read -r dir; do parent=$(dirname "$dir") base=$(basename "$dir") new_base="${base//$OLD/$NEW}" @@ -29,7 +33,13 @@ for pair in "$@"; do mv "$dir" "$new_path" echo "Renamed directory: $dir -> $new_path" done +} +# Main loop over all name pairs +for pair in "$@"; do + OLD="${pair%%:*}" + NEW="${pair##*:}" + rename_pair "$OLD" "$NEW" done -echo "✅ Done with all replacements." +echo "✅ All done, with .git folder safely ignored." From e28e9bd49d38593ade89a4ae68f0a599c4678dcc Mon Sep 17 00:00:00 2001 From: Patrick Mulligan Date: Tue, 24 Jun 2025 10:51:00 +0200 Subject: [PATCH 5/5] make prettier --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 994293d..8764d12 100644 --- a/README.md +++ b/README.md @@ -30,15 +30,15 @@ Ready to start hacking? Once you've forked this extension, you can incorporate f 1. Push to your github repo -1. [!IMPORTANT] **you must create a release** *in your github repo* in order for it to show up in your lnbits extensions! +1. [!IMPORTANT] **you must create a release** _in your github repo_ in order for it to show up in your lnbits extensions! -1. Start up your lnbits server and go to the Settings -> EXTENSIONS and add your manifest to the extension sources. It should be `https://raw.githubusercontent.com///main/manifest.json` (going to this link should show your updated manifest) and **save**. ![Extension Sources](https://i.imgur.com/MUGwAU3.png) +1. Start up your lnbits server and go to the Settings -> EXTENSIONS and add your manifest to the extension sources. It should be `https://raw.githubusercontent.com///main/manifest.json` (going to this link should show your updated manifest) and **save**. ![Extension Sources](https://i.imgur.com/MUGwAU3.png) 1. Great! Now if you go to the **Extensions** and go to the **ALL** tab, you should see your extension available for installing! (note that Github has an API rate limit, and you may want to include an API key generated from your github account in the `.env` file) 1. Remove the installed extension from `lnbits/lnbits/extensions`. 1. Create a symbolic link using `ln -s /home/ben/Projects/ /home/ben/Projects/lnbits/lnbits/extensions`. -1. Restart your LNbits installation. You can now modify your extension and the changes will appear on your LNbits instance (stop & restart your lnbits for full initialization of all files if needed, e.g., for migration to take effect). You can also `git push` changes to your new repo and create a release *in your github repo* if you want to install it from a fresh lnbits! +1. Restart your LNbits installation. You can now modify your extension and the changes will appear on your LNbits instance (stop & restart your lnbits for full initialization of all files if needed, e.g., for migration to take effect). You can also `git push` changes to your new repo and create a release _in your github repo_ if you want to install it from a fresh lnbits! 1. IMPORTANT: If you want your extension to be added to the official LNbits manifest, please follow the guidelines here: