Create GIT Repo NAS

Create GIT Repo NAS - An AppleScript that will help you to create a GIT repository on either a server or NAS (As long as it's reachable via SSH).

It will also initiate it to a bare GIT repository, ready to add files and commit changes.

Pre-requisitions

The NAS or server must have git-server installed, SSH access with RSA public keys (not login via User Name and Password)


Install

Some variables need to be changed to reflect your setup

nasIP - address to the Git server
userName - Username that have public key access
repoPath - path to where the repo will be created
sshPort - the port number the SSH server uses

Usage

When you run the script a dialog will open and ask for the name of the repository.

Image
The script source code:

-- Creates a repo on a NAS or server and inits it to a bare repo
-- By Michael Augustsson
-- Version 1.0 2018-08-18 Initial release

set nasIP to "10.0.1.7"
set
userName to "user"
set
repoPath to "/volume1/git/"
set
sshPort to "25"

-- First we ask for the repo-name


display dialog "Repository Name (note! will take 1 minute to create repository)" default answer ""
set
repoName to text returned of result
try

if
repoName is not "" then

-- we have entered a repo-name, lets create it on the Synology NAS


-- First we create all the commands needed to be executed on the NAS


set
cmd1 to "ssh " & userName & "@" & nasIP & " -p " & sshPort
set
cmd2 to repoPath
set
cmd3 to "sudo mkdir " & repoName & ".git"
set
cmd4 to "sudo chown -R " & userName & ":administrators " & repoName & ".git"
set
cmd5 to "git --bare init " & repoName & ".git"
set
cmd6 to "cd " & repoName & ".git"
set
cmd7 to "git update-server-info"

-- and now start to execute them 1 after 1, the first sudo needs a password

-- but 1:st start a new terminal window so we don't destroy an already open session


tell
application "Terminal"

-- wake up the NAS, can take up to 60 s

set
w to do script "ssh " & userName & "@" & nasIP & " -p " & sshPort & " 'ls -l > /dev/null'"
activate

delay
1
repeat

delay
0.5
if
not busy of w then exit repeat
end
repeat

-- star to send the commands


my
execCmd(cmd1, 1) -- make sure we are logged in before continue
my
execCmd(cmd2, 0)
my
execCmd(cmd3, 1)
my
execCmd(userPW, 1) -- only the first sudo needs a password, and we send that emulatingsh keystrokes
my
execCmd(cmd4, 0)
my
execCmd(cmd5, 1)
my
execCmd(cmd6, 0)
my
execCmd(cmd7, 2) -- 2 seconds to let the git-update to finnish

display dialog
"Repository " & repoName & " Created. Press cancel to let terminl session stay open."
my
execCmd("exit", 0) -- logout from the NAS, can be stopped by pressing cancel instead of ok
close
front window
end
tell
end
if
end
try

-- execute a command by simulating keystrokes

on
execCmd(cmd, pause)
tell
application "System Events"
tell
application process "Terminal"
set
frontmost to true
keystroke
cmd
keystroke
return
end
tell
end
tell
delay
pause
end
execCmd

© 2018-2020 Michael Augustsson Contact Me

improve your online experience. Take a look at the Cookie Privacy to learn more and also my Privacy Policy. By pressing Dismiss I assume you are happy to allow the use of these cookies.

RapidWeaver Icon

Made in RapidWeaver