Skip to content

Commit 970e1f3

Browse files
author
Andreas Poulsen
committed
Merge branch 'feature/56299_more_language_variability_in_scripts' into 'master'
More language variability in scripts See merge request os2borgerpc/os2borgerpc-scripts!219
2 parents a772e00 + 7f1815f commit 970e1f3

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

common/system/on_off_schedule_remove.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ if ! get_os2borgerpc_config os2_product | grep --quiet kiosk; then
3333
USERCRON=/tmp/usercron
3434
crontab -u user -l > $USERCRON
3535
if [ -f $USERCRON ]; then
36-
sed --in-place "/lukker/d" $USERCRON
36+
sed --in-place "/zenity/d" $USERCRON
3737
crontab -u user $USERCRON
3838
fi
3939
rm --force $USERCRON

common/system/on_off_schedule_set.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ import os
147147
148148
FILE = "$WAKE_PLAN_FILE" # "/etc/os2borgerpc/" + "$PLAN_NAME"
149149
MODE = "$MODE".lower()
150+
LOCALE_FILE = "/etc/default/locale"
150151
151152
def check_weekday(plan, date):
152153
"""Helper method that returns the week plan settings for the week day
@@ -318,7 +319,17 @@ def main():
318319
319320
# Check the product type and add a notification 5 minutes before shutdown on OS2BorgerPC machines
320321
if plan['product'] == 'os2borgerpc':
321-
MESSAGE = 'ADVARSEL: Denne computer lukker ned om fem minutter'
322+
# Set the notification text based on the chosen language
323+
locale = "None"
324+
if os.path.exists(LOCALE_FILE):
325+
with open(LOCALE_FILE, "r") as file:
326+
locale = file.read()
327+
if 'LANG=sv' in locale or 'LANG="sv' in locale:
328+
MESSAGE = 'VARNING: Den här datorn stängs av om fem minuter'
329+
elif 'LANG=en' in locale or 'LANG="en' in locale:
330+
MESSAGE = 'WARNING: This computer will shut down in five minutes'
331+
else:
332+
MESSAGE = 'ADVARSEL: Denne computer lukker ned om fem minutter'
322333
# Find the time 5 minutes before shutdown
323334
notify_time = shutdown - datetime.timedelta(minutes=5)
324335
# Get current entries
@@ -330,7 +341,7 @@ def main():
330341
cronentries = cronfile.readlines()
331342
with open(USERCRON, 'w') as cronfile:
332343
for entry in cronentries:
333-
if "lukker" not in entry:
344+
if "zenity" not in entry and "notify-send" not in entry:
334345
cronfile.write(entry)
335346
# Add notification for next shutdown
336347
with open(USERCRON, 'a') as cronfile:

common/system/shutdown_and_wakeup.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@ fi
3939

4040
ROOTCRON_TMP=/tmp/oldcron
4141
USERCRON_TMP=/tmp/usercron
42-
MESSAGE="Denne computer lukker ned om fem minutter"
42+
if grep "LANG=" /etc/default/locale | grep "sv"; then
43+
MESSAGE="Den här datorn stängs av om fem minuter"
44+
elif grep "LANG=" /etc/default/locale | grep "en"; then
45+
MESSAGE="This computer will shut down in five minutes"
46+
else
47+
MESSAGE="Denne computer lukker ned om fem minutter"
48+
fi
4349

4450
mkdir --parents "$(dirname $SCHEDULED_OFF_SCRIPT)"
4551

@@ -49,7 +55,7 @@ crontab -u user -l > $USERCRON_TMP
4955

5056
# Delete current crontab entries related to this script AND shutdown_at_time
5157
sed --in-place --expression "/rtcwake/d" --expression "/scheduled_off/d" --expression "/shutdown/d" $ROOTCRON_TMP
52-
sed --in-place "/lukker/d" $USERCRON_TMP
58+
sed --in-place "/notify-send/d" $USERCRON_TMP
5359

5460
if [ "$1" == "--off" ]; then
5561
rm --force $SCHEDULED_OFF_SCRIPT

common/system/shutdown_at_time.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,21 @@ fi
3030

3131
ROOTCRON_TMP=/tmp/oldcron
3232
USERCRON_TMP=/tmp/usercron
33-
MESSAGE="Denne computer lukker ned om fem minutter"
33+
if grep "LANG=" /etc/default/locale | grep "sv"; then
34+
MESSAGE="Den här datorn stängs av om fem minuter"
35+
elif grep "LANG=" /etc/default/locale | grep "en"; then
36+
MESSAGE="This computer will shut down in five minutes"
37+
else
38+
MESSAGE="Denne computer lukker ned om fem minutter"
39+
fi
3440

3541
# Read and save current cron settings first
3642
crontab -l > $ROOTCRON_TMP
3743
crontab -u user -l > $USERCRON_TMP
3844

3945
# Delete current crontab entries related to this script AND shutdown_and_wakeup.sh
4046
sed --in-place --expression "/shutdown/d" --expression "/rtcwake/d" --expression "/scheduled_off/d" $ROOTCRON_TMP
41-
sed --in-place "/lukker/d" $USERCRON_TMP
47+
sed --in-place "/notify-send/d" $USERCRON_TMP
4248

4349
# If not called with --off: Determine the new crontab contents
4450
if [ "$1" != "--off" ]; then

0 commit comments

Comments
 (0)