Skip to content

Commit

Permalink
Add cronjob for gc (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
lylex committed Dec 20, 2018
1 parent 91178b4 commit 9535015
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 9 deletions.
11 changes: 5 additions & 6 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ archive:
files:
- LICENSE
- README.md
- scripts/install_mac.sh
- scripts/drm.conf
- scripts/**/**
replacements:
darwin: Darwin
linux: Linux
Expand Down Expand Up @@ -89,10 +88,10 @@ nfpm:
config_files:
"scripts/*.conf": "/etc/drm/*.conf"
scripts:
preinstall: "scripts/preinstall.sh"
# postinstall: "scripts/postinstall.sh"
# preremove: "scripts/preremove.sh"
# postremove: "scripts/postremove.sh"
preinstall: "scripts/linux/preinstall.sh"
postinstall: "scripts/linux/postinstall.sh"
# preremove: "scripts/linux/preremove.sh"
postremove: "scripts/linux/postremove.sh"
overrides:
deb:
conflicts:
Expand Down
12 changes: 12 additions & 0 deletions scripts/linux/postinstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash -ex

DRM_USER=drm
BIN_NAME=drm

CRON="0 0,6,12,18 * * * $BIN_NAME gc"

useradd -M -s /sbin/nologin $DRM_USER
printf '%s\n' "$CRON" >> crontab.tmp
crontab -u $DRM_USER crontab.tmp && rm -f crontab.tmp

echo "alias rm=\"$BIN_NAME\"" >> /etc/profile
8 changes: 8 additions & 0 deletions scripts/linux/postremove.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash -ex

DRM_USER=drm

crontab -l -u $DRM_USER
userdel -r $DRM_USER

sed -i '/alias rm=/d' /etc/profile
File renamed without changes.
13 changes: 10 additions & 3 deletions scripts/install_mac.sh → scripts/mac/install_mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,21 @@ BLOB_DIR=$DATA_DIR/blob
BIN_DIR=/usr/local/bin/
BIN_NAME=drm

CRON="0 0,6,12,18 * * * $BIN_NAME gc"

[ -d $CFG_DIR ] || mkdir $CFG_DIR

if [ ! -d $DATA_DIR ]; then
mkdir $DATA_DIR $BLOB_DIR
chmod -R 777 $DATA_DIR
fi

cp $WORK_DIR/drm.conf $CFG_DIR/drm.conf
cp $WORK_DIR/../drm $BIN_DIR
cp $WORK_DIR/../drm.conf $CFG_DIR/drm.conf
cp $WORK_DIR/../../drm $BIN_DIR

echo "alias rm=\"$BIN_NAME\"" >> /etc/profile

alias rm='$$BIN_NAME' >> ~/.bashrc
# setup cronjob
crontab -l -u root > crontab.tmp
printf '%s\n' "$CRON" >> crontab.tmp
crontab -u root crontab.tmp && rm -f crontab.tmp
13 changes: 13 additions & 0 deletions scripts/mac/uninstall_mac.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash -ex

# Here is the workaround since we have no `deb` or `dmg` like packages for macOS

BIN_NAME=drm

sed -i '' '/alias rm=/d' /etc/profile

# remove cronjob
TEMP_FILE=crontab.tmp
crontab -l -u root > $TEMP_FILE
sed -i '' "/$BIN_NAME gc/d" $TEMP_FILE
crontab -u root $TEMP_FILE && rm -f $TEMP_FILE

0 comments on commit 9535015

Please sign in to comment.