error while installing go from source - go

i am trying to install go from source
i follow this steps
git clone https://go.googlesource.com/go
cd go
git checkout go1.6.1
cd src
./all.bash
now it gives me the error saying
##### Building Go bootstrap tool.
cmd/dist
ERROR: Cannot find /root/go1.4/bin/go.
Set $GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4.
any idea how can i fix this do i just need to set env variable or any other installation is needed ?

You need to have an installed Go version 1.4 or newer to build the recent Go releases. The build script defaults to some path but if it's not there you need to set GOROOT_BOOTSTRAP environment variable to point to a previous working Go installation.

Go is written in Go (starting from version 1.5) so you have to install Go1.4 first. Just get Go Version Manager and run:
$ gvm install go1.4
$ gvm use go1.4
$ export GOROOT_BOOTSTRAP=$GOROOT
Another approach is about to install gcc go frontend:
$ sudo apt-get install gccgo-5
$ sudo update-alternatives --set go /usr/bin/go-5
$ export GOROOT_BOOTSTRAP=/usr

If you are not using gvm and are on Linux, your go binary is mostly installed at /usr/local/go/bin/go. You need to set /usr/local/go as your GOROOT_BOOTSTRAP by:
$ export GOROOT_BOOTSTRAP=/usr/local/go

The following won't work if you haven't previously built from source (the version parsing will fail). Unfortunately it also won't work for windows (unless you're in wsl/cygwin/msys et cetera).
If you have the source for an older version you may want to use the following zsh/bash(?) function
# create a backup of a directory by recursively copying its contents into an empty one with a similar name
bckp () {
old=$1
if [[ -z $1 ]]; then
old="../$(basename "$(pwd)")"
fi
new="$old-bckp"
[[ -d $new ]] && echo "already exists" && return 1
cp -rf "$old/" "$new"
}
then do one, or some combination, of the following
if you have unstashed changes you want to commit:
cd $(go env GOROOT) # visit the root directory of your current go installation
bckp # back it up
git stash # keep any changes you've made but do not want to commit in a safe place
git pull # collect remote commits
git stash pop # restore your changes
cd src # go to the golang source files and installation scripts
export GOROOT_BOOTSTRAP=$(go env GOROOT)-bckp # make the environment variable accessible from other shells
chmod +x ./all.bash # set the permissions of the installation/build script so that it can be executed
./all.bash # execute the installation/build script
cd ../bin && sudo ln -f $PWD/go /usr/bin/go # create a globablly accessible link to the new binary, feels like it should be unnecessary but I couldn't use the new binary until I did this
or, if you've already pulled the commits you wish to include and popped your changes:
cd $(go env GOROOT) # visit the root directory of your current go installation
bckp # back it up
cd ../go-bckp # enter the backup directory
git stash # keep any changes you've made but do not want to commit in a safe place
git checkout $(go version | cut -d- -f2 | cut -d" " -f1) # parse version info and restore the old codebase
git stash pop # restore your changes
cd ../go/src # go to the golang source files and installation scripts
export GOROOT_BOOTSTRAP=$(go env GOROOT)-bckp # make the environment variable accessible from other shells
chmod +x ./all.bash # set the permissions of the installation/build script so that it can be executed
./all.bash # execute the installation/build script
cd ../bin && sudo ln -f $PWD/go /usr/bin/go # create a globablly accessible link to the new binary, feels like it should be unnecessary but I couldn't use the new binary until I did this
or if you haven't made any changes:
cd $(go env GOROOT) # visit the root directory of your current go installation
bckp # back it up
cd src # go to the golang source files and installation scripts
export GOROOT_BOOTSTRAP=$(go env GOROOT)-bckp # make the environment variable accessible from other shells
chmod +x ./all.bash # set the permissions of the installation/build script so that it can be executed
./all.bash # execute the installation/build script
cd ../bin && sudo ln -f $PWD/go /usr/bin/go # create a globablly accessible link to the new binary, feels like it should be unnecessary but I couldn't use the new binary until I did this.

Related

Trying to set GOPATH and GOROOT in AWS EC2 user data, but it is not working

