some improvements
This commit is contained in:
parent
98057ae340
commit
d4c169aaa6
3 changed files with 66 additions and 59 deletions
65
build-go.sh
65
build-go.sh
|
|
@ -1,56 +1,62 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
if [ ${EUID} -ne 0 ]; then
|
||||
echo "error: this script must be run as root" 1>&2
|
||||
set -x
|
||||
if [ $(id -u) -ne 0 ]; then
|
||||
echo "error: this script must be run as root">&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
INSTALL="/usr/local"
|
||||
GITHUB="https://github.com/golang/go/archive"
|
||||
install_dir="/usr/local"
|
||||
go_dir="${install_dir}/go"
|
||||
url="https://github.com/golang/go/archive"
|
||||
|
||||
V14="go1.4.3"
|
||||
bootstrap="${INSTALL}/bootstrap-${V14}"
|
||||
TGZ14="${V14}.tar.gz"
|
||||
v14="go1.4.3"
|
||||
v14_sum="65e8d2ea08447f02f8b6ab63778e4d98586ac4fd676401dae0eda494c7829965"
|
||||
bootstrap="${install_dir}/bootstrap-${v14}"
|
||||
tgz14="${v14}.tar.gz"
|
||||
path_v14="${install_dir}/${tgz14}"
|
||||
|
||||
Vnew="go1.12.4"
|
||||
TGZnew="${Vnew}.tar.gz"
|
||||
new="go1.12.9"
|
||||
new_sum="c31433aa0bb01856c812d40a91336e25cbce2e50800eb9fe88a7adf0305f1a5b"
|
||||
tgznew="${new}.tar.gz"
|
||||
path_new="${install_dir}/${tgznew}"
|
||||
|
||||
rm -rf ${INSTALL}/go*
|
||||
rm -rf ${go_dir}
|
||||
|
||||
if [ ! -d "${bootstrap}" ]; then
|
||||
wget -q ${GITHUB}/${TGZ14} -O ${INSTALL}/${TGZ14}
|
||||
tar xfz ${INSTALL}/${TGZ14} -C ${INSTALL}
|
||||
mv ${INSTALL}/go-${V14} ${bootstrap}
|
||||
if [[ ! -d "${bootstrap}" ]]; then
|
||||
wget -q ${url}/${tgz14} -O ${path_v14}
|
||||
if [[ "$(sha256sum ${path_v14}|cut -d" " -f1)" != "${v14_sum}" ]]; then
|
||||
echo "error: wrong checksum: ${path_v14}">&2
|
||||
exit 1
|
||||
fi
|
||||
tar xfz ${path_v14} -C ${install_dir}
|
||||
mv ${install_dir}/go-${v14} ${bootstrap}
|
||||
fi
|
||||
|
||||
wget -q ${GITHUB}/${TGZnew} -O ${INSTALL}/${TGZnew}
|
||||
tar xfz ${INSTALL}/${TGZnew} -C ${INSTALL}
|
||||
mv ${INSTALL}/go-${Vnew} ${INSTALL}/${Vnew}
|
||||
wget -q ${url}/${tgznew} -O ${path_new}
|
||||
if [[ "$(sha256sum ${path_new}|cut -d" " -f1)" != "${new_sum}" ]]; then
|
||||
echo "error: wrong checksum: ${path_new}">&2
|
||||
exit 1
|
||||
fi
|
||||
tar xfz ${path_new} -C ${install_dir}
|
||||
mv ${install_dir}/go-${new} ${go_dir}
|
||||
|
||||
export CGO_ENABLED=0
|
||||
|
||||
if [ ! -x "${bootstrap}/bin/go" ]; then
|
||||
if [[ ! -x "${bootstrap}/bin/go" ]]; then
|
||||
cd ${bootstrap}/src
|
||||
./make.bash &> /dev/null
|
||||
fi
|
||||
|
||||
export GOROOT_BOOTSTRAP=${bootstrap}
|
||||
|
||||
if [ "$(uname -m)" == "x86_64" ]; then
|
||||
export GOARCH=amd64
|
||||
else
|
||||
export GOARCH=386
|
||||
fi
|
||||
[[ "$(uname -m)" == "x86_64" ]] && export GOARCH=amd64 || export GOARCH=386
|
||||
|
||||
cd ${INSTALL}/${Vnew}/src
|
||||
cd ${go_dir}/src
|
||||
./make.bash &> /dev/null
|
||||
|
||||
rm -rf ${INSTALL}/go
|
||||
mv ${INSTALL}/${Vnew} ${INSTALL}/go
|
||||
#ln -s ${INSTALL}/go ${INSTALL}/${Vnew}
|
||||
|
||||
export GOROOT=${INSTALL}/go
|
||||
export GOROOT=${go_dir}
|
||||
export PATH=${PATH}:${GOROOT}/bin:~/go/bin
|
||||
|
||||
cat <<EOF
|
||||
|
|
@ -59,6 +65,7 @@ add this to your .bashrc/.profile:
|
|||
export CGO_ENABLED=${CGO_ENABLED}
|
||||
export GOPATH=~/go
|
||||
export GOROOT=${GOROOT}
|
||||
export GO111MODULE=on
|
||||
export PATH=\${PATH}:${GOROOT}:~/go/bin
|
||||
|
||||
EOF
|
||||
|
|
|
|||
12
mk_chroot.sh
12
mk_chroot.sh
|
|
@ -84,8 +84,8 @@ userinfo ${user} || useradd -L ${user} -g ${user} -d /var/empty -s /sbin/nologin
|
|||
|
||||
rsync -aR $(ldd ${bin}|tail -n+4|awk '{print $7}') ${chr}
|
||||
|
||||
daemon=$(basename ${bin})
|
||||
cat <<EOF> /etc/rc.d/${daemon}
|
||||
base=$(basename ${bin})
|
||||
cat <<EOF> /etc/rc.d/${base}
|
||||
#!/bin/sh
|
||||
|
||||
daemon="/usr/bin/env -i /usr/sbin/chroot -u ${user} -g ${group} ${chr}"
|
||||
|
|
@ -97,8 +97,8 @@ pexp="\${daemon_flags}"
|
|||
rc_cmd \$1
|
||||
EOF
|
||||
|
||||
chmod 0555 /etc/rc.d/${daemon}
|
||||
chmod 0555 /etc/rc.d/${base}
|
||||
|
||||
rcctl enable ${daemon}
|
||||
rcctl set ${daemon} flags "/bin/${daemon}"
|
||||
rcctl start ${daemon}
|
||||
rcctl enable ${base}
|
||||
rcctl set ${base} flags "/bin/${base}"
|
||||
rcctl start ${base}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#!/bin/sh
|
||||
|
||||
UNAME=$(uname)
|
||||
[ $(id -u) -ne 0 ] && { echo "error: this script must be run as root" 1>&2; exit 1; }
|
||||
[ $(id -u) -ne 0 ] && { echo "error: this script must be run as root">&2; exit 1; }
|
||||
|
||||
echo "warning: this script will disable ssh password authentication"
|
||||
echo -n "continue? [y/N] "
|
||||
|
|
@ -64,7 +64,7 @@ echo -n "enter your username "
|
|||
read user
|
||||
|
||||
if [ -z "${user}" ]; then
|
||||
echo "error: no user submitted" 1>&2
|
||||
echo "error: no user submitted">&2
|
||||
mv ${ssh_config}.bak ${ssh_config}
|
||||
exit 1
|
||||
fi
|
||||
|
|
@ -79,7 +79,7 @@ echo "paste your full ssh public key "
|
|||
read sshkey
|
||||
|
||||
if [ -z "${sshkey}" ]; then
|
||||
echo "error: no ssh key submitted" 1>&2
|
||||
echo "error: no ssh key submitted">&2
|
||||
mv ${ssh_config}.bak ${ssh_config}
|
||||
exit 1
|
||||
fi
|
||||
|
|
@ -101,7 +101,7 @@ case ${UNAME} in
|
|||
esac
|
||||
|
||||
if [ -z "$(ps aux -w | awk '/\/usr\/s?bin\/sshd/')" ]; then
|
||||
echo "error: ssh service failed to restart" 1>&2
|
||||
echo "please check for sshd config errors manually" 1>&2
|
||||
echo "error: ssh service failed to restart">&2
|
||||
echo "please check for sshd config errors manually">&2
|
||||
exit 1
|
||||
fi
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue