Skip to content

Commit

Permalink
Add README.md and scriptmanager command line tool
Browse files Browse the repository at this point in the history
  • Loading branch information
Amin Rostami committed Oct 30, 2023
1 parent 5730b76 commit 2171952
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Linux Script Manager
- Don't keep your bash scripts in a repository?😱
- Do it with my-script-manager today!

Manage your day to day or work linux bash scripts as a git repository 😍 with command line tool to auto update and sync your machine. 💘

With my-script-manager you can share your scripts between your devices and with your friends and colleagues, easily setup your new devices, keep track of your scripts and never lost them again.

💌 Help this project evolve by your contributin.

# Usage

1. fork this repositry

2. clone your respository in a nice location (ex: /opt)

3. `cd {clone-location}/my-script-manager`

4. load scrits: `sudo ./scriptmanager --load`

5. open new terminal or logout from existing

6. add your scripts in project root directory (see: example), don't forget `sudo chmod +x your-new-script`

7. push your changes

8. sync scripts: `scriptmanager --sync`

9. [optional] add --sync cronjob: `scriptmanager --cron`

10. access and use your scripts from any machine just by clone it in seconds!

11. enjoy your nice scripts!
3 changes: 3 additions & 0 deletions examplescript
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

echo "hi, i am manage happily by linux script manager"
51 changes: 51 additions & 0 deletions scriptmanager
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash


script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"


if [[ $1 == '--load' ]] ; then

if [ "$EUID" -ne 0 ] ; then
echo "Please run --load command as root"
exit
fi
USER_HOME=$(getent passwd "$SUDO_USER" | cut -d : -f 6)
file_path="$USER_HOME/.bashrc"
echo "add scripts to PATH in $file_path"
cat >> $file_path <<- EOM
export PATH="$script_dir:\$PATH" # add my-script-manager scripts
EOM

exit 1
fi


if [[ $1 == '--sync' ]] ; then
echo "sync scripts..."
cd $script_dir
git pull
exit 1
fi


if [[ $1 == '--cron' ]] ; then
echo "add my-script-manager --sync cronjob..."
croncmd="$script_dir/scriptmanager --sync > $script_dir/sync-log.out 2>&1"
cronjob="*/5 * * * * $croncmd" # each 5 minutes
( crontab -l | grep -v -F "$croncmd" ; echo "$cronjob" ) | crontab -
exit 1
fi


echo "Script Manager v0.1
Usage:
scriptmanager [COMMAND]
Commands:
--sync: pull from origin and sync scripts
--load: init my-script-manager and add scripts to PATH (use .profile)
--cron: add cronjob to --sync each 5 minutes
--help: show this message
"

0 comments on commit 2171952

Please sign in to comment.