|
本帖最后由 feifenspace 于 2024-6-21 14:32 编辑
1、把代码保存为roonbridge-installer-linuxx64.sh
vi roonbridge-installer-linuxx64.sh
粘贴代码保存
2、确保你的脚本是正确的且具有执行权限。你可以使用以下命令来确保脚本具有执行权限:
chmod +x roonbridge-installer-linuxx64.sh
3、如果你想安装RoonBridge,请使用以下命令:
sudo ./roonbridge-installer-linuxx64.sh install
- #!/bin/bash
- # blow up on non-zero exit code
- set -e
- # these are replaced by build.sh
- PACKAGE_NAME=RoonBridge
- ARCH=x64
- PACKAGE_URL=https://download.roonlabs.net/builds/RoonBridge_linuxx64.tar.bz2
- PACKAGE_FILE=${PACKAGE_NAME}_linux${ARCH}.tar.bz2
- PACKAGE_NAME_LOWER=$(echo "$PACKAGE_NAME" | tr "[A-Z]" "[a-z]")
- TMPDIR=$(mktemp -d)
- MACHINE_ARCH=$(uname -m)
- OK=0
- CLEAN_EXIT=0
- # for colorization
- ESC_SEQ="\033["
- COL_RESET=$ESC_SEQ"39;49;00m"
- COL_RED=$ESC_SEQ"31;01m"
- COL_GREEN=$ESC_SEQ"32;01m"
- COL_YELLOW=$ESC_SEQ"33;01m"
- COL_BLUE=$ESC_SEQ"34;01m"
- COL_MAGENTA=$ESC_SEQ"35;01m"
- COL_CYAN=$ESC_SEQ"36;01m"
- COL_BOLD=$ESC_SEQ"1m"
- function hr {
- echo -e "${COL_BOLD}--------------------------------------------------------------------------------------${COL_RESET}"
- }
- function clean_up {
- rm -Rf $TMPDIR
- if [ x$CLEAN_EXIT != x1 ]; then
- echo ""
- hr
- echo ""
- echo -e "${COL_BOLD}${COL_RED}The $PACKAGE_NAME installer did not complete successfully.${COL_RESET}"
- echo ""
- echo "If you are not sure how to proceed, please check out:"
- echo ""
- echo " - Roon Labs Community https://community.roonlabs.com/c/support"
- echo " - Roon Labs Knowledge Base https://kb.roonlabs.com/LinuxInstall"
- echo ""
- hr
- echo ""
- fi
- }
- trap clean_up EXIT
- function install {
- #
- # Print banner/message
- #
- echo ""
- hr
- echo ""
- echo -e "${COL_BOLD}Welcome to the $PACKAGE_NAME installer${COL_RESET}"
- echo ""
- echo "This installer sets up $PACKAGE_NAME to run on linux with the following settings:"
- echo ""
- echo " - $PACKAGE_NAME will be installed in /opt/$PACKAGE_NAME"
- echo " - $PACKAGE_NAME's data will be stored in /var/roon/$PACKAGE_NAME"
- echo " - $PACKAGE_NAME will be configured to run as a system service"
- echo " - $PACKAGE_NAME will run as root"
- echo ""
- echo "These settings are suitable for turning a dedicated or semi-dedicated device"
- echo "into an appliance that runs $PACKAGE_NAME"
- echo ""
- echo "If you want customize how $PACKAGE_NAME is installed, see:"
- echo ""
- echo " http://kb.roonlabs.com/LinuxInstall"
- echo ""
- hr
- echo ""
- #
- # Check for linux (in case someone runs on OS X, Cygwin, BSD, etc)
- #
- case $(uname -s) in
- Linux)
- ;;
- *)
- echo -e "${COL_RED}${COL_BOLD}Error:${COL_RESET} This package is intended for Linux platforms. It is not compatible with your machine. Exiting."
- exit 1
- ;;
- esac
- #
- # Check for proper architecture
- #
- case "$MACHINE_ARCH" in
- armv7*)
- if [ x$ARCH = xarmv7hf ]; then OK=1; fi
- ;;
- aarch64*)
- if [ x$ARCH = xarmv8 ]; then OK=1; fi
- if [ x$ARCH = xarmv7hf ]; then OK=1; fi
- ;;
- x86_64*)
- if [ x$ARCH = xx64 ]; then OK=1; fi
- ;;
- i686*)
- if [ x$ARCH = xx86 ]; then OK=1; fi
- ;;
- esac
- #
- # Check for root privileges
- #
- if [ x$UID != x0 ]; then
- echo ""
- echo -e "${COL_RED}${COL_BOLD}Error:${COL_RESET} This installer must be run with root privileges. Exiting."
- echo ""
- exit 2
- fi
- #
- # Check for curl (used for downloading files)
- #
- if ! command -v curl &> /dev/null
- then
- echo "curl could not be found, installing..."
- emerge --ask net-misc/curl
- fi
- #
- # Check for tar (used for extracting files)
- #
- if ! command -v tar &> /dev/null
- then
- echo "tar could not be found, installing..."
- emerge --ask app-arch/tar
- fi
- #
- # Check for proper architecture
- #
- if [ x$OK != x1 ]; then
- echo ""
- echo -e "${COL_RED}${COL_BOLD}Error:${COL_RESET} This package is intended for $ARCH platforms. It is not compatible with your machine. Exiting."
- echo ""
- exit 3
- fi
- function confirm_n {
- while true; do
- read -p "$1 [y/N] " yn
- case $yn in
- [Yy]* )
- break
- ;;
- "")
- CLEAN_EXIT=1
- echo ""
- echo "Ok. Exiting."
- echo ""
- exit 4
- ;;
- [Nn]* )
- CLEAN_EXIT=1
- echo ""
- echo "Ok. Exiting."
- echo ""
- exit 4
- ;;
- * ) echo "Please answer yes or no.";;
- esac
- done
- }
- function confirm {
- while true; do
- read -p "$1 [Y/n] " yn
- case $yn in
- "")
- break
- ;;
- [Yy]* )
- break
- ;;
- [Nn]* )
- CLEAN_EXIT=1
- echo ""
- echo "Ok. Exiting."
- echo ""
- exit 4
- ;;
- * ) echo "Please answer yes or no.";;
- esac
- done
- }
- #
- # Double-check with user that this is what they want
- #
- confirm "Do you want to install $PACKAGE_NAME on this machine?"
- echo ""
- echo "Downloading $PACKAGE_FILE to $TMPDIR/$PACKAGE_FILE"
- echo ""
- curl -L -# -o "$TMPDIR/$PACKAGE_FILE" "$PACKAGE_URL"
- echo ""
- echo -n "Unpacking ${PACKAGE_FILE}..."
- cd $TMPDIR
- tar xf "$PACKAGE_FILE"
- echo "Done"
- if [ ! -d "$TMPDIR/$PACKAGE_NAME" ]; then
- echo "Missing directory: $TMPDIR/$PACKAGE_NAME. This indicates a broken package."
- exit 5
- fi
- if [ ! -f "$TMPDIR/$PACKAGE_NAME/check.sh" ]; then
- echo "Missing $TMPDIR/$PACKAGE_NAME/check.sh. This indicates a broken package."
- exit 5
- fi
- $TMPDIR/$PACKAGE_NAME/check.sh
- if [ -e /opt/$PACKAGE_NAME ]; then
- hr
- echo ""
- echo -e "${COL_RED}${COL_BOLD}Warning:${COL_RESET} The /opt/$PACKAGE_NAME directory already exists."
- echo ""
- echo "This usually indicates that $PACKAGE_NAME was installed previously on this machine."
- echo ""
- confirm_n "Do you want to remove /opt/$PACKAGE_NAME and proceed with the install?"
- echo ""
- rm -rf /opt/$PACKAGE_NAME
- fi
- if [ -e /etc/systemd/system/$PACKAGE_NAME.service ]; then
- hr
- echo ""
- echo -e "${COL_RED}${COL_BOLD}Warning:${COL_RESET} The /etc/systemd/system/$PACKAGE_NAME.service file already exists."
- echo ""
- echo "This usually indicates that $PACKAGE_NAME was installed previously on this machine."
- echo ""
- confirm_n "Do you want to remove /etc/systemd/system/$PACKAGE_NAME.service and proceed with the install?"
- echo ""
- systemctl stop $PACKAGE_NAME || true
- rm -rf /etc/systemd/system/$PACKAGE_NAME.service
- systemctl daemon-reload
- fi
- if [ -e /etc/init.d/$PACKAGE_NAME ]; then
- hr
- echo ""
- echo -e "${COL_RED}${COL_BOLD}Warning:${COL_RESET} The /etc/init.d/$PACKAGE_NAME file already exists."
- echo ""
- echo "This usually indicates that $PACKAGE_NAME was installed previously on this machine."
- echo ""
- confirm_n "Do you want to remove /etc/init.d/$PACKAGE_NAME and proceed with the install?"
- echo ""
- /etc/init.d/$PACKAGE_NAME stop || true
- rm -rf /etc/init.d/$PACKAGE_NAME
- fi
- echo ""
- echo "Copying files to /opt/$PACKAGE_NAME..."
- cp -pR $TMPDIR/$PACKAGE_NAME /opt
- #
- # set up OpenRC service
- #
- SERVICE_FILE=/etc/init.d/${PACKAGE_NAME_LOWER}
- echo ""
- echo "Stopping service ${PACKAGE_NAME_LOWER} if it exists..."
- /etc/init.d/$PACKAGE_NAME_LOWER stop || true
- cat > $SERVICE_FILE << END_OPENRC
- #!/sbin/openrc-run
- name="${PACKAGE_NAME}"
- description="Roon Bridge Service"
- command="/opt/${PACKAGE_NAME}/start.sh"
- pidfile="/var/run/${PACKAGE_NAME_LOWER}.pid"
- command_background="yes"
- depend() {
- need net
- }
- END_OPENRC
- echo "wrote out OpenRC service file"
- chmod +x ${SERVICE_FILE}
- echo ""
- echo "Adding service ${PACKAGE_NAME_LOWER} to default runlevel..."
- rc-update add ${PACKAGE_NAME_LOWER} default
- echo ""
- echo "Starting service ${PACKAGE_NAME_LOWER}..."
- rc-service ${PACKAGE_NAME_LOWER} start
- echo "Service Started"
- CLEAN_EXIT=1
- echo ""
- hr
- echo ""
- echo -e "${COL_GREEN}${COL_BOLD}All Done!${COL_RESET}"
- echo ""
- echo "$PACKAGE_NAME has been installed and started."
- echo ""
- hr
- echo ""
- }
- function uninstall {
- #
- # Print banner/message
- #
- echo ""
- hr
- echo ""
- echo -e "${COL_BOLD}Welcome to the $PACKAGE_NAME uninstaller${COL_RESET}"
- echo ""
- hr
- echo ""
- #
- # Check for linux (in case someone runs on OS X, Cygwin, BSD, etc)
- #
- case $(uname -s) in
- Linux)
- ;;
- *)
- echo -e "${COL_RED}${COL_BOLD}Error:${COL_RESET} This package is intended for Linux platforms. It is not compatible with your machine. Exiting."
- exit 1
- ;;
- esac
- #
- # Check for proper architecture
- #
- case "$MACHINE_ARCH" in
- armv7*)
- if [ x$ARCH = xarmv7hf ]; then OK=1; fi
- ;;
- aarch64*)
- if [ x$ARCH = xarmv8 ]; then OK=1; fi
- if [ x$ARCH = xarmv7hf ]; then OK=1; fi
- ;;
- x86_64*)
- if [ x$ARCH = xx64 ]; then OK=1; fi
- ;;
- i686*)
- if [ x$ARCH = xx86 ]; then OK=1; fi
- ;;
- esac
- #
- # Check for root privileges
- #
- if [ x$UID != x0 ]; then
- echo ""
- echo -e "${COL_RED}${COL_BOLD}Error:${COL_RESET} This installer must be run with root privileges. Exiting."
- echo ""
- exit 2
- fi
- #
- # Check for proper architecture
- #
- if [ x$OK != x1 ]; then
- echo ""
- echo -e "${COL_RED}${COL_BOLD}Error:${COL_RESET} This package is intended for $ARCH platforms. It is not compatible with your machine. Exiting."
- echo ""
- exit 3
- fi
- function confirm_n {
- while true; do
- read -p "$1 [y/N] " yn
- case $yn in
- [Yy]* )
- break
- ;;
- "")
- CLEAN_EXIT=1
- echo ""
- echo "Ok. Exiting."
- echo ""
- exit 4
- ;;
- [Nn]* )
- CLEAN_EXIT=1
- echo ""
- echo "Ok. Exiting."
- echo ""
- exit 4
- ;;
- * ) echo "Please answer yes or no.";;
- esac
- done
- }
- function confirm {
- while true; do
- read -p "$1 [Y/n] " yn
- case $yn in
- "")
- break
- ;;
- [Yy]* )
- break
- ;;
- [Nn]* )
- CLEAN_EXIT=1
- echo ""
- echo "Ok. Exiting."
- echo ""
- exit 4
- ;;
- * ) echo "Please answer yes or no.";;
- esac
- done
- }
- #
- # Double-check with user that this is what they want
- #
- confirm "Do you want to uninstall $PACKAGE_NAME from this machine?"
- if [ -e /opt/$PACKAGE_NAME ]; then
- echo ""
- echo "Stopping service ${PACKAGE_NAME_LOWER} if it exists..."
- /etc/init.d/$PACKAGE_NAME_LOWER stop || true
- echo ""
- echo "Removing /opt/$PACKAGE_NAME..."
- rm -rf /opt/$PACKAGE_NAME
- fi
- if [ -e /etc/init.d/$PACKAGE_NAME_LOWER ]; then
- echo ""
- echo "Removing service ${PACKAGE_NAME_LOWER}..."
- rc-update del ${PACKAGE_NAME_LOWER} default || true
- rm -f /etc/init.d/${PACKAGE_NAME_LOWER}
- fi
- CLEAN_EXIT=1
- echo ""
- hr
- echo ""
- echo -e "${COL_GREEN}${COL_BOLD}All Done!${COL_RESET}"
- echo ""
- echo "$PACKAGE_NAME has been uninstalled."
- echo ""
- hr
- echo ""
- }
- if [[ "$1" == "install" ]]; then
- install
- elif [[ "$1" == "uninstall" ]]; then
- uninstall
- else
- echo "Usage: $0 [install|uninstall]"
- exit 1
- fi
复制代码
|
|