Skip to content

Commit

Permalink
update beyond 5.2.4 fscrypt v1 to v2
Browse files Browse the repository at this point in the history
  • Loading branch information
bkauler committed May 3, 2023
1 parent 24c4895 commit 73d89bd
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 1 deletion.
23 changes: 22 additions & 1 deletion easyos/easy-code/boot/initrd-tree/init
Expand Up @@ -159,6 +159,7 @@
#20230429 fix workingdir when mount overlay fs. /build-choices has EOS_ variables.
#20230429 /build-choices has EOS_FSCRYPT_VER value 1 or 2
#20230430 64 byte hash generated from password.
#20230503 fscrypt v1 to v2 update.

#20230429
. /build-choices #3buildeasydistro copies it here.
Expand Down Expand Up @@ -1114,6 +1115,18 @@ if [ $SFchk -eq 1 ];then #20210524 20210526
fi
fi
fi

#20230503 fscrypt v1 to v2 update...
if [ -d /mnt/${WKG_DEV}/${WKG_DIR}v1tov2 ];then #created by easy-update script.
rm -rf /mnt/${WKG_DEV}/${WKG_DIR}containers
rm -rf /mnt/${WKG_DEV}/${WKG_DIR}files
rm -rf /mnt/${WKG_DEV}/${WKG_DIR}releases
rm -rf /mnt/${WKG_DEV}/${WKG_DIR}.session
rm -rf /mnt/${WKG_DEV}/${WKG_DIR}data
rm -rf /mnt/${WKG_DEV}/${WKG_DIR}.tempwork
sync
fi