I am trying to set up GOPATH GOROOT in my AWS EC2 Ubuntu 20.04 user data, but it never worked, every time I connect to the AWS EC2 and view the log in /var/log/cloud-init-output.log it always says
go: not found, but if I key in the echo part it will work.
I am trying to set up multiple EC2 with this basis, so I can't key in every instance myself.
The CloudFormation yaml user data part is below:
UserData:
Fn::Base64: |
#!/bin/bash
wget https://dl.google.com/go/go1.14.4.linux-amd64.tar.gz
tar -C /usr/local -zxvf go1.14.4.linux-amd64.tar.gz
mkdir -p ~/go/{bin,pkg,src}
echo 'export GOPATH=$HOME/go' >> ~/.bashrc
echo 'export GOROOT=/usr/local/go' >> ~/.bashrc
echo 'export PATH=$PATH:$GOPATH/bin:$GOROOT/bin' >> ~/.bashrc
echo 'export GO111MODULE=auto' >> ~/.bashrc
source ~/.bashrc
apt -y update
apt -y install mongodb wget git
systemctl start mongodb
apt -y install git gcc cmake autoconf libtool pkg-config libmnl-dev libyaml-dev
go get -u github.com/sirupsen/logrus
cd ~
git clone --recursive https://github.com/williamlin0504/free5gcWithOCF.git
cd free5gcWithOCF
make
And here is the error inside /var/log/cloud-init-output.log
Error while user data runs
Is there anyone is familiar with this, please I need some help~
In your error message, in the Makefile at line 30 there is a program bin/amf being used
This program appears to be a shell script with a problem in line 1
The nature of the problem is "go: not found"
If you have the bare word "go" in line 1 of the shell script and the path cannot find it then this is what will happen
Probably you need to alter the last line of your userdata shell script to say
PATH=/usr/local/go/bin:$PATH make
I know you have a source command earlier in the script that is supposed to set this up but it doesn't do what you think it does

Prevent git from overwriting file owner upon git pull

