Skip to content

Commit 9072459

Browse files
authored
Refactor (#5724)
1 parent c2f9737 commit 9072459

File tree

2 files changed

+38
-47
lines changed

2 files changed

+38
-47
lines changed

ct/cryptpad.sh

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,48 +20,46 @@ color
2020
catch_errors
2121

2222
function update_script() {
23-
header_info
24-
check_container_storage
25-
check_container_resources
23+
header_info
24+
check_container_storage
25+
check_container_resources
2626

27-
if [[ ! -d "/opt/cryptpad" ]]; then
28-
msg_error "No ${APP} Installation Found!"
29-
exit
30-
fi
31-
RELEASE=$(curl -fsSL https://api.github.com/repos/cryptpad/cryptpad/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }')
32-
if [[ "${RELEASE}" != "$(cat /opt/${APP}_version.txt)" ]] || [[ ! -f /opt/${APP}_version.txt ]]; then
33-
msg_info "Stopping $APP"
34-
systemctl stop cryptpad
35-
msg_ok "Stopped $APP"
27+
if [[ ! -d "/opt/cryptpad" ]]; then
28+
msg_error "No ${APP} Installation Found!"
29+
exit
30+
fi
31+
RELEASE=$(curl -fsSL https://api.github.com/repos/cryptpad/cryptpad/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }')
32+
if [[ "${RELEASE}" != "$(cat ~/.cryptpad 2>/dev/null)" ]] || [[ ! -f ~/.cryptpad ]]; then
33+
msg_info "Stopping $APP"
34+
systemctl stop cryptpad
35+
msg_ok "Stopped $APP"
3636

37-
msg_info "Updating $APP to ${RELEASE}"
38-
temp_dir=$(mktemp -d)
39-
cp -f /opt/cryptpad/config/config.js /opt/config.js
40-
curl -fsSL "https://github.com/cryptpad/cryptpad/archive/refs/tags/${RELEASE}.tar.gz" -o "$temp_dir/cryptpad-${RELEASE}.tar.gz"
41-
cd "$temp_dir"
42-
tar zxf "cryptpad-${RELEASE}.tar.gz"
43-
cp -rf "cryptpad-${RELEASE}"/* /opt/cryptpad
44-
cd /opt/cryptpad
45-
$STD npm ci
46-
$STD npm run install:components
47-
$STD npm run build
48-
cp -f /opt/config.js /opt/cryptpad/config/config.js
49-
echo "${RELEASE}" >/opt/${APP}_version.txt
50-
msg_ok "Updated $APP to ${RELEASE}"
37+
msg_info "Backing up configuration"
38+
[ -f /opt/cryptpad/config/config.js ] && mv /opt/cryptpad/config/config.js /opt/
39+
msg_ok "Backed up configuration"
5140

52-
msg_info "Cleaning Up"
53-
rm -rf $temp_dir
54-
msg_ok "Cleanup Completed"
41+
fetch_and_deploy_gh_release "cryptpad" "cryptpad/cryptpad"
5542

56-
msg_info "Starting $APP"
57-
systemctl start cryptpad
58-
msg_ok "Started $APP"
43+
msg_info "Updating $APP to ${RELEASE}"
44+
cd /opt/cryptpad
45+
$STD npm ci
46+
$STD npm run install:components
47+
$STD npm run build
48+
msg_ok "Updated $APP to ${RELEASE}"
5949

60-
msg_ok "Update Successful"
61-
else
62-
msg_ok "No update required. ${APP} is already at ${RELEASE}"
63-
fi
64-
exit
50+
msg_info "Restoring configuration"
51+
mv /opt/config.js /opt/cryptpad/config/
52+
msg_ok "Configuration restored"
53+
54+
msg_info "Starting $APP"
55+
systemctl start cryptpad
56+
msg_ok "Started $APP"
57+
58+
msg_ok "Update Successful"
59+
else
60+
msg_ok "No update required. ${APP} is already at ${RELEASE}"
61+
fi
62+
exit
6563
}
6664

6765
start

install/cryptpad-install.sh

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,15 @@ network_check
1414
update_os
1515

1616
msg_info "Installing Dependencies"
17-
$STD apt-get install -y \
18-
git
17+
$STD apt-get install -y git
1918
msg_ok "Installed Dependencies"
2019

2120
NODE_VERSION="22" setup_nodejs
2221

23-
read -p "${TAB3}Install OnlyOffice components instead of CKEditor? (Y/N): " onlyoffice
22+
read -rp "${TAB3}Install OnlyOffice components instead of CKEditor? (Y/N): " onlyoffice
23+
fetch_and_deploy_gh_release "cryptpad" "cryptpad/cryptpad"
2424

2525
msg_info "Setup ${APPLICATION}"
26-
temp_file=$(mktemp)
27-
RELEASE=$(curl -fsSL https://api.github.com/repos/cryptpad/cryptpad/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3) }')
28-
curl -fsSL "https://github.com/cryptpad/cryptpad/archive/refs/tags/${RELEASE}.tar.gz" -o "$temp_file"
29-
tar zxf $temp_file
30-
mv cryptpad-$RELEASE /opt/cryptpad
3126
cd /opt/cryptpad
3227
$STD npm ci
3328
$STD npm run install:components
@@ -39,7 +34,6 @@ sed -i "80s#//httpAddress: 'localhost'#httpAddress: '0.0.0.0'#g" /opt/cryptpad/c
3934
if [[ "$onlyoffice" =~ ^[Yy]$ ]]; then
4035
$STD bash -c "./install-onlyoffice.sh --accept-license"
4136
fi
42-
echo "${RELEASE}" >/opt/${APPLICATION}_version.txt
4337
msg_ok "Setup ${APPLICATION}"
4438

4539
msg_info "Creating Service"
@@ -69,7 +63,6 @@ motd_ssh
6963
customize
7064

7165
msg_info "Cleaning up"
72-
rm -f $temp_file
7366
$STD apt-get -y autoremove
7467
$STD apt-get -y autoclean
7568
msg_ok "Cleaned"

0 commit comments

Comments
 (0)