Skip to content

Commit

Permalink
refactor: refactor rimerc install script
Browse files Browse the repository at this point in the history
  • Loading branch information
Bambooin committed Jun 18, 2021
1 parent 97e56de commit 78507b8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
47 changes: 29 additions & 18 deletions rimerc.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#!/usr/bin/env bash

RELEASE_PATH=release

if [ -z $1 ]; then
echo "Provide at least one input method!"
echo "Such as: $0 fcitx5"
exit
fi

VALID_RIME="fcitx, fcitx5, ibus or squirrel"
VALID_RIME="fcitx, fcitx5, ibus, squirrel, trime or weasel"
case $1 in
fcitx)
RIME_CONFIG_PATH=~/.config/fcitx/rime
Expand All @@ -23,6 +25,25 @@ ibus)
squirrel)
RIME_CONFIG_PATH=~/Library/Rime
;;

trime | weasel)
case $1 in
weasel)
RIME_CONFIG_PATH=%AppData%\Rime
;;

trime)
RIME_CONFIG_PATH=/sdcard/rime
;;
esac

# package flavor
./script/package.sh $1
echo "Please install $1 manually"
echo "Copy ${RELEASE_PATH}/$1 to your rime $1 ${RIME_CONFIG_PATH} and deploy"
exit
;;

*)
echo "Invalid $1 input method"
echo "Valid input method is ${VALID_RIME}"
Expand All @@ -32,10 +53,12 @@ esac

echo -e "Starting setup $1...\n"

EXTRACT=7z
INPUT_METHOD=$1
RIMERC=rimerc

# package flavor
./script/package.sh $1

# check if input method installed
if [ $1 == squirrel ]; then
if [ ! -d '/Library/Input Methods/Squirrel.app' ]; then
Expand All @@ -50,18 +73,6 @@ else
fi
fi

# check if 7z installed
if ! command -v ${EXTRACT} &>/dev/null; then
echo "${EXTRACT} could not be found"
echo "Please install ${EXTRACT} in your distro and try again!"
exit
fi

# extract
TMP_DIR=$(mktemp -d -t ${RIMERC}-XXXX)
echo -e "Extracting archive ${INPUT_METHOD}.7z to ${TMP_DIR} ..."
7z e ${INPUT_METHOD}.7z -o${TMP_DIR} -primerc >/dev/null 2>&1

# backup rime config
if [ -d ${RIME_CONFIG_PATH} ]; then
BACKUP_PATH=$(mktemp -p $(dirname ${RIME_CONFIG_PATH}) -d \
Expand All @@ -70,12 +81,12 @@ if [ -d ${RIME_CONFIG_PATH} ]; then
echo -e "\nBackup your rime config to ${BACKUP_PATH}"
fi

# copy yaml to config path
# copy config to config path
mkdir -p ${RIME_CONFIG_PATH}
cp ${TMP_DIR}/*.yaml ${RIME_CONFIG_PATH}
cp -ra ${RELEASE_PATH}/${INPUT_METHOD}/* ${RIME_CONFIG_PATH}

# remove tmp dir
rm -rf ${TMP_DIR}
# copy userdb to config path
cp -ra ${BACKUP_PATH}/*.userdb ${RIME_CONFIG_PATH}

# restart input method
echo -e "\nWaiting for ${INPUT_METHOD} restart and deploying..."
Expand Down
7 changes: 6 additions & 1 deletion script/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

releasePath=release

flavors=(fcitx fcitx5 ibus squirrel trime weasel)
if [ -z $1 ]; then
flavors=(fcitx fcitx5 ibus squirrel trime weasel)
else
flavors=($1)
fi

schemas=(common easy_en luna_pinyin)

mkdir -p ${releasePath}
Expand Down

0 comments on commit 78507b8

Please sign in to comment.