Refactor (#5733)
This commit is contained in:
parent
2cbf0f744f
commit
73f1c261ab
@ -28,12 +28,12 @@ function update_script() {
|
|||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
RELEASE=$(curl -fsSL https://api.github.com/repos/bitmagnet-io/bitmagnet/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
|
RELEASE=$(curl -fsSL https://api.github.com/repos/bitmagnet-io/bitmagnet/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
|
||||||
if [[ ! -f /opt/${APP}_version.txt ]] || [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]]; then
|
if [[ "${RELEASE}" != "$(cat ~/.bitmagnet 2>/dev/null)" ]] || [[ ! -f ~/.bitmagnet ]]; then
|
||||||
msg_info "Stopping Service"
|
msg_info "Stopping Service"
|
||||||
systemctl stop bitmagnet-web
|
systemctl stop bitmagnet-web
|
||||||
msg_ok "Stopped Service"
|
msg_ok "Stopped Service"
|
||||||
|
|
||||||
msg_info "Backing up database"
|
msg_info "Backing up data"
|
||||||
rm -f /tmp/backup.sql
|
rm -f /tmp/backup.sql
|
||||||
$STD sudo -u postgres pg_dump \
|
$STD sudo -u postgres pg_dump \
|
||||||
--column-inserts \
|
--column-inserts \
|
||||||
@ -56,31 +56,26 @@ function update_script() {
|
|||||||
bitmagnet \
|
bitmagnet \
|
||||||
>/tmp/backup.sql
|
>/tmp/backup.sql
|
||||||
mv /tmp/backup.sql /opt/
|
mv /tmp/backup.sql /opt/
|
||||||
msg_ok "Database backed up"
|
|
||||||
|
|
||||||
msg_info "Updating ${APP} to v${RELEASE}"
|
|
||||||
[ -f /opt/bitmagnet/.env ] && cp /opt/bitmagnet/.env /opt/
|
[ -f /opt/bitmagnet/.env ] && cp /opt/bitmagnet/.env /opt/
|
||||||
[ -f /opt/bitmagnet/config.yml ] && cp /opt/bitmagnet/config.yml /opt/
|
[ -f /opt/bitmagnet/config.yml ] && cp /opt/bitmagnet/config.yml /opt/
|
||||||
rm -rf /opt/bitmagnet/*
|
msg_ok "Data backed up"
|
||||||
temp_file=$(mktemp)
|
|
||||||
curl -fsSL "https://github.com/bitmagnet-io/bitmagnet/archive/refs/tags/v${RELEASE}.tar.gz" -o "$temp_file"
|
rm -rf /opt/bitmagnet
|
||||||
tar zxf "$temp_file" --strip-components=1 -C /opt/bitmagnet
|
fetch_and_deploy_gh_release "bitmagnet" "bitmagnet-io/bitmagnet"
|
||||||
|
|
||||||
|
msg_info "Updating ${APP} to v${RELEASE}"
|
||||||
cd /opt/bitmagnet
|
cd /opt/bitmagnet
|
||||||
VREL=v$RELEASE
|
VREL=v$RELEASE
|
||||||
$STD go build -ldflags "-s -w -X github.com/bitmagnet-io/bitmagnet/internal/version.GitTag=$VREL"
|
$STD go build -ldflags "-s -w -X github.com/bitmagnet-io/bitmagnet/internal/version.GitTag=$VREL"
|
||||||
chmod +x bitmagnet
|
chmod +x bitmagnet
|
||||||
[ -f "/opt/.env" ] && cp "/opt/.env" /opt/bitmagnet/
|
[ -f "/opt/.env" ] && cp "/opt/.env" /opt/bitmagnet/
|
||||||
[ -f "/opt/config.yml" ] && cp "/opt/config.yml" /opt/bitmagnet/
|
[ -f "/opt/config.yml" ] && cp "/opt/config.yml" /opt/bitmagnet/
|
||||||
echo "${RELEASE}" >/opt/${APP}_version.txt
|
|
||||||
msg_ok "Updated $APP to v${RELEASE}"
|
msg_ok "Updated $APP to v${RELEASE}"
|
||||||
|
|
||||||
msg_info "Starting Service"
|
msg_info "Starting Service"
|
||||||
systemctl start bitmagnet-web
|
systemctl start bitmagnet-web
|
||||||
msg_ok "Started Service"
|
msg_ok "Started Service"
|
||||||
|
|
||||||
msg_info "Cleaning up"
|
|
||||||
rm -f "$temp_file"
|
|
||||||
msg_ok "Cleaned"
|
|
||||||
msg_ok "Updated Successfully"
|
msg_ok "Updated Successfully"
|
||||||
else
|
else
|
||||||
msg_ok "No update required. ${APP} is already at v${RELEASE}"
|
msg_ok "No update required. ${APP} is already at v${RELEASE}"
|
||||||
|
@ -22,17 +22,10 @@ msg_ok "Installed Dependencies"
|
|||||||
|
|
||||||
PG_VERSION="16" setup_postgresql
|
PG_VERSION="16" setup_postgresql
|
||||||
setup_go
|
setup_go
|
||||||
|
fetch_and_deploy_gh_release "bitmagnet" "bitmagnet-io/bitmagnet"
|
||||||
RELEASE=$(curl -fsSL https://api.github.com/repos/bitmagnet-io/bitmagnet/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
|
RELEASE=$(curl -fsSL https://api.github.com/repos/bitmagnet-io/bitmagnet/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4) }')
|
||||||
|
|
||||||
msg_info "Installing bitmagnet v${RELEASE}"
|
msg_info "Setting up database"
|
||||||
mkdir -p /opt/bitmagnet
|
|
||||||
temp_file=$(mktemp)
|
|
||||||
curl -fsSL "https://github.com/bitmagnet-io/bitmagnet/archive/refs/tags/v${RELEASE}.tar.gz" -o "$temp_file"
|
|
||||||
tar zxf "$temp_file" --strip-components=1 -C /opt/bitmagnet
|
|
||||||
cd /opt/bitmagnet
|
|
||||||
VREL=v$RELEASE
|
|
||||||
$STD go build -ldflags "-s -w -X github.com/bitmagnet-io/bitmagnet/internal/version.GitTag=$VREL"
|
|
||||||
chmod +x bitmagnet
|
|
||||||
POSTGRES_PASSWORD=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | head -c13)
|
POSTGRES_PASSWORD=$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | head -c13)
|
||||||
$STD sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '$POSTGRES_PASSWORD';"
|
$STD sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '$POSTGRES_PASSWORD';"
|
||||||
$STD sudo -u postgres psql -c "CREATE DATABASE bitmagnet;"
|
$STD sudo -u postgres psql -c "CREATE DATABASE bitmagnet;"
|
||||||
@ -41,8 +34,14 @@ $STD sudo -u postgres psql -c "CREATE DATABASE bitmagnet;"
|
|||||||
echo ""
|
echo ""
|
||||||
echo "postgres user password: $POSTGRES_PASSWORD"
|
echo "postgres user password: $POSTGRES_PASSWORD"
|
||||||
} >>~/postgres.creds
|
} >>~/postgres.creds
|
||||||
echo "${RELEASE}" >/opt/bitmagnet_version.txt
|
msg_ok "Database set up"
|
||||||
msg_ok "Installed bitmagnet v${RELEASE}"
|
|
||||||
|
msg_info "Configuring bitmagnet v${RELEASE}"
|
||||||
|
cd /opt/bitmagnet
|
||||||
|
VREL=v$RELEASE
|
||||||
|
$STD go build -ldflags "-s -w -X github.com/bitmagnet-io/bitmagnet/internal/version.GitTag=$VREL"
|
||||||
|
chmod +x bitmagnet
|
||||||
|
msg_ok "Configured bitmagnet v${RELEASE}"
|
||||||
|
|
||||||
read -r -p "${TAB3}Enter your TMDB API key if you have one: " tmdbapikey
|
read -r -p "${TAB3}Enter your TMDB API key if you have one: " tmdbapikey
|
||||||
|
|
||||||
@ -72,7 +71,6 @@ motd_ssh
|
|||||||
customize
|
customize
|
||||||
|
|
||||||
msg_info "Cleaning up"
|
msg_info "Cleaning up"
|
||||||
rm -f "$temp_file"
|
|
||||||
$STD apt-get -y autoremove
|
$STD apt-get -y autoremove
|
||||||
$STD apt-get -y autoclean
|
$STD apt-get -y autoclean
|
||||||
msg_ok "Cleaned"
|
msg_ok "Cleaned"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user