if [ ! -d /mnt/${WKG_DEV}/${WKG_DIR}.session ];then
for aDIR in containers releases files sfs .tempwork data #sanity check 20210919 20211212
do
Expand All @@ -1123,7 +1136,7 @@ if [ ! -d /mnt/${WKG_DEV}/${WKG_DIR}.session ];then
[ "$EOS_SUPPORT_CONTAINERS" != "0" ] && mkdir /mnt/${WKG_DEV}/${WKG_DIR}containers
mkdir /mnt/${WKG_DEV}/${WKG_DIR}releases
mkdir /mnt/${WKG_DEV}/${WKG_DIR}files
mkdir /mnt/${WKG_DEV}/${WKG_DIR}sfs
mkdir -p /mnt/${WKG_DEV}/${WKG_DIR}sfs
mkdir /mnt/${WKG_DEV}/${WKG_DIR}.session
mkdir /mnt/${WKG_DEV}/${WKG_DIR}.tempwork
mkdir /mnt/${WKG_DEV}/${WKG_DIR}data #20211212
Expand Down Expand Up @@ -1233,6 +1246,14 @@ ${S133}\\033[0;39m" #red.
cp -a -f /skeleton/sfs /mnt/${WKG_DEV}/${WKG_DIR}
echo "KEYMAP='${KEYMAP}'" > /mnt/${WKG_DEV}/${WKG_DIR}sfs/settings/initrd/CONFIG
echo "ALLOW_ASK_PW='${ALLOW_ASK_PW}'" >> /mnt/${WKG_DEV}/${WKG_DIR}sfs/settings/initrd/CONFIG

if [ -d /mnt/${WKG_DEV}/${WKG_DIR}v1tov2 ];then #20230503
cp -a -f /mnt/${WKG_DEV}/${WKG_DIR}v1tov2/containers/* /mnt/${WKG_DEV}/${WKG_DIR}containers/
cp -a -f /mnt/${WKG_DEV}/${WKG_DIR}v1tov2/files/* /mnt/${WKG_DEV}/${WKG_DIR}files/
cp -a -f /mnt/${WKG_DEV}/${WKG_DIR}v1tov2/session/* /mnt/${WKG_DEV}/${WKG_DIR}.session/
sync
rm -rf /mnt/${WKG_DEV}/${WKG_DIR}v1tov2
fi
else
#20211006 crap, if updating to 3.0+, have 'home' folder, not 'files'. here test 'releases' instead...
if [ "$EOS_FSCRYPT_VER" == "1" ];then #20230429
Expand Down
Expand Up @@ -31,6 +31,7 @@
#20230221 no longer have language-specific .img files.
#20230305 easy-*.img may have a different name. note: "easy.sfs" changed in 3buildeasydistro
#20230328 ask if current .img is elsewhere.
#20230503 cannot update fscrypt v1 to v2

export TEXTDOMAIN=easy-update
export OUTPUT_CHARSET=UTF-8
Expand Down Expand Up @@ -155,6 +156,66 @@ else
echo -e '\033[0;39m' #reset.
fi

#20230503 cannot update fscrypt v1 to v2...
. /mnt/wkg/sfs/settings/initrd/CONFIg
if [ "$ALLOW_ASK_PW" == "yes" ];then
vercmp ${latestVER} gt 5.2.4
if [ $? -eq 0 ];then
vercmp ${DISTRO_VERSION} le 5.2.4
if [ $? -eq 0 ];then
S1=$(du -m -s /mnt/wkg/containers | tr '\t' ' ' | cut -f 1 -d ' ')
S2=$(du -m -s /mnt/wkg/files | tr '\t' ' ' | cut -f 1 -d ' ')
S3=$(du -m -s /mnt/wkg/.session | tr '\t' ' ' | cut -f 1 -d ' ')
St=$(($S1+$S2+$S3))
St=$(($St+3100))
Sf=$(df -m /dev/${WKG_DEV} | grep '^/dev' | tr -s ' ' | cut -f 4 -d ' ')

echo -en '\033[1;31m' #bright red.
echo "$(gettext 'WARNING! WARNING! WARNING!')"
echo "$(gettext 'Beyond version 5.2.4 the method used to encrypt the folders has changed. This means you cannot update in the normal way.')"
echo "$(gettext "Instead, the 'containers', 'files' and '.session' encrypted folders will be copied into /mnt/wkg/v1tov2. The four encrypted folders 'containers', 'files', '.sesssion' and 'releases' will then be deleted.")"
echo "$(gettext "The update may then continue. At next bootup, the four encrypted folders will be recreated with the new v2 encryption technique, and the contents of folder 'v1tov2' copied into them.")"
echo "$(gettext 'The most important consequence is that the history is wiped, no rollback to 5.2.4 and before.')"
echo -e '\033[0;39m' #reset.
echo "$(gettext 'There is one potential complication: there must be sufficient free space in the working-partition.')"
echo -n "$(gettext 'Required space for v1tov2 folder and download:') "
echo "${St}M"
echo -n "$(gettext 'Free space available in working-partition:') "
echo "${Sf}M"
vercmp ${St} lt ${Sf}
if [ $? -eq 0 ];then
echo -en '\033[1;31m' #bright red.
echo "$(gettext 'NOT ENOUGH FREE SPACE! Aborting update')"
echo -e '\033[0;39m' #reset.
askabort='y'
else
echo "$(gettext 'Press the ENTER key to continue with update,')"
echo -n "$(gettext 'or any other key to abort:') "
read askabort
fi
if [ "$askabort" != "" ];then
echo ''
echo "$(gettext 'Update aborted')"
echo -e "\033[1;31m${MSGexit}\033[0;39m"
exit 9
fi
echo ''
echo "$(gettext 'Copying contents of encrypted folders to /mnt/wkg/v1tov2:')"
if [ -d /mnt/wkg/v1tov2 ];then
rm -rf /mnt/wkg/v1tov2
fi
mkdir /mnt/wkg/v1tov2
mkdir /mnt/wkg/v1tov2/containers
cp -a /mnt/wkg/containers/* /mnt/wkg/v1tov2/containers/
mkdir /mnt/wkg/v1tov2/files
cp -a /mnt/wkg/files/* /mnt/wkg/v1tov2/files/
mkdir /mnt/wkg/v1tov2/session
cp -a /mnt/wkg/.session/* /mnt/wkg/v1tov2/session/
sync
fi
fi
fi

#ask for a download location, must have 3GB free space... 20220629 bump from 2GB
BLOCKbytes="$(stat -f -c %S /mnt/${WKG_DEV})" #block size, usually 4096
FREEblocks="$(stat -f -c %f /mnt/${WKG_DEV})"
Expand Down

0 comments on commit 73d89bd

Please sign in to comment.