Skip to content

Instantly share code, notes, and snippets.

Created May 11, 2017 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/ae925b7c083f51ddcc33d2a93164db8d to your computer and use it in GitHub Desktop.
Save anonymous/ae925b7c083f51ddcc33d2a93164db8d to your computer and use it in GitHub Desktop.
Jolla Phone retail store demo scripts
#!/bin/sh
# Contact: Pekka Lundstrom <pekka.lundstrom@jollamobile.com>
#
# Copyright (c) 2013, Jolla Ltd.
# All rights reserved.
#
# This will check if it is time to run factory clear
# Check happens once per hour and if time is 02
# we do the clean
HRS=$(date +%H)
# We accept both 2am and 3am because we might have been in suspend
# state full hour. Start script holds boot checking 2 hours after
# clear so we won't come back here at 3 am if clear was done at 2 am.
if [ $HRS -ne 2 -a $HRS -ne 3 ]; then
exit 0
fi
# It is time to start clean
# Use preinit oneshot to do the job
add-preinit-oneshot /usr/sbin/clear-store-phone
sync
dsmetool -b
sleep 30
# If dsme reboot didn't work, reboot manually
reboot -f &
sleep 30
# this should never happen
echo b > /proc/sysrq-trigger
[Unit]
Description=Run factory clear to the phone
[Service]
Type=oneshot
RemainAfterExit=no
ExecStart=/usr/sbin/check-store-clear
[Unit]
Description=Check Daily Cleanup
[Timer]
OnBootSec=2h
OnUnitActiveSec=1h
[Install]
WantedBy=graphical.target actdead.target
#!/bin/sh
# Contact: Pekka Lundstrom <pekka.lundstrom@jollamobile.com>
#
# Copyright (c) 2013, Jolla Ltd.
# All rights reserved.
#
# This will forcefully clear the phone to factory settings and
# sw rolls back to factory release
echo_g()
{
[ -r /proc/uptime ] && read uptime idletime < /proc/uptime
echo "clear: ($uptime) $@"
}
# ===== main =====
echo_g "Phone clear started"
export PATH=/sbin:/usr/sbin:/bin:/usr/bin
# Find root
ROOT=$(grep "/dev/mmc.* / " /proc/mounts | cut -d " " -f1)
[ -z "$ROOT" ] && echo_g "Root not found??" && exit 1
# We have RO filesystem. Make it RW
mount -o subvolid=0 $ROOT /mnt/ || { echo_g "Cant mount /mnt" && exit 1; }
cd /mnt/
# Clean root
mv @ @_old
btrfs subvolume snapshot factory-\@ @
ROOTFS_ID=$(btrfs subvolume list . | grep " @$" | cut -d " " -f2)
btrfs subvolume set-default $ROOTFS_ID @
# Clean /home
btrfs subvolume delete @home
btrfs subvolume snapshot factory-\@home @home
# Mark cleanup
# Note, do not change name nor path for this. It must be backward compatible
touch @/.cleanup-needed
btrfs filesystem sync .
sync
cd /
umount /mnt
echo_g "Store clear done"
# preinit will do reboot
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment