Skip to content

Commit 2171952

Browse files
author
Amin Rostami
committed
Add README.md and scriptmanager command line tool
1 parent 5730b76 commit 2171952

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Linux Script Manager
2+
- Don't keep your bash scripts in a repository?😱
3+
- Do it with my-script-manager today!
4+
5+
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. 💘
6+
7+
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.
8+
9+
💌 Help this project evolve by your contributin.
10+
11+
# Usage
12+
13+
1. fork this repositry
14+
15+
2. clone your respository in a nice location (ex: /opt)
16+
17+
3. `cd {clone-location}/my-script-manager`
18+
19+
4. load scrits: `sudo ./scriptmanager --load`
20+
21+
5. open new terminal or logout from existing
22+
23+
6. add your scripts in project root directory (see: example), don't forget `sudo chmod +x your-new-script`
24+
25+
7. push your changes
26+
27+
8. sync scripts: `scriptmanager --sync`
28+
29+
9. [optional] add --sync cronjob: `scriptmanager --cron`
30+
31+
10. access and use your scripts from any machine just by clone it in seconds!
32+
33+
11. enjoy your nice scripts!

examplescript

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
echo "hi, i am manage happily by linux script manager"

scriptmanager

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
3+
4+
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5+
6+
7+
if [[ $1 == '--load' ]] ; then
8+
9+
if [ "$EUID" -ne 0 ] ; then
10+
echo "Please run --load command as root"
11+
exit
12+
fi
13+
USER_HOME=$(getent passwd "$SUDO_USER" | cut -d : -f 6)
14+
file_path="$USER_HOME/.bashrc"
15+
echo "add scripts to PATH in $file_path"
16+
cat >> $file_path <<- EOM
17+
export PATH="$script_dir:\$PATH" # add my-script-manager scripts
18+
EOM
19+
20+
exit 1
21+
fi
22+
23+
24+
if [[ $1 == '--sync' ]] ; then
25+
echo "sync scripts..."
26+
cd $script_dir
27+
git pull
28+
exit 1
29+
fi
30+
31+
32+
if [[ $1 == '--cron' ]] ; then
33+
echo "add my-script-manager --sync cronjob..."
34+
croncmd="$script_dir/scriptmanager --sync > $script_dir/sync-log.out 2>&1"
35+
cronjob="*/5 * * * * $croncmd" # each 5 minutes
36+
( crontab -l | grep -v -F "$croncmd" ; echo "$cronjob" ) | crontab -
37+
exit 1
38+
fi
39+
40+
41+
echo "Script Manager v0.1
42+
43+
Usage:
44+
scriptmanager [COMMAND]
45+
46+
Commands:
47+
--sync: pull from origin and sync scripts
48+
--load: init my-script-manager and add scripts to PATH (use .profile)
49+
--cron: add cronjob to --sync each 5 minutes
50+
--help: show this message
51+
"

0 commit comments

Comments
 (0)