From adc9162d3a493c935d27ad5f01508990a3e54af7 Mon Sep 17 00:00:00 2001 From: Yorick Date: Thu, 12 Nov 2015 12:04:05 +0100 Subject: [PATCH 1/6] Very first modification for updating existing Gogs installation --- FreeNAS-Gogs | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 2 +- gogs_root.sh | 66 --------------------------------------- 3 files changed, 89 insertions(+), 67 deletions(-) create mode 100755 FreeNAS-Gogs delete mode 100755 gogs_root.sh diff --git a/FreeNAS-Gogs b/FreeNAS-Gogs new file mode 100755 index 0000000..4e3d7d1 --- /dev/null +++ b/FreeNAS-Gogs @@ -0,0 +1,88 @@ +#!/bin/tcsh +echo "FreeNAS Gogs installation script." +echo "This has been tested on:" +echo " 9.3-RELEASE-p5 FreeBSD 9.3-RELEASE-p5 #1" +echo " f8ed4e8: Fri Dec 19 20:25:35 PST 2014" +echo +echo "Press any key to begin" +set jnk = $< + +if ( -f /usr/locat/etc/rc.d/gogs ) then + update() +else + install() +endif + +update () {a + echo "Updating Gogs..." + echo + # Stop Gogs service + service gogs stop + compile() + service gogs start +} + +install { + # 3) Enable SSH + echo "Enabling SSH" + /usr/bin/sed -i '.bak' 's/sshd_enable="NO"/sshd_enable="YES"/g' /etc/rc.conf + # Generate root keys & Enable root login (with SSH keys). + echo "Enabling root login without password" + echo "PermitRootLogin without-password" >> /etc/ssh/sshd_config + # Start SSH + echo "Starting SSH Service" + /usr/sbin/service sshd start + # 4) Update packages and upgrade any. + echo "Updating packages" + /usr/sbin/pkg update -f + echo "Upgrading packages" + /usr/sbin/pkg upgrade -y + echo "Installing memcached, redis & go" + /usr/sbin/pkg install -y memcached redis go git bash + echo "Enabling & starting memcached & redis" + echo memcached_enable="YES" >> /etc/rc.conf + echo redis_enable="YES" >> /etc/rc.conf + /usr/sbin/service memcached start + /usr/sbin/service redis start + # 5) Create user first; installing git will install a git user to 1001 + echo "Creating git user" + setenv GITHOME /usr/home/git/ + mkdir -p $GITHOME + if (! -d /home ) then + /bin/ln -s /usr/home /home + endif + pw add user -n git -u 913 -d $GITHOME -s /bin/tcsh -c "Gogs - Go Git Service" + chown -R git:git $GITHOME + su - git -c "/usr/bin/ssh-keygen -b 2048 -N '' -f ~/.ssh/id_rsa -t rsa -q &" + # 6) Get & compile gogs + compile () + su - git -c "ln -s /usr/home/git/.ssh/ /usr/home/git/gogs/" + # 7) Start up scripts + echo "Copying startup script to rc.d, enabling & starting gogs" + #/usr/bin/sed 's/\/home\/git/\/home\/git\/gogs/g' /home/git/go/src/github.com/gogits/gogs/scripts/init/freebsd/gogs + cp /home/git/go/src/github.com/gogits/gogs/scripts/init/freebsd/gogs /usr/local/etc/rc.d/ + sed -i -e 's/\/home\/git/\/home\/git\/gogs/g' /usr/local/etc/rc.d/gogs + chmod +x /usr/local/etc/rc.d/gogs + echo gogs_enable="YES" >> /etc/rc.conf + service gogs start + } + +compile() { + echo "Fetching gogs from Github" + su - git -c "setenv GOPATH /usr/home/git/go; go get -u github.com/gogits/gogs" + echo "Getting gogs compile tags" + su - git -c "setenv GOPATH /usr/home/git/go; cd /home/git/go/src/github.com/gogits/gogs; go get -u -tags 'sqlite redis memcache cert' github.com/gogits/gogs" + echo "Compiling gogs" + su - git -c "setenv GOPATH /usr/home/git/go; cd /home/git/go/src/github.com/gogits/gogs; go build -tags 'sqlite redis memcache cert'" + echo "Copying gogs build to git home" + su - git -c "cp -R /usr/home/git/go/src/github.com/gogits/gogs /home/git/" + # Change ownership of everything in the git directory + chown -R git:git /usr/home/git/ +} + +echo +echo +echo + +echo "Gogs should be running on port 3000 on the following addresses:" +ifconfig | grep inet diff --git a/README.md b/README.md index 3da7277..8436575 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # FreeNAS-Gogs -Gogs (gogs.io) install script for FreeNAS (and any FreeBSD Jail) +Gogs (gogs.io) install an update script for FreeNAS (and any FreeBSD Jail) 1. ```git clone https://github.com/jedediahfrey/FreeNAS-Gogs.git``` 2. ```cd FreeNAS-Gogs``` diff --git a/gogs_root.sh b/gogs_root.sh deleted file mode 100755 index 3b8628a..0000000 --- a/gogs_root.sh +++ /dev/null @@ -1,66 +0,0 @@ -#!/bin/tcsh -echo "FreeNAS Gogs installation script." -echo "This has been tested on:" -echo " 9.3-RELEASE-p5 FreeBSD 9.3-RELEASE-p5 #1" -echo " f8ed4e8: Fri Dec 19 20:25:35 PST 2014" -echo -echo "Press any key to begin" -set jnk = $< -# 3) Enable SSH -echo "Enabling SSH" -/usr/bin/sed -i '.bak' 's/sshd_enable="NO"/sshd_enable="YES"/g' /etc/rc.conf -# Generate root keys & Enable root login (with SSH keys). -echo "Enabling root login without password" -echo "PermitRootLogin without-password" >> /etc/ssh/sshd_config -# Start SSH -echo "Starting SSH Service" -/usr/sbin/service sshd start -# 4) Update packages and upgrade any. -echo "Updating packages" -/usr/sbin/pkg update -f -echo "Upgrading packages" -/usr/sbin/pkg upgrade -y -echo "Installing memcached, redis & go" -/usr/sbin/pkg install -y memcached redis go git bash -echo "Enabling & starting memcached & redis" -echo memcached_enable="YES" >> /etc/rc.conf -echo redis_enable="YES" >> /etc/rc.conf -/usr/sbin/service memcached start -/usr/sbin/service redis start -# 5) Create user first; installing git will install a git user to 1001 -echo "Creating git user" -setenv GITHOME /usr/home/git/ -mkdir -p $GITHOME -if (! -d /home ) then - /bin/ln -s /usr/home /home -endif -pw add user -n git -u 913 -d $GITHOME -s /bin/tcsh -c "Gogs - Go Git Service" -chown -R git:git $GITHOME -su - git -c "/usr/bin/ssh-keygen -b 2048 -N '' -f ~/.ssh/id_rsa -t rsa -q &" -# 6) Get & compile gogs -echo "Fetching gogs from Github" -su - git -c "setenv GOPATH /usr/home/git/go; go get -u github.com/gogits/gogs" -echo "Getting gogs compile tags" -su - git -c "setenv GOPATH /usr/home/git/go; cd /home/git/go/src/github.com/gogits/gogs; go get -u -tags 'sqlite redis memcache cert' github.com/gogits/gogs" -echo "Compiling gogs" -su - git -c "setenv GOPATH /usr/home/git/go; cd /home/git/go/src/github.com/gogits/gogs; go build -tags 'sqlite redis memcache cert'" -echo "Copying gogs build to git home" -su - git -c "cp -R /usr/home/git/go/src/github.com/gogits/gogs /home/git/" -su - git -c "ln -s /usr/home/git/.ssh/ /usr/home/git/gogs/" -# Change ownership of everything in the git directory -chown -R git:git /usr/home/git/ -# 7) Start up scripts -echo "Copying startup script to rc.d, enabling & starting gogs" -#/usr/bin/sed 's/\/home\/git/\/home\/git\/gogs/g' /home/git/go/src/github.com/gogits/gogs/scripts/init/freebsd/gogs -cp /home/git/go/src/github.com/gogits/gogs/scripts/init/freebsd/gogs /usr/local/etc/rc.d/ -sed -i -e 's/\/home\/git/\/home\/git\/gogs/g' /usr/local/etc/rc.d/gogs -chmod +x /usr/local/etc/rc.d/gogs -echo gogs_enable="YES" >> /etc/rc.conf -service gogs start - -echo -echo -echo - -echo "Gogs should be running on port 3000 on the following addresses:" -ifconfig | grep inet From 5bb7d164d8262e57cb78f3f992bf355c34388f49 Mon Sep 17 00:00:00 2001 From: Yorick Date: Thu, 12 Nov 2015 12:21:32 +0100 Subject: [PATCH 2/6] copy rc.d script done by compile() --- FreeNAS-Gogs => gogs-root.sh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) rename FreeNAS-Gogs => gogs-root.sh (96%) diff --git a/FreeNAS-Gogs b/gogs-root.sh similarity index 96% rename from FreeNAS-Gogs rename to gogs-root.sh index 4e3d7d1..6863aaf 100755 --- a/FreeNAS-Gogs +++ b/gogs-root.sh @@ -13,13 +13,14 @@ else install() endif -update () {a +update () { echo "Updating Gogs..." echo # Stop Gogs service service gogs stop compile() service gogs start + echo "Update Done!" } install { @@ -58,14 +59,9 @@ install { compile () su - git -c "ln -s /usr/home/git/.ssh/ /usr/home/git/gogs/" # 7) Start up scripts - echo "Copying startup script to rc.d, enabling & starting gogs" - #/usr/bin/sed 's/\/home\/git/\/home\/git\/gogs/g' /home/git/go/src/github.com/gogits/gogs/scripts/init/freebsd/gogs - cp /home/git/go/src/github.com/gogits/gogs/scripts/init/freebsd/gogs /usr/local/etc/rc.d/ - sed -i -e 's/\/home\/git/\/home\/git\/gogs/g' /usr/local/etc/rc.d/gogs - chmod +x /usr/local/etc/rc.d/gogs echo gogs_enable="YES" >> /etc/rc.conf service gogs start - } +} compile() { echo "Fetching gogs from Github" @@ -78,6 +74,11 @@ compile() { su - git -c "cp -R /usr/home/git/go/src/github.com/gogits/gogs /home/git/" # Change ownership of everything in the git directory chown -R git:git /usr/home/git/ + echo "Copying startup script to rc.d, enabling & starting gogs" + #/usr/bin/sed 's/\/home\/git/\/home\/git\/gogs/g' /home/git/go/src/github.com/gogits/gogs/scripts/init/freebsd/gogs + cp /home/git/go/src/github.com/gogits/gogs/scripts/init/freebsd/gogs /usr/local/etc/rc.d/ + sed -i -e 's/\/home\/git/\/home\/git\/gogs/g' /usr/local/etc/rc.d/gogs + chmod +x /usr/local/etc/rc.d/gogs } echo From 99f91504bf297793acb38fa345df7dd53228037c Mon Sep 17 00:00:00 2001 From: Yorick Date: Thu, 12 Nov 2015 13:28:27 +0100 Subject: [PATCH 3/6] since functions not supported on tcsh, call compile script --- gogs-compile.sh | 17 +++++++++++++++++ gogs-root.sh | 37 +++++-------------------------------- 2 files changed, 22 insertions(+), 32 deletions(-) create mode 100755 gogs-compile.sh diff --git a/gogs-compile.sh b/gogs-compile.sh new file mode 100755 index 0000000..301968e --- /dev/null +++ b/gogs-compile.sh @@ -0,0 +1,17 @@ +#!/bin/tcsh +# Gogs compile script for FreeNAS +echo "Fetching gogs from Github" +su - git -c "setenv GOPATH /usr/home/git/go; go get -u github.com/gogits/gogs" +echo "Getting gogs compile tags" +su - git -c "setenv GOPATH /usr/home/git/go; cd /home/git/go/src/github.com/gogits/gogs; go get -u -tags 'sqlite redis memcache cert' github.com/gogits/gogs" +echo "Compiling gogs" +su - git -c "setenv GOPATH /usr/home/git/go; cd /home/git/go/src/github.com/gogits/gogs; go build -tags 'sqlite redis memcache cert'" +echo "Copying gogs build to git home" +su - git -c "cp -R /usr/home/git/go/src/github.com/gogits/gogs /home/git/" +# Change ownership of everything in the git directory +chown -R git:git /usr/home/git/ +echo "Copying startup script to rc.d, enabling & starting gogs" +#/usr/bin/sed 's/\/home\/git/\/home\/git\/gogs/g' /home/git/go/src/github.com/gogits/gogs/scripts/init/freebsd/gogs +cp /home/git/go/src/github.com/gogits/gogs/scripts/init/freebsd/gogs /usr/local/etc/rc.d/ +sed -i -e 's/\/home\/git/\/home\/git\/gogs/g' /usr/local/etc/rc.d/gogs +chmod +x /usr/local/etc/rc.d/gogs diff --git a/gogs-root.sh b/gogs-root.sh index 6863aaf..63d964a 100755 --- a/gogs-root.sh +++ b/gogs-root.sh @@ -8,22 +8,14 @@ echo "Press any key to begin" set jnk = $< if ( -f /usr/locat/etc/rc.d/gogs ) then - update() -else - install() -endif - -update () { echo "Updating Gogs..." echo # Stop Gogs service service gogs stop - compile() + gogs-compile.sh service gogs start echo "Update Done!" -} - -install { +else # 3) Enable SSH echo "Enabling SSH" /usr/bin/sed -i '.bak' 's/sshd_enable="NO"/sshd_enable="YES"/g' /etc/rc.conf @@ -56,31 +48,12 @@ install { chown -R git:git $GITHOME su - git -c "/usr/bin/ssh-keygen -b 2048 -N '' -f ~/.ssh/id_rsa -t rsa -q &" # 6) Get & compile gogs - compile () + gogs-compile.sh su - git -c "ln -s /usr/home/git/.ssh/ /usr/home/git/gogs/" # 7) Start up scripts echo gogs_enable="YES" >> /etc/rc.conf - service gogs start -} - -compile() { - echo "Fetching gogs from Github" - su - git -c "setenv GOPATH /usr/home/git/go; go get -u github.com/gogits/gogs" - echo "Getting gogs compile tags" - su - git -c "setenv GOPATH /usr/home/git/go; cd /home/git/go/src/github.com/gogits/gogs; go get -u -tags 'sqlite redis memcache cert' github.com/gogits/gogs" - echo "Compiling gogs" - su - git -c "setenv GOPATH /usr/home/git/go; cd /home/git/go/src/github.com/gogits/gogs; go build -tags 'sqlite redis memcache cert'" - echo "Copying gogs build to git home" - su - git -c "cp -R /usr/home/git/go/src/github.com/gogits/gogs /home/git/" - # Change ownership of everything in the git directory - chown -R git:git /usr/home/git/ - echo "Copying startup script to rc.d, enabling & starting gogs" - #/usr/bin/sed 's/\/home\/git/\/home\/git\/gogs/g' /home/git/go/src/github.com/gogits/gogs/scripts/init/freebsd/gogs - cp /home/git/go/src/github.com/gogits/gogs/scripts/init/freebsd/gogs /usr/local/etc/rc.d/ - sed -i -e 's/\/home\/git/\/home\/git\/gogs/g' /usr/local/etc/rc.d/gogs - chmod +x /usr/local/etc/rc.d/gogs -} - +endif +service gogs start echo echo echo From 2f65b67a218d8a8f8c0c3e3501df9d6f2ba29665 Mon Sep 17 00:00:00 2001 From: Yorick Date: Thu, 12 Nov 2015 13:57:24 +0100 Subject: [PATCH 4/6] syntax error when call gogs-compile.sh --- gogs-root.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gogs-root.sh b/gogs-root.sh index 63d964a..a6f0724 100755 --- a/gogs-root.sh +++ b/gogs-root.sh @@ -12,8 +12,7 @@ if ( -f /usr/locat/etc/rc.d/gogs ) then echo # Stop Gogs service service gogs stop - gogs-compile.sh - service gogs start + ./gogs-compile.sh echo "Update Done!" else # 3) Enable SSH From 6f38b39376adff9f577c471ebc0329d55ac6c4a4 Mon Sep 17 00:00:00 2001 From: Yorick Date: Thu, 12 Nov 2015 14:15:26 +0100 Subject: [PATCH 5/6] Cleaning ~/go directory after install --- gogs-root.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gogs-root.sh b/gogs-root.sh index a6f0724..aa4b5a5 100755 --- a/gogs-root.sh +++ b/gogs-root.sh @@ -52,6 +52,8 @@ else # 7) Start up scripts echo gogs_enable="YES" >> /etc/rc.conf endif +# cleaning this mess +su - git -c "rm -rf /usr/home/git/go/" service gogs start echo echo From c36b54227998643684ec36e16b5b8c3aebb45bac Mon Sep 17 00:00:00 2001 From: Yorick Date: Thu, 12 Nov 2015 14:29:15 +0100 Subject: [PATCH 6/6] tested on Freenas 9.3 RELEASE p29 --- gogs-root.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gogs-root.sh b/gogs-root.sh index aa4b5a5..b9efaf7 100755 --- a/gogs-root.sh +++ b/gogs-root.sh @@ -1,8 +1,8 @@ #!/bin/tcsh echo "FreeNAS Gogs installation script." echo "This has been tested on:" -echo " 9.3-RELEASE-p5 FreeBSD 9.3-RELEASE-p5 #1" -echo " f8ed4e8: Fri Dec 19 20:25:35 PST 2014" +echo " 9.3-RELEASE-p29" +echo echo echo "Press any key to begin" set jnk = $<