-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add cleanup script for future uninstall modularization (#16)
- Loading branch information
Showing
8 changed files
with
192 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
build/scripts/migration/service.d/user-service/migration.list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
LEGACY_WITHOUT_VERSION v0.3.6 | ||
v0.3.5 v0.3.6 | ||
v0.3.5.1 v0.3.6 | ||
LEGACY_WITHOUT_VERSION https://github.com/IceWhaleTech/CasaOS-UserService/releases/download/v0.3.6/linux-${ARCH}-casaos-user-service-migration-tool-v0.3.6.tar.gz | ||
v0.3.5 https://github.com/IceWhaleTech/CasaOS-UserService/releases/download/v0.3.6/linux-${ARCH}-casaos-user-service-migration-tool-v0.3.6.tar.gz | ||
v0.3.5.1 https://github.com/IceWhaleTech/CasaOS-UserService/releases/download/v0.3.6/linux-${ARCH}-casaos-user-service-migration-tool-v0.3.6.tar.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
build/sysroot/usr/share/casaos/cleanup/script.d/02-cleanup-user-service.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
readonly APP_NAME_SHORT=user-service | ||
|
||
__get_setup_script_directory_by_os_release() { | ||
pushd "$(dirname "${BASH_SOURCE[0]}")/../service.d/${APP_NAME_SHORT}" &>/dev/null | ||
|
||
{ | ||
# shellcheck source=/dev/null | ||
{ | ||
source /etc/os-release | ||
{ | ||
pushd "${ID}"/"${VERSION_CODENAME}" &>/dev/null | ||
} || { | ||
pushd "${ID}" &>/dev/null | ||
} || { | ||
pushd "${ID_LIKE}" &>/dev/null | ||
} || { | ||
echo "Unsupported OS: ${ID} ${VERSION_CODENAME} (${ID_LIKE})" | ||
exit 1 | ||
} | ||
|
||
pwd | ||
|
||
popd &>/dev/null | ||
|
||
} || { | ||
echo "Unsupported OS: unknown" | ||
exit 1 | ||
} | ||
|
||
} | ||
|
||
popd &>/dev/null | ||
} | ||
|
||
SETUP_SCRIPT_DIRECTORY=$(__get_setup_script_directory_by_os_release) | ||
|
||
readonly SETUP_SCRIPT_DIRECTORY | ||
readonly SETUP_SCRIPT_FILENAME="cleanup-${APP_NAME_SHORT}.sh" | ||
readonly SETUP_SCRIPT_FILEPATH="${SETUP_SCRIPT_DIRECTORY}/${SETUP_SCRIPT_FILENAME}" | ||
|
||
echo "🟩 Running ${SETUP_SCRIPT_FILENAME}..." | ||
$SHELL "${SETUP_SCRIPT_FILEPATH}" "${BUILD_PATH}" |
1 change: 1 addition & 0 deletions
1
...t/usr/share/casaos/cleanup/service.d/user-service/debian/bullseye/cleanup-user-service.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../cleanup-user-service.sh |
109 changes: 109 additions & 0 deletions
109
build/sysroot/usr/share/casaos/cleanup/service.d/user-service/debian/cleanup-user-service.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
readonly CASA_EXEC=casaos-user-service | ||
readonly CASA_SERVICE=casaos-user-service.service | ||
|
||
CASA_SERVICE_PATH=$(systemctl show ${CASA_SERVICE} --no-pager --property FragmentPath | cut -d'=' -sf2) | ||
readonly CASA_SERVICE_PATH | ||
|
||
CASA_CONF=$( grep -i ExecStart= "${CASA_SERVICE_PATH}" | cut -d'=' -sf2 | cut -d' ' -sf3) | ||
if [[ -z "${CASA_CONF}" ]]; then | ||
CASA_CONF=/etc/casaos/user-service.conf | ||
fi | ||
|
||
CASA_DB_PATH=$( (grep -i dbpath "${CASA_CONF}" || echo "/var/lib/casaos/db") | cut -d'=' -sf2 | xargs ) | ||
readonly CASA_DB_PATH | ||
|
||
CASA_DB_FILE=${CASA_DB_PATH}/user-service.db | ||
|
||
readonly aCOLOUR=( | ||
'\e[38;5;154m' # green | Lines, bullets and separators | ||
'\e[1m' # Bold white | Main descriptions | ||
'\e[90m' # Grey | Credits | ||
'\e[91m' # Red | Update notifications Alert | ||
'\e[33m' # Yellow | Emphasis | ||
) | ||
|
||
Show() { | ||
# OK | ||
if (($1 == 0)); then | ||
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[0]} OK $COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2" | ||
# FAILED | ||
elif (($1 == 1)); then | ||
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[3]}FAILED$COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2" | ||
# INFO | ||
elif (($1 == 2)); then | ||
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[0]} INFO $COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2" | ||
# NOTICE | ||
elif (($1 == 3)); then | ||
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[4]}NOTICE$COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2" | ||
fi | ||
} | ||
|
||
Warn() { | ||
echo -e "${aCOLOUR[3]}$1$COLOUR_RESET" | ||
} | ||
|
||
trap 'onCtrlC' INT | ||
onCtrlC() { | ||
echo -e "${COLOUR_RESET}" | ||
exit 1 | ||
} | ||
|
||
if [[ ! -x "$(command -v ${CASA_EXEC})" ]]; then | ||
Show 2 "${CASA_EXEC} is not detected, exit the script." | ||
exit 1 | ||
fi | ||
|
||
while true; do | ||
echo -n -e " ${aCOLOUR[4]}Do you want delete user database? Y/n :${COLOUR_RESET}" | ||
read -r input | ||
case $input in | ||
[yY][eE][sS] | [yY]) | ||
REMOVE_USER_DATABASE=true | ||
break | ||
;; | ||
[nN][oO] | [nN]) | ||
REMOVE_USER_DATABASE=false | ||
break | ||
;; | ||
*) | ||
echo -e " ${aCOLOUR[3]}Invalid input, please try again.${COLOUR_RESET}" | ||
;; | ||
esac | ||
done | ||
|
||
while true; do | ||
echo -n -e " ${aCOLOUR[4]}Do you want delete user directory? Y/n :${COLOUR_RESET}" | ||
read -r input | ||
case $input in | ||
[yY][eE][sS] | [yY]) | ||
REMOVE_USER_DIRECTORY=true | ||
break | ||
;; | ||
[nN][oO] | [nN]) | ||
REMOVE_USER_DIRECTORY=false | ||
break | ||
;; | ||
*) | ||
echo -e " ${aCOLOUR[3]}Invalid input, please try again.${COLOUR_RESET}" | ||
;; | ||
esac | ||
done | ||
|
||
Show 2 "Stopping ${CASA_SERVICE}..." | ||
systemctl disable --now "${CASA_SERVICE}" || Show 3 "Failed to disable ${CASA_SERVICE}" | ||
|
||
rm -rvf "$(which ${CASA_EXEC})" || Show 3 "Failed to remove ${CASA_EXEC}" | ||
rm -rvf "${CASA_CONF}" || Show 3 "Failed to remove ${CASA_CONF}" | ||
|
||
if [[ "${REMOVE_USER_DATABASE}" == true ]]; then | ||
rm -rvf "${CASA_DB_FILE}" || Show 3 "Failed to remove ${CASA_DB_FILE}" | ||
fi | ||
|
||
if [[ "${REMOVE_USER_DIRECTORY}" == true ]]; then | ||
Show 2 "Removing user directories..." | ||
rm -rvf /var/lib/casaos/[1-9]* | ||
fi |
1 change: 1 addition & 0 deletions
1
build/sysroot/usr/share/casaos/cleanup/service.d/user-service/ubuntu/cleanup-user-service.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../debian/cleanup-user-service.sh |
1 change: 1 addition & 0 deletions
1
...root/usr/share/casaos/cleanup/service.d/user-service/ubuntu/jammy/cleanup-user-service.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../debian/bullseye/cleanup-user-service.sh |