I've seen a handful of similar questions on here, but none of the solutions given seem to be working... wondering if they're outdated, or this case is somehow different...so I wanted to open up a new thread to talk about it.
I've run into a frustrating problem where, every time I perform and git pull, it changes the owner to the pull-er's user. What happens then is that the site shows the following error:
Warning: file_get_contents(/var/www/html/wp-content/themes/<my-theme>/resources/views/<changed-file>): failed to open stream: Permission denied in /var/www/html/wp-includes/class-wp-theme.php on line 1207
which can only be fixed by running chown www-data on the changed file.
This will become an issue when more people begin to work on the site, or when important files are change (default template/header/footer..), and the site goes blank until chown is run.
Site details
Laravel, wordpress, ubuntu 18, armor hosting
Git repo stored in custom theme
I've tried a few solutions, but none seem to work, (perhaps because they're implemented incorrectly..)
Solutions I've tried
1: set filemode to false - I set filemode to false, locally and globally, on my local machine and the server in question. I've tried changing the case to "fileMode" too.
2: implement post-update hook - I added a post update hook to automatically update the file permissions/ownership. Here's the script (note that the git repo is in the custom theme):
#!/bin/sh
# default owner user
OWNER="www-data:www-data"
# changed file permission
PERMISSION="664"
# web repository directory
REPO_DIR="/var/www/html/wp-content/themes/quorum-theme"
# remote repository
REMOTE_REPO="origin"
# public branch of the remote repository
REMOTE_REPO_BRANCH="master"
cd $REPO_DIR || exit
unset GIT_DIR
files="$(git diff-tree -r --name-only --no-commit-id HEAD#{1} HEAD)"
git merge FETCH_HEAD
for file in $files
do
sudo chown $OWNER $file
sudo chmod $PERMISSION $file
done
exec git-update-server-info
Let me know if there is anything else worth trying, or if you notice an issue with my code...
All the best,
Jill
You are pretty close to the correct solution.
You need to enable the following hooks:
post-merge, called after a successful git pull
post-checkout, called after a successful git checkout
If you are sure to only use git pull, the post-merge hook is enough.
Enabling both hooks guarantee you the hook is always called at not extra cost.
The content of the hook should be like:
#!/bin/sh
# default owner user
OWNER="www-data:www-data"
# web repository directory
REPO_DIR="/var/www/html/wp-content/themes/quorum-theme"
echo
echo "---"
echo "--- Resetting ownership to ${OWNER} on ${REPO_DIR}"
sudo chown -R $OWNER $REPO_DIR
echo "--- Done"
echo "---"
The script will reset the ownership to OWNER of all files and directory inside REPO_DIR.
I have copied the values from your post, eventually change it to your needs.
To enable the hook you should:
create a file named post-merge with the script above
move it inside the directory .git/hook/ of your repo
give it the executable permission with chmod +x post-merge
Repeat eventually these steps for the post-checkout hook, that needs to be equal to the post-merge hook.
Pay attention to perform a sudo git pull if your user is not root. All the files and directories in the target directory are owned by www-data, you need to perform the git pull command with a superuser privilege or the command will fail.
From the looks of your question, it looks like you are using git pull to deploy in production.
git is not a deployment tool. If you want to deploy your code, I would invite you to write a deployment script.
The first version of your script could be :
# deploy.sh
# cd to the appropriate directory :
cd /var/www/mysite
# change to the correct user before pulling :
sudo -u www-data git pull
An updated version would be to stop depending on git pull.
Ideally : you want to be able to identify the versions of your code that can be deployed to productions, and not depend on the fact that "git pull will work without triggering merge conflicts".
Here is the outline of a generic workflow you can follow :
When you want to deploy to production :
produce some artifact that packs your code from an identified commit : for php code this can be a simple .tar.gz
# set a clearly identifiable tag on target commit
git tag v-x.y.z
# create a tar.gz archive that stores the files :
# look at 'git help archive'
git archive -o ../myapp-x.y.z.tgz v-x.y.z
push that artifact your production server
scp myapp-x.y.z.tgz production-server:
run your deployment script, without calling git anymore :
# deploy.sh :
# usage : ./deploy.sh myapp-x.y.z.tgz
archive="$1"
# extract the archive to a fresh folder :
mkdir /var/www/mysite.new
tar -C /var/www/mysite.new -xzf "$archive"
chown -R www-data: /var/www/mysite.new
# replace old folder with new folder :
mv /var/www/mysite /var/www/mysite.old
mv /var/www/mysite.new /var/www/mysite
Some extra actions you will generally want to manage around your deployment :
backup your database before deploying
hanlde config parameters (copy your production config file ? setup the environment ? ...)
apply migration actions
restart apache or nginx
...
You probably want to version that deploy.sh script along with your project.
My approach works for me.
First, add a file named post-merge to /path/to/your_project/.git/hooks/
cd /path/to/your_project/.git/hooks/
touch post-merge
Then, change it's ownership to same as <your_project> folder(this is the same as nginx and php-fpm runner), in my case, I use www:www
sudo chown www:www post-merge
Then change it's file mode to 775(then it can be executed)
sudo chmod 775 post-merge
Then put the snippet below to post-merge. To understand the snippet, see here(actually that's me).
#!/bin/sh
# default owner user
OWNER="www:www"
# changed file permission
PERMISSION="664"
# web repository directory
REPO_DIR="/www/wwwroot/your_project/"
# remote repository
REMOTE_REPO="origin"
# public branch of the remote repository
REMOTE_REPO_BRANCH="master"
cd $REPO_DIR || exit
unset GIT_DIR
files="$(git diff-tree -r --name-only --no-commit-id HEAD#{1} HEAD)"
for file in $files
do
sudo chown $OWNER $file
sudo chmod $PERMISSION $file
done
exec git-update-server-info
Everything is done, now, go back to your_project folder
cd /path/to/your_project/
run git pull under your_project folder, remember you must run as root or sudo(I remember sudo)
sudo git pull
Now check the new file that pulled from remote repository, see if its ownership has been changed to www:www(if it was as expected, the ownership of the new pulled file should be changed to www:www).
This approach is much better than sudo chown -R www:www /www/wwwroot/your_project/, because it only change the new file's ownership, not all of then! Say I just pulled 2 new file, if you change the whole folder's ownership, it's costs more time and server resources(cpu usage, memory usage...), that's totally unnecessary.

Activate virtualenv INSIDE the my current bash (no subprocess)

I want to have a generic BASH script witch activates my virtual
environment inside a given folder.
The script should be able to be called from from any folder I have a virtual environment in.
If there is no virtual environment it should create one and install the pip requirements.
I can not run the activation inside my original BASH only as a subprocess (see --rcfile). Just source-ing it is not working!
Thats my current script:
#!/bin/bash -e
# BASH script to run virtual environment
# Show errors
set -x
DIR_CURRENT="$PWD"
DIR_VIRTUAL_ENV="$PWD/venv"
FILE_PYTHON="/usr/bin/python2.7"
FILE_REQUIREMENTS="requirements.txt"
FILE_VIRTUAL_ACTIVATE_BASH="$DIR_VIRTUAL_ENV/bin/activate"
# CD to current folder
cd ${DIR_CURRENT}
echo DIR: $(pwd)
# Create the virtual environment if not existing
if [ ! -d ${DIR_VIRTUAL_ENV} ]; then
virtualenv -p ${FILE_PYTHON} ${DIR_VIRTUAL_ENV}
chmod a+x ${FILE_VIRTUAL_ACTIVATE_BASH}
source ${FILE_VIRTUAL_ACTIVATE_BASH}
pip install -r ${FILE_REQUIREMENTS}
fi
/bin/bash --rcfile "$FILE_VIRTUAL_ACTIVATE_BASH"
# Disable errors
set +x
I use Mac OSX 10.10.5 and Python 2.7.
Sadly existing 1, 2, 3 questions couldn't answer my problem.
First, what you are trying to do has already been nicely solved by a project called virtualenvwrapper.
About your question: Use a function instead of a script. Place this into your bashrc for example:
function enter_venv(){
# BASH script to run virtual environment
# Show errors
set -x
DIR_CURRENT="$PWD"
DIR_VIRTUAL_ENV="$PWD/venv"
FILE_PYTHON="/usr/bin/python2.7"
FILE_REQUIREMENTS="requirements.txt"
FILE_VIRTUAL_ACTIVATE_BASH="$DIR_VIRTUAL_ENV/bin/activate"
# CD to current folder
cd ${DIR_CURRENT}
echo DIR: $(pwd)
# Create the virtual environment if not existing
if [ ! -d ${DIR_VIRTUAL_ENV} ]; then
virtualenv -p ${FILE_PYTHON} ${DIR_VIRTUAL_ENV}
chmod a+x ${FILE_VIRTUAL_ACTIVATE_BASH}
source ${FILE_VIRTUAL_ACTIVATE_BASH}
pip install -r ${FILE_REQUIREMENTS}
fi
/bin/bash --rcfile "$FILE_VIRTUAL_ACTIVATE_BASH"
# Disable errors
set +x
}
The you can call it like this:
enter_venv

Where are the svn hook files located in OS X?

I'm running OS X Mavericks. Pretty sure I got svn from the Command Line Tools from the Apple Developer site.
I've searched around for where hook script are supposed to be located. All the articles I've found (e.g. this one: https://stackoverflow.com/a/7577251/726378) say that there is a hooks directory in the repository directory. I have found no such directory.
Where is this directory?
Is this directory on the svn server or the client?
In Subversion, hooks are run on the server side, and are located inside the repository directory on the server.
Try this:
$ cd $HOME
$ svnadmin create foo_repo # Creating Subversion repository called "foo_repo"
$ cd foo_repo
$ hooks
post-commit.tmpl post-revprop-change.tmpl pre-commit.tmpl
pre-revprop-change.tmpl start-commit.tmpl post-lock.tmpl
post-unlock.tmpl pre-lock.tmpl pre-unlock.tmpl
There they are!
You can try using this repo if you'd like:
$ cd $HOME/foo_repo/conf
$ vi svnserve.conf # Remove the "#" from "password-db = passwd" (Line 27)
$ vi passwd # You want to define a password for your user
$ cd $HOME
$ svnserve -r foo_repo -d # Starts up the Subversion server
$ mkdir $HOME/workdir
$ cd $HOME/workdir
$ svn co svn://localhost localhost
$ cd localhost # Your Subversion working directory!
Now, you can play around with your various hook and see how it affects using your repository.

Git Bash cannot find git directory when git is installed

I'm running cap deploy to deploy a site to a server. It deploys just fine, except for this last part:
export GIT_RECURSIVE=$([ ! \"`git --version`\" \\< \"git version 1.6.5\" ] && echo --recursive) && git submodule -q update --init $GIT_RECURSIVE && (echo b8ce153ac56e3e79eda1e053b922ac48e775321a > /var/www/alkdfjf/releases/20130822204731/REVISION)
If I didn't have git, I have git installed, as it clones just fine. But at this step, I receive an error stating:
bash: "git: No such file or directory.
I think the .git folder those files are in is usually hidden and needs higher privileges. Are you sure you don't need or that you are sudo or whatever the equivalent is on Macs?
Use the full path to git in your command, i.e. /usr/local/bin/git or what ever it is on your system.

Resources