install script
This commit is contained in:
parent
80cf65e379
commit
f280156e8a
2 changed files with 45 additions and 23 deletions
5
Makefile
5
Makefile
|
@ -4,12 +4,13 @@ INSTALLER=dist/installer.sh
|
||||||
all: $(INSTALLER)
|
all: $(INSTALLER)
|
||||||
|
|
||||||
$(BINARY): version.go
|
$(BINARY): version.go
|
||||||
GOARCH=arm go build -ldflags="-w -s" -trimpath -o $(BINARY)
|
GOARCH=arm GOARM=7 go build -ldflags="-w -s" -o $(BINARY)
|
||||||
version.go:
|
version.go:
|
||||||
go generate
|
go generate
|
||||||
|
|
||||||
$(INSTALLER): $(BINARY) scripts/installer.sh
|
$(INSTALLER): $(BINARY) scripts/installer.sh
|
||||||
cp scripts/install.sh $@
|
cp scripts/installer.sh $@
|
||||||
gzip -c $(BINARY) >> $@
|
gzip -c $(BINARY) >> $@
|
||||||
|
chmod +x $@
|
||||||
clean:
|
clean:
|
||||||
rm -fr dist
|
rm -fr dist
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
SERVICE_NAME=proxy
|
set -e
|
||||||
|
|
||||||
|
UNIT_NAME=proxy
|
||||||
|
BINARY=rmfake-proxy
|
||||||
DESTINATION="/home/root/rmfakecloud"
|
DESTINATION="/home/root/rmfakecloud"
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "rmfakecloud proxy installer"
|
echo "rmFakeCloud proxy installer"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,10 +15,11 @@ echo ""
|
||||||
|
|
||||||
function unpack(){
|
function unpack(){
|
||||||
mkdir -p ${DESTINATION}
|
mkdir -p ${DESTINATION}
|
||||||
systemctl stop proxy || true
|
systemctl stop ${UNIT_NAME} || true
|
||||||
# Find __ARCHIVE__ maker, read archive content and decompress it
|
# Find __ARCHIVE__ maker, read archive content and decompress it
|
||||||
ARCHIVE=$(awk '/^__ARCHIVE__/ {print NR + 1; exit 0; }' "${0}")
|
ARCHIVE=$(awk '/^__ARCHIVE__/ {print NR + 1; exit 0; }' "${0}")
|
||||||
tail -n+${ARCHIVE} "${0}" | gunzip > ${DESTINATION}/${SERVICE_NAME}
|
tail -n+${ARCHIVE} "${0}" | gunzip > ${DESTINATION}/${BINARY}
|
||||||
|
chmod +x ${DESTINATION}/${BINARY}
|
||||||
}
|
}
|
||||||
|
|
||||||
# marks all as unsynced so that they are not deleted
|
# marks all as unsynced so that they are not deleted
|
||||||
|
@ -30,7 +34,7 @@ workdir=$DESTINATION
|
||||||
cat > $workdir/proxy.cfg <<EOF
|
cat > $workdir/proxy.cfg <<EOF
|
||||||
URL=
|
URL=
|
||||||
EOF
|
EOF
|
||||||
cat > /etc/systemd/system/proxy.service <<EOF
|
cat > /etc/systemd/system/${UNIT_NAME}.service <<EOF
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=reverse proxy
|
Description=reverse proxy
|
||||||
#StartLimitIntervalSec=600
|
#StartLimitIntervalSec=600
|
||||||
|
@ -41,30 +45,33 @@ After=home.mount
|
||||||
Environment=HOME=/home/root
|
Environment=HOME=/home/root
|
||||||
#EnvironmentFile=$workdir/proxy.cfg
|
#EnvironmentFile=$workdir/proxy.cfg
|
||||||
WorkingDirectory=$workdir
|
WorkingDirectory=$workdir
|
||||||
ExecStart=$workdir/${SERVICE_NAME} -cert $workdir/proxy.crt -key $workdir/proxy.key ${cloudurl}
|
ExecStart=$workdir/${BINARY} -cert $workdir/proxy.crt -key $workdir/proxy.key ${cloudurl}
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
EOF
|
EOF
|
||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
systemctl enable ${SERVICE_NAME}
|
systemctl enable ${UNIT_NAME}
|
||||||
systemctl restart ${SERVICE_NAME}
|
systemctl restart ${UNIT_NAME}
|
||||||
}
|
}
|
||||||
|
|
||||||
function uninstall(){
|
function uninstall(){
|
||||||
systemctl stop ${SERVICE_NAME}
|
systemctl stop ${UNIT_NAME}
|
||||||
systemctl disable ${SERVICE_NAME}
|
systemctl disable ${UNIT_NAME}
|
||||||
rm proxy.key proxy.crt ca.crt ca.srl ca.key proxy.pubkey proxy.csr csr.conf proxy.cfg
|
#rm proxy.key proxy.crt ca.crt ca.srl ca.key proxy.pubkey proxy.csr csr.conf proxy.cfg
|
||||||
rm /usr/local/share/ca-certificates/ca.crt
|
rm /usr/local/share/ca-certificates/ca.crt
|
||||||
|
update-ca-certificates --fresh
|
||||||
rm /etc/systemd/system/proxy.service
|
rm /etc/systemd/system/proxy.service
|
||||||
sed -i '/# rmfake_start/,/# rmfake_end/d' /etc/hosts
|
sed -i '/# rmfake_start/,/# rmfake_end/d' /etc/hosts
|
||||||
echo "Marking files as not synced to prevent data loss"
|
echo "Marking files as not synced to prevent data loss"
|
||||||
fixsync
|
fixsync
|
||||||
|
rm -fr $DESTINATION
|
||||||
echo "You can restart xochitl now"
|
echo "You can restart xochitl now"
|
||||||
}
|
}
|
||||||
|
|
||||||
function generate_certificates(){
|
function generate_certificates(){
|
||||||
# thanks to https://gist.github.com/Soarez/9688998
|
# thanks to https://gist.github.com/Soarez/9688998
|
||||||
|
pushd $DESTINATION
|
||||||
|
|
||||||
cat <<EOF > csr.conf
|
cat <<EOF > csr.conf
|
||||||
[ req ]
|
[ req ]
|
||||||
|
@ -140,8 +147,9 @@ if [ ! -f proxy.crt ]; then
|
||||||
else
|
else
|
||||||
echo "crt exists"
|
echo "crt exists"
|
||||||
fi
|
fi
|
||||||
|
popd
|
||||||
}
|
}
|
||||||
# Put your logic here (if you need)
|
|
||||||
function install_certificates(){
|
function install_certificates(){
|
||||||
certdir="/usr/local/share/ca-certificates"
|
certdir="/usr/local/share/ca-certificates"
|
||||||
certname=$certdir/ca.crt
|
certname=$certdir/ca.crt
|
||||||
|
@ -151,7 +159,7 @@ function install_certificates(){
|
||||||
update-ca-certificates --fresh
|
update-ca-certificates --fresh
|
||||||
fi
|
fi
|
||||||
mkdir -p $certdir
|
mkdir -p $certdir
|
||||||
cp ca.crt $certdir/
|
cp $DESTINATION/ca.crt $certdir/
|
||||||
update-ca-certificates --fresh
|
update-ca-certificates --fresh
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,23 +177,24 @@ EOF
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getproxy(){
|
||||||
|
read -p "Enter your own cloud url: " url
|
||||||
|
echo $url
|
||||||
|
}
|
||||||
|
|
||||||
function doinstall(){
|
function doinstall(){
|
||||||
unpack
|
unpack
|
||||||
generate_certificates
|
generate_certificates
|
||||||
install_certificates
|
install_certificates
|
||||||
# install proxy
|
# install proxy
|
||||||
url=getproxy
|
url=$(getproxy)
|
||||||
installproxy.sh $url
|
install_proxyservice $url
|
||||||
patch_hosts
|
patch_hosts
|
||||||
systemctl stop xochitl
|
systemctl stop xochitl
|
||||||
fixsync
|
fixsync
|
||||||
systemctl start xochitl
|
systemctl start xochitl
|
||||||
}
|
}
|
||||||
|
|
||||||
function getproxy(){
|
|
||||||
read -p "Enter your own cloud url: " url
|
|
||||||
echo $url
|
|
||||||
}
|
|
||||||
|
|
||||||
case $1 in
|
case $1 in
|
||||||
"uninstall" )
|
"uninstall" )
|
||||||
|
@ -202,11 +211,23 @@ case $1 in
|
||||||
if [ $# -lt 1 ]; then
|
if [ $# -lt 1 ]; then
|
||||||
url=$(getproxy)
|
url=$(getproxy)
|
||||||
fi
|
fi
|
||||||
echo $url
|
install_proxyservice $url
|
||||||
;;
|
;;
|
||||||
|
|
||||||
* )
|
* )
|
||||||
echo "params"
|
cat <<EOF
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
install
|
||||||
|
installs
|
||||||
|
|
||||||
|
uninstall
|
||||||
|
uninstall
|
||||||
|
|
||||||
|
setproxy [cloudurl]
|
||||||
|
changes the cloud address to
|
||||||
|
|
||||||
|
EOF
|
||||||
;;
|
;;
|
||||||
|
|
||||||
esac
|
esac
|
||||||
|
|
Loading…
Add table
Reference in a new